Context.java revision 788fc2b904add1c8b02ac62663b61ae8fd7aed5a
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.content.pm.ApplicationInfo; 34import android.content.pm.PackageManager; 35import android.content.res.AssetManager; 36import android.content.res.ColorStateList; 37import android.content.res.Configuration; 38import android.content.res.Resources; 39import android.content.res.TypedArray; 40import android.database.DatabaseErrorHandler; 41import android.database.sqlite.SQLiteDatabase; 42import android.database.sqlite.SQLiteDatabase.CursorFactory; 43import android.graphics.Bitmap; 44import android.graphics.drawable.Drawable; 45import android.net.Uri; 46import android.os.Bundle; 47import android.os.Environment; 48import android.os.Handler; 49import android.os.IBinder; 50import android.os.Looper; 51import android.os.StatFs; 52import android.os.UserHandle; 53import android.os.UserManager; 54import android.provider.MediaStore; 55import android.util.AttributeSet; 56import android.view.DisplayAdjustments; 57import android.view.Display; 58import android.view.ViewDebug; 59import android.view.WindowManager; 60 61import java.io.File; 62import java.io.FileInputStream; 63import java.io.FileNotFoundException; 64import java.io.FileOutputStream; 65import java.io.IOException; 66import java.io.InputStream; 67import java.lang.annotation.Retention; 68import java.lang.annotation.RetentionPolicy; 69 70/** 71 * Interface to global information about an application environment. This is 72 * an abstract class whose implementation is provided by 73 * the Android system. It 74 * allows access to application-specific resources and classes, as well as 75 * up-calls for application-level operations such as launching activities, 76 * broadcasting and receiving intents, etc. 77 */ 78public abstract class Context { 79 /** 80 * File creation mode: the default mode, where the created file can only 81 * be accessed by the calling application (or all applications sharing the 82 * same user ID). 83 * @see #MODE_WORLD_READABLE 84 * @see #MODE_WORLD_WRITEABLE 85 */ 86 public static final int MODE_PRIVATE = 0x0000; 87 /** 88 * @deprecated Creating world-readable files is very dangerous, and likely 89 * to cause security holes in applications. It is strongly discouraged; 90 * instead, applications should use more formal mechanism for interactions 91 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and 92 * {@link android.app.Service}. There are no guarantees that this 93 * access mode will remain on a file, such as when it goes through a 94 * backup and restore. 95 * File creation mode: allow all other applications to have read access 96 * to the created file. 97 * @see #MODE_PRIVATE 98 * @see #MODE_WORLD_WRITEABLE 99 */ 100 @Deprecated 101 public static final int MODE_WORLD_READABLE = 0x0001; 102 /** 103 * @deprecated Creating world-writable files is very dangerous, and likely 104 * to cause security holes in applications. It is strongly discouraged; 105 * instead, applications should use more formal mechanism for interactions 106 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and 107 * {@link android.app.Service}. There are no guarantees that this 108 * access mode will remain on a file, such as when it goes through a 109 * backup and restore. 110 * File creation mode: allow all other applications to have write access 111 * to the created file. 112 * @see #MODE_PRIVATE 113 * @see #MODE_WORLD_READABLE 114 */ 115 @Deprecated 116 public static final int MODE_WORLD_WRITEABLE = 0x0002; 117 /** 118 * File creation mode: for use with {@link #openFileOutput}, if the file 119 * already exists then write data to the end of the existing file 120 * instead of erasing it. 121 * @see #openFileOutput 122 */ 123 public static final int MODE_APPEND = 0x8000; 124 125 /** 126 * SharedPreference loading flag: when set, the file on disk will 127 * be checked for modification even if the shared preferences 128 * instance is already loaded in this process. This behavior is 129 * sometimes desired in cases where the application has multiple 130 * processes, all writing to the same SharedPreferences file. 131 * Generally there are better forms of communication between 132 * processes, though. 133 * 134 * <p>This was the legacy (but undocumented) behavior in and 135 * before Gingerbread (Android 2.3) and this flag is implied when 136 * targetting such releases. For applications targetting SDK 137 * versions <em>greater than</em> Android 2.3, this flag must be 138 * explicitly set if desired. 139 * 140 * @see #getSharedPreferences 141 * 142 * @deprecated MODE_MULTI_PROCESS does not work reliably in 143 * some versions of Android, and furthermore does not provide any 144 * mechanism for reconciling concurrent modifications across 145 * processes. Applications should not attempt to use it. Instead, 146 * they should use an explicit cross-process data management 147 * approach such as {@link android.content.ContentProvider ContentProvider}. 148 */ 149 @Deprecated 150 public static final int MODE_MULTI_PROCESS = 0x0004; 151 152 /** 153 * Database open flag: when set, the database is opened with write-ahead 154 * logging enabled by default. 155 * 156 * @see #openOrCreateDatabase(String, int, CursorFactory) 157 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler) 158 * @see SQLiteDatabase#enableWriteAheadLogging 159 */ 160 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008; 161 162 /** @hide */ 163 @IntDef(flag = true, 164 value = { 165 BIND_AUTO_CREATE, 166 BIND_DEBUG_UNBIND, 167 BIND_NOT_FOREGROUND, 168 BIND_ABOVE_CLIENT, 169 BIND_ALLOW_OOM_MANAGEMENT, 170 BIND_WAIVE_PRIORITY, 171 BIND_IMPORTANT, 172 BIND_ADJUST_WITH_ACTIVITY 173 }) 174 @Retention(RetentionPolicy.SOURCE) 175 public @interface BindServiceFlags {} 176 177 /** 178 * Flag for {@link #bindService}: automatically create the service as long 179 * as the binding exists. Note that while this will create the service, 180 * its {@link android.app.Service#onStartCommand} 181 * method will still only be called due to an 182 * explicit call to {@link #startService}. Even without that, though, 183 * this still provides you with access to the service object while the 184 * service is created. 185 * 186 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, 187 * not supplying this flag would also impact how important the system 188 * consider's the target service's process to be. When set, the only way 189 * for it to be raised was by binding from a service in which case it will 190 * only be important when that activity is in the foreground. Now to 191 * achieve this behavior you must explicitly supply the new flag 192 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications 193 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have 194 * the flags {@link #BIND_WAIVE_PRIORITY} and 195 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve 196 * the same result. 197 */ 198 public static final int BIND_AUTO_CREATE = 0x0001; 199 200 /** 201 * Flag for {@link #bindService}: include debugging help for mismatched 202 * calls to unbind. When this flag is set, the callstack of the following 203 * {@link #unbindService} call is retained, to be printed if a later 204 * incorrect unbind call is made. Note that doing this requires retaining 205 * information about the binding that was made for the lifetime of the app, 206 * resulting in a leak -- this should only be used for debugging. 207 */ 208 public static final int BIND_DEBUG_UNBIND = 0x0002; 209 210 /** 211 * Flag for {@link #bindService}: don't allow this binding to raise 212 * the target service's process to the foreground scheduling priority. 213 * It will still be raised to at least the same memory priority 214 * as the client (so that its process will not be killable in any 215 * situation where the client is not killable), but for CPU scheduling 216 * purposes it may be left in the background. This only has an impact 217 * in the situation where the binding client is a foreground process 218 * and the target service is in a background process. 219 */ 220 public static final int BIND_NOT_FOREGROUND = 0x0004; 221 222 /** 223 * Flag for {@link #bindService}: indicates that the client application 224 * binding to this service considers the service to be more important than 225 * the app itself. When set, the platform will try to have the out of 226 * memory killer kill the app before it kills the service it is bound to, though 227 * this is not guaranteed to be the case. 228 */ 229 public static final int BIND_ABOVE_CLIENT = 0x0008; 230 231 /** 232 * Flag for {@link #bindService}: allow the process hosting the bound 233 * service to go through its normal memory management. It will be 234 * treated more like a running service, allowing the system to 235 * (temporarily) expunge the process if low on memory or for some other 236 * whim it may have, and being more aggressive about making it a candidate 237 * to be killed (and restarted) if running for a long time. 238 */ 239 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010; 240 241 /** 242 * Flag for {@link #bindService}: don't impact the scheduling or 243 * memory management priority of the target service's hosting process. 244 * Allows the service's process to be managed on the background LRU list 245 * just like a regular application process in the background. 246 */ 247 public static final int BIND_WAIVE_PRIORITY = 0x0020; 248 249 /** 250 * Flag for {@link #bindService}: this service is very important to 251 * the client, so should be brought to the foreground process level 252 * when the client is. Normally a process can only be raised to the 253 * visibility level by a client, even if that client is in the foreground. 254 */ 255 public static final int BIND_IMPORTANT = 0x0040; 256 257 /** 258 * Flag for {@link #bindService}: If binding from an activity, allow the 259 * target service's process importance to be raised based on whether the 260 * activity is visible to the user, regardless whether another flag is 261 * used to reduce the amount that the client process's overall importance 262 * is used to impact it. 263 */ 264 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080; 265 266 /** 267 * @hide Flag for {@link #bindService}: Like {@link #BIND_FOREGROUND_SERVICE}, 268 * but only applies while the device is awake. 269 */ 270 public static final int BIND_FOREGROUND_SERVICE_WHILE_AWAKE = 0x02000000; 271 272 /** 273 * @hide Flag for {@link #bindService}: For only the case where the binding 274 * is coming from the system, set the process state to FOREGROUND_SERVICE 275 * instead of the normal maximum of IMPORTANT_FOREGROUND. That is, this is 276 * saying that the process shouldn't participate in the normal power reduction 277 * modes (removing network access etc). 278 */ 279 public static final int BIND_FOREGROUND_SERVICE = 0x04000000; 280 281 /** 282 * @hide Flag for {@link #bindService}: Treat the binding as hosting 283 * an activity, an unbinding as the activity going in the background. 284 * That is, when unbinding, the process when empty will go on the activity 285 * LRU list instead of the regular one, keeping it around more aggressively 286 * than it otherwise would be. This is intended for use with IMEs to try 287 * to keep IME processes around for faster keyboard switching. 288 */ 289 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000; 290 291 /** 292 * @hide An idea that is not yet implemented. 293 * Flag for {@link #bindService}: If binding from an activity, consider 294 * this service to be visible like the binding activity is. That is, 295 * it will be treated as something more important to keep around than 296 * invisible background activities. This will impact the number of 297 * recent activities the user can switch between without having them 298 * restart. There is no guarantee this will be respected, as the system 299 * tries to balance such requests from one app vs. the importantance of 300 * keeping other apps around. 301 */ 302 public static final int BIND_VISIBLE = 0x10000000; 303 304 /** 305 * @hide 306 * Flag for {@link #bindService}: Consider this binding to be causing the target 307 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes 308 * away. 309 */ 310 public static final int BIND_SHOWING_UI = 0x20000000; 311 312 /** 313 * Flag for {@link #bindService}: Don't consider the bound service to be 314 * visible, even if the caller is visible. 315 * @hide 316 */ 317 public static final int BIND_NOT_VISIBLE = 0x40000000; 318 319 /** Return an AssetManager instance for your application's package. */ 320 public abstract AssetManager getAssets(); 321 322 /** Return a Resources instance for your application's package. */ 323 public abstract Resources getResources(); 324 325 /** Return PackageManager instance to find global package information. */ 326 public abstract PackageManager getPackageManager(); 327 328 /** Return a ContentResolver instance for your application's package. */ 329 public abstract ContentResolver getContentResolver(); 330 331 /** 332 * Return the Looper for the main thread of the current process. This is 333 * the thread used to dispatch calls to application components (activities, 334 * services, etc). 335 * <p> 336 * By definition, this method returns the same result as would be obtained 337 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}. 338 * </p> 339 * 340 * @return The main looper. 341 */ 342 public abstract Looper getMainLooper(); 343 344 /** 345 * Return the context of the single, global Application object of the 346 * current process. This generally should only be used if you need a 347 * Context whose lifecycle is separate from the current context, that is 348 * tied to the lifetime of the process rather than the current component. 349 * 350 * <p>Consider for example how this interacts with 351 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}: 352 * <ul> 353 * <li> <p>If used from an Activity context, the receiver is being registered 354 * within that activity. This means that you are expected to unregister 355 * before the activity is done being destroyed; in fact if you do not do 356 * so, the framework will clean up your leaked registration as it removes 357 * the activity and log an error. Thus, if you use the Activity context 358 * to register a receiver that is static (global to the process, not 359 * associated with an Activity instance) then that registration will be 360 * removed on you at whatever point the activity you used is destroyed. 361 * <li> <p>If used from the Context returned here, the receiver is being 362 * registered with the global state associated with your application. Thus 363 * it will never be unregistered for you. This is necessary if the receiver 364 * is associated with static data, not a particular component. However 365 * using the ApplicationContext elsewhere can easily lead to serious leaks 366 * if you forget to unregister, unbind, etc. 367 * </ul> 368 */ 369 public abstract Context getApplicationContext(); 370 371 /** 372 * Add a new {@link ComponentCallbacks} to the base application of the 373 * Context, which will be called at the same times as the ComponentCallbacks 374 * methods of activities and other components are called. Note that you 375 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when 376 * appropriate in the future; this will not be removed for you. 377 * 378 * @param callback The interface to call. This can be either a 379 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface. 380 */ 381 public void registerComponentCallbacks(ComponentCallbacks callback) { 382 getApplicationContext().registerComponentCallbacks(callback); 383 } 384 385 /** 386 * Remove a {@link ComponentCallbacks} object that was previously registered 387 * with {@link #registerComponentCallbacks(ComponentCallbacks)}. 388 */ 389 public void unregisterComponentCallbacks(ComponentCallbacks callback) { 390 getApplicationContext().unregisterComponentCallbacks(callback); 391 } 392 393 /** 394 * Return a localized, styled CharSequence from the application's package's 395 * default string table. 396 * 397 * @param resId Resource id for the CharSequence text 398 */ 399 public final CharSequence getText(@StringRes int resId) { 400 return getResources().getText(resId); 401 } 402 403 /** 404 * Returns a localized string from the application's package's 405 * default string table. 406 * 407 * @param resId Resource id for the string 408 * @return The string data associated with the resource, stripped of styled 409 * text information. 410 */ 411 @NonNull 412 public final String getString(@StringRes int resId) { 413 return getResources().getString(resId); 414 } 415 416 /** 417 * Returns a localized formatted string from the application's package's 418 * default string table, substituting the format arguments as defined in 419 * {@link java.util.Formatter} and {@link java.lang.String#format}. 420 * 421 * @param resId Resource id for the format string 422 * @param formatArgs The format arguments that will be used for 423 * substitution. 424 * @return The string data associated with the resource, formatted and 425 * stripped of styled text information. 426 */ 427 @NonNull 428 public final String getString(@StringRes int resId, Object... formatArgs) { 429 return getResources().getString(resId, formatArgs); 430 } 431 432 /** 433 * Returns a color associated with a particular resource ID and styled for 434 * the current theme. 435 * 436 * @param id The desired resource identifier, as generated by the aapt 437 * tool. This integer encodes the package, type, and resource 438 * entry. The value 0 is an invalid identifier. 439 * @return A single color value in the form 0xAARRGGBB. 440 * @throws android.content.res.Resources.NotFoundException if the given ID 441 * does not exist. 442 */ 443 @ColorInt 444 public final int getColor(@ColorRes int id) { 445 return getResources().getColor(id, getTheme()); 446 } 447 448 /** 449 * Returns a drawable object associated with a particular resource ID and 450 * styled for the current theme. 451 * 452 * @param id The desired resource identifier, as generated by the aapt 453 * tool. This integer encodes the package, type, and resource 454 * entry. The value 0 is an invalid identifier. 455 * @return An object that can be used to draw this resource, or 456 * {@code null} if the resource could not be resolved. 457 * @throws android.content.res.Resources.NotFoundException if the given ID 458 * does not exist. 459 */ 460 @Nullable 461 public final Drawable getDrawable(@DrawableRes int id) { 462 return getResources().getDrawable(id, getTheme()); 463 } 464 465 /** 466 * Returns a color state list associated with a particular resource ID and 467 * styled for the current theme. 468 * 469 * @param id The desired resource identifier, as generated by the aapt 470 * tool. This integer encodes the package, type, and resource 471 * entry. The value 0 is an invalid identifier. 472 * @return A color state list, or {@code null} if the resource could not be 473 * resolved. 474 * @throws android.content.res.Resources.NotFoundException if the given ID 475 * does not exist. 476 */ 477 @Nullable 478 public final ColorStateList getColorStateList(@ColorRes int id) { 479 return getResources().getColorStateList(id, getTheme()); 480 } 481 482 /** 483 * Set the base theme for this context. Note that this should be called 484 * before any views are instantiated in the Context (for example before 485 * calling {@link android.app.Activity#setContentView} or 486 * {@link android.view.LayoutInflater#inflate}). 487 * 488 * @param resid The style resource describing the theme. 489 */ 490 public abstract void setTheme(@StyleRes int resid); 491 492 /** @hide Needed for some internal implementation... not public because 493 * you can't assume this actually means anything. */ 494 public int getThemeResId() { 495 return 0; 496 } 497 498 /** 499 * Return the Theme object associated with this Context. 500 */ 501 @ViewDebug.ExportedProperty(deepExport = true) 502 public abstract Resources.Theme getTheme(); 503 504 /** 505 * Retrieve styled attribute information in this Context's theme. See 506 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])} 507 * for more information. 508 * 509 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[]) 510 */ 511 public final TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) { 512 return getTheme().obtainStyledAttributes(attrs); 513 } 514 515 /** 516 * Retrieve styled attribute information in this Context's theme. See 517 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])} 518 * for more information. 519 * 520 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[]) 521 */ 522 public final TypedArray obtainStyledAttributes( 523 @StyleRes int resid, @StyleableRes int[] attrs) throws Resources.NotFoundException { 524 return getTheme().obtainStyledAttributes(resid, attrs); 525 } 526 527 /** 528 * Retrieve styled attribute information in this Context's theme. See 529 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)} 530 * for more information. 531 * 532 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int) 533 */ 534 public final TypedArray obtainStyledAttributes( 535 AttributeSet set, @StyleableRes int[] attrs) { 536 return getTheme().obtainStyledAttributes(set, attrs, 0, 0); 537 } 538 539 /** 540 * Retrieve styled attribute information in this Context's theme. See 541 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)} 542 * for more information. 543 * 544 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int) 545 */ 546 public final TypedArray obtainStyledAttributes( 547 AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr, 548 @StyleRes int defStyleRes) { 549 return getTheme().obtainStyledAttributes( 550 set, attrs, defStyleAttr, defStyleRes); 551 } 552 553 /** 554 * Return a class loader you can use to retrieve classes in this package. 555 */ 556 public abstract ClassLoader getClassLoader(); 557 558 /** Return the name of this application's package. */ 559 public abstract String getPackageName(); 560 561 /** @hide Return the name of the base context this context is derived from. */ 562 public abstract String getBasePackageName(); 563 564 /** @hide Return the package name that should be used for app ops calls from 565 * this context. This is the same as {@link #getBasePackageName()} except in 566 * cases where system components are loaded into other app processes, in which 567 * case this will be the name of the primary package in that process (so that app 568 * ops uid verification will work with the name). */ 569 public abstract String getOpPackageName(); 570 571 /** Return the full application info for this context's package. */ 572 public abstract ApplicationInfo getApplicationInfo(); 573 574 /** 575 * Return the full path to this context's primary Android package. 576 * The Android package is a ZIP file which contains the application's 577 * primary resources. 578 * 579 * <p>Note: this is not generally useful for applications, since they should 580 * not be directly accessing the file system. 581 * 582 * @return String Path to the resources. 583 */ 584 public abstract String getPackageResourcePath(); 585 586 /** 587 * Return the full path to this context's primary Android package. 588 * The Android package is a ZIP file which contains application's 589 * primary code and assets. 590 * 591 * <p>Note: this is not generally useful for applications, since they should 592 * not be directly accessing the file system. 593 * 594 * @return String Path to the code and assets. 595 */ 596 public abstract String getPackageCodePath(); 597 598 /** 599 * {@hide} 600 * Return the full path to the shared prefs file for the given prefs group name. 601 * 602 * <p>Note: this is not generally useful for applications, since they should 603 * not be directly accessing the file system. 604 */ 605 public abstract File getSharedPrefsFile(String name); 606 607 /** 608 * Retrieve and hold the contents of the preferences file 'name', returning 609 * a SharedPreferences through which you can retrieve and modify its 610 * values. Only one instance of the SharedPreferences object is returned 611 * to any callers for the same name, meaning they will see each other's 612 * edits as soon as they are made. 613 * 614 * @param name Desired preferences file. If a preferences file by this name 615 * does not exist, it will be created when you retrieve an 616 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()). 617 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the 618 * default operation, {@link #MODE_WORLD_READABLE} 619 * and {@link #MODE_WORLD_WRITEABLE} to control permissions. 620 * 621 * @return The single {@link SharedPreferences} instance that can be used 622 * to retrieve and modify the preference values. 623 * 624 * @see #MODE_PRIVATE 625 * @see #MODE_WORLD_READABLE 626 * @see #MODE_WORLD_WRITEABLE 627 */ 628 public abstract SharedPreferences getSharedPreferences(String name, 629 int mode); 630 631 /** 632 * Open a private file associated with this Context's application package 633 * for reading. 634 * 635 * @param name The name of the file to open; can not contain path 636 * separators. 637 * 638 * @return The resulting {@link FileInputStream}. 639 * 640 * @see #openFileOutput 641 * @see #fileList 642 * @see #deleteFile 643 * @see java.io.FileInputStream#FileInputStream(String) 644 */ 645 public abstract FileInputStream openFileInput(String name) 646 throws FileNotFoundException; 647 648 /** 649 * Open a private file associated with this Context's application package 650 * for writing. Creates the file if it doesn't already exist. 651 * 652 * <p>No permissions are required to invoke this method, since it uses internal 653 * storage. 654 * 655 * @param name The name of the file to open; can not contain path 656 * separators. 657 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the 658 * default operation, {@link #MODE_APPEND} to append to an existing file, 659 * {@link #MODE_WORLD_READABLE} and {@link #MODE_WORLD_WRITEABLE} to control 660 * permissions. 661 * 662 * @return The resulting {@link FileOutputStream}. 663 * 664 * @see #MODE_APPEND 665 * @see #MODE_PRIVATE 666 * @see #MODE_WORLD_READABLE 667 * @see #MODE_WORLD_WRITEABLE 668 * @see #openFileInput 669 * @see #fileList 670 * @see #deleteFile 671 * @see java.io.FileOutputStream#FileOutputStream(String) 672 */ 673 public abstract FileOutputStream openFileOutput(String name, int mode) 674 throws FileNotFoundException; 675 676 /** 677 * Delete the given private file associated with this Context's 678 * application package. 679 * 680 * @param name The name of the file to delete; can not contain path 681 * separators. 682 * 683 * @return {@code true} if the file was successfully deleted; else 684 * {@code false}. 685 * 686 * @see #openFileInput 687 * @see #openFileOutput 688 * @see #fileList 689 * @see java.io.File#delete() 690 */ 691 public abstract boolean deleteFile(String name); 692 693 /** 694 * Returns the absolute path on the filesystem where a file created with 695 * {@link #openFileOutput} is stored. 696 * 697 * @param name The name of the file for which you would like to get 698 * its path. 699 * 700 * @return An absolute path to the given file. 701 * 702 * @see #openFileOutput 703 * @see #getFilesDir 704 * @see #getDir 705 */ 706 public abstract File getFileStreamPath(String name); 707 708 /** 709 * Returns the absolute path to the directory on the filesystem where 710 * files created with {@link #openFileOutput} are stored. 711 * 712 * <p>No permissions are required to read or write to the returned path, since this 713 * path is internal storage. 714 * 715 * @return The path of the directory holding application files. 716 * 717 * @see #openFileOutput 718 * @see #getFileStreamPath 719 * @see #getDir 720 */ 721 public abstract File getFilesDir(); 722 723 /** 724 * Returns the absolute path to the directory on the filesystem similar to 725 * {@link #getFilesDir()}. The difference is that files placed under this 726 * directory will be excluded from automatic backup to remote storage. See 727 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion 728 * of the automatic backup mechanism in Android. 729 * 730 * <p>No permissions are required to read or write to the returned path, since this 731 * path is internal storage. 732 * 733 * @return The path of the directory holding application files that will not be 734 * automatically backed up to remote storage. 735 * 736 * @see #openFileOutput 737 * @see #getFileStreamPath 738 * @see #getDir 739 * @see android.app.backup.BackupAgent 740 */ 741 public abstract File getNoBackupFilesDir(); 742 743 /** 744 * Returns the absolute path to the directory on the primary external filesystem 745 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory() 746 * Environment.getExternalStorageDirectory()}) where the application can 747 * place persistent files it owns. These files are internal to the 748 * applications, and not typically visible to the user as media. 749 * 750 * <p>This is like {@link #getFilesDir()} in that these 751 * files will be deleted when the application is uninstalled, however there 752 * are some important differences: 753 * 754 * <ul> 755 * <li>External files are not always available: they will disappear if the 756 * user mounts the external storage on a computer or removes it. See the 757 * APIs on {@link android.os.Environment} for information in the storage state. 758 * <li>There is no security enforced with these files. For example, any application 759 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to 760 * these files. 761 * </ul> 762 * 763 * <p>Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions 764 * are required to read or write to the returned path; it's always 765 * accessible to the calling app. This only applies to paths generated for 766 * package name of the calling application. To access paths belonging 767 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} 768 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required. 769 * 770 * <p>On devices with multiple users (as described by {@link UserManager}), 771 * each user has their own isolated external storage. Applications only 772 * have access to the external storage for the user they're running as.</p> 773 * 774 * <p>Here is an example of typical code to manipulate a file in 775 * an application's private storage:</p> 776 * 777 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java 778 * private_file} 779 * 780 * <p>If you supply a non-null <var>type</var> to this function, the returned 781 * file will be a path to a sub-directory of the given type. Though these files 782 * are not automatically scanned by the media scanner, you can explicitly 783 * add them to the media database with 784 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], 785 * android.media.MediaScannerConnection.OnScanCompletedListener) 786 * MediaScannerConnection.scanFile}. 787 * Note that this is not the same as 788 * {@link android.os.Environment#getExternalStoragePublicDirectory 789 * Environment.getExternalStoragePublicDirectory()}, which provides 790 * directories of media shared by all applications. The 791 * directories returned here are 792 * owned by the application, and their contents will be removed when the 793 * application is uninstalled. Unlike 794 * {@link android.os.Environment#getExternalStoragePublicDirectory 795 * Environment.getExternalStoragePublicDirectory()}, the directory 796 * returned here will be automatically created for you. 797 * 798 * <p>Here is an example of typical code to manipulate a picture in 799 * an application's private storage and add it to the media database:</p> 800 * 801 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java 802 * private_picture} 803 * 804 * @param type The type of files directory to return. May be null for 805 * the root of the files directory or one of 806 * the following Environment constants for a subdirectory: 807 * {@link android.os.Environment#DIRECTORY_MUSIC}, 808 * {@link android.os.Environment#DIRECTORY_PODCASTS}, 809 * {@link android.os.Environment#DIRECTORY_RINGTONES}, 810 * {@link android.os.Environment#DIRECTORY_ALARMS}, 811 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS}, 812 * {@link android.os.Environment#DIRECTORY_PICTURES}, or 813 * {@link android.os.Environment#DIRECTORY_MOVIES}. 814 * 815 * @return The path of the directory holding application files 816 * on external storage. Returns null if external storage is not currently 817 * mounted so it could not ensure the path exists; you will need to call 818 * this method again when it is available. 819 * 820 * @see #getFilesDir 821 * @see android.os.Environment#getExternalStoragePublicDirectory 822 */ 823 @Nullable 824 public abstract File getExternalFilesDir(@Nullable String type); 825 826 /** 827 * Returns absolute paths to application-specific directories on all 828 * external storage devices where the application can place persistent files 829 * it owns. These files are internal to the application, and not typically 830 * visible to the user as media. 831 * <p> 832 * This is like {@link #getFilesDir()} in that these files will be deleted when 833 * the application is uninstalled, however there are some important differences: 834 * <ul> 835 * <li>External files are not always available: they will disappear if the 836 * user mounts the external storage on a computer or removes it. 837 * <li>There is no security enforced with these files. 838 * </ul> 839 * <p> 840 * External storage devices returned here are considered a permanent part of 841 * the device, including both emulated external storage and physical media 842 * slots, such as SD cards in a battery compartment. The returned paths do 843 * not include transient devices, such as USB flash drives. 844 * <p> 845 * An application may store data on any or all of the returned devices. For 846 * example, an app may choose to store large files on the device with the 847 * most available space, as measured by {@link StatFs}. 848 * <p> 849 * No permissions are required to read or write to the returned paths; they 850 * are always accessible to the calling app. Write access outside of these 851 * paths on secondary external storage devices is not available. 852 * <p> 853 * The first path returned is the same as {@link #getExternalFilesDir(String)}. 854 * Returned paths may be {@code null} if a storage device is unavailable. 855 * 856 * @see #getExternalFilesDir(String) 857 * @see Environment#getExternalStorageState(File) 858 */ 859 public abstract File[] getExternalFilesDirs(String type); 860 861 /** 862 * Return the primary external storage directory where this application's OBB 863 * files (if there are any) can be found. Note if the application does not have 864 * any OBB files, this directory may not exist. 865 * <p> 866 * This is like {@link #getFilesDir()} in that these files will be deleted when 867 * the application is uninstalled, however there are some important differences: 868 * <ul> 869 * <li>External files are not always available: they will disappear if the 870 * user mounts the external storage on a computer or removes it. 871 * <li>There is no security enforced with these files. For example, any application 872 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to 873 * these files. 874 * </ul> 875 * <p> 876 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions 877 * are required to read or write to the returned path; it's always 878 * accessible to the calling app. This only applies to paths generated for 879 * package name of the calling application. To access paths belonging 880 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} 881 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required. 882 * <p> 883 * On devices with multiple users (as described by {@link UserManager}), 884 * multiple users may share the same OBB storage location. Applications 885 * should ensure that multiple instances running under different users don't 886 * interfere with each other. 887 */ 888 public abstract File getObbDir(); 889 890 /** 891 * Returns absolute paths to application-specific directories on all 892 * external storage devices where the application's OBB files (if there are 893 * any) can be found. Note if the application does not have any OBB files, 894 * these directories may not exist. 895 * <p> 896 * This is like {@link #getFilesDir()} in that these files will be deleted when 897 * the application is uninstalled, however there are some important differences: 898 * <ul> 899 * <li>External files are not always available: they will disappear if the 900 * user mounts the external storage on a computer or removes it. 901 * <li>There is no security enforced with these files. 902 * </ul> 903 * <p> 904 * External storage devices returned here are considered a permanent part of 905 * the device, including both emulated external storage and physical media 906 * slots, such as SD cards in a battery compartment. The returned paths do 907 * not include transient devices, such as USB flash drives. 908 * <p> 909 * An application may store data on any or all of the returned devices. For 910 * example, an app may choose to store large files on the device with the 911 * most available space, as measured by {@link StatFs}. 912 * <p> 913 * No permissions are required to read or write to the returned paths; they 914 * are always accessible to the calling app. Write access outside of these 915 * paths on secondary external storage devices is not available. 916 * <p> 917 * The first path returned is the same as {@link #getObbDir()}. 918 * Returned paths may be {@code null} if a storage device is unavailable. 919 * 920 * @see #getObbDir() 921 * @see Environment#getExternalStorageState(File) 922 */ 923 public abstract File[] getObbDirs(); 924 925 /** 926 * Returns the absolute path to the application specific cache directory 927 * on the filesystem. These files will be ones that get deleted first when the 928 * device runs low on storage. 929 * There is no guarantee when these files will be deleted. 930 * 931 * <strong>Note: you should not <em>rely</em> on the system deleting these 932 * files for you; you should always have a reasonable maximum, such as 1 MB, 933 * for the amount of space you consume with cache files, and prune those 934 * files when exceeding that space.</strong> 935 * 936 * @return The path of the directory holding application cache files. 937 * 938 * @see #openFileOutput 939 * @see #getFileStreamPath 940 * @see #getDir 941 */ 942 public abstract File getCacheDir(); 943 944 /** 945 * Returns the absolute path to the application specific cache directory on 946 * the filesystem designed for storing cached code. The system will delete 947 * any files stored in this location both when your specific application is 948 * upgraded, and when the entire platform is upgraded. 949 * <p> 950 * This location is optimal for storing compiled or optimized code generated 951 * by your application at runtime. 952 * <p> 953 * Apps require no extra permissions to read or write to the returned path, 954 * since this path lives in their private storage. 955 * 956 * @return The path of the directory holding application code cache files. 957 */ 958 public abstract File getCodeCacheDir(); 959 960 /** 961 * Returns the absolute path to the directory on the primary external filesystem 962 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory() 963 * Environment.getExternalStorageDirectory()} where the application can 964 * place cache files it owns. These files are internal to the application, and 965 * not typically visible to the user as media. 966 * 967 * <p>This is like {@link #getCacheDir()} in that these 968 * files will be deleted when the application is uninstalled, however there 969 * are some important differences: 970 * 971 * <ul> 972 * <li>The platform does not always monitor the space available in external 973 * storage, and thus may not automatically delete these files. Currently 974 * the only time files here will be deleted by the platform is when running 975 * on {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and 976 * {@link android.os.Environment#isExternalStorageEmulated() 977 * Environment.isExternalStorageEmulated()} returns true. Note that you should 978 * be managing the maximum space you will use for these anyway, just like 979 * with {@link #getCacheDir()}. 980 * <li>External files are not always available: they will disappear if the 981 * user mounts the external storage on a computer or removes it. See the 982 * APIs on {@link android.os.Environment} for information in the storage state. 983 * <li>There is no security enforced with these files. For example, any application 984 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to 985 * these files. 986 * </ul> 987 * 988 * <p>Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions 989 * are required to read or write to the returned path; it's always 990 * accessible to the calling app. This only applies to paths generated for 991 * package name of the calling application. To access paths belonging 992 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} 993 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required. 994 * 995 * <p>On devices with multiple users (as described by {@link UserManager}), 996 * each user has their own isolated external storage. Applications only 997 * have access to the external storage for the user they're running as.</p> 998 * 999 * @return The path of the directory holding application cache files 1000 * on external storage. Returns null if external storage is not currently 1001 * mounted so it could not ensure the path exists; you will need to call 1002 * this method again when it is available. 1003 * 1004 * @see #getCacheDir 1005 */ 1006 @Nullable 1007 public abstract File getExternalCacheDir(); 1008 1009 /** 1010 * Returns absolute paths to application-specific directories on all 1011 * external storage devices where the application can place cache files it 1012 * owns. These files are internal to the application, and not typically 1013 * visible to the user as media. 1014 * <p> 1015 * This is like {@link #getCacheDir()} in that these files will be deleted when 1016 * the application is uninstalled, however there are some important differences: 1017 * <ul> 1018 * <li>External files are not always available: they will disappear if the 1019 * user mounts the external storage on a computer or removes it. 1020 * <li>There is no security enforced with these files. 1021 * </ul> 1022 * <p> 1023 * External storage devices returned here are considered a permanent part of 1024 * the device, including both emulated external storage and physical media 1025 * slots, such as SD cards in a battery compartment. The returned paths do 1026 * not include transient devices, such as USB flash drives. 1027 * <p> 1028 * An application may store data on any or all of the returned devices. For 1029 * example, an app may choose to store large files on the device with the 1030 * most available space, as measured by {@link StatFs}. 1031 * <p> 1032 * No permissions are required to read or write to the returned paths; they 1033 * are always accessible to the calling app. Write access outside of these 1034 * paths on secondary external storage devices is not available. 1035 * <p> 1036 * The first path returned is the same as {@link #getExternalCacheDir()}. 1037 * Returned paths may be {@code null} if a storage device is unavailable. 1038 * 1039 * @see #getExternalCacheDir() 1040 * @see Environment#getExternalStorageState(File) 1041 */ 1042 public abstract File[] getExternalCacheDirs(); 1043 1044 /** 1045 * Returns absolute paths to application-specific directories on all 1046 * external storage devices where the application can place media files. 1047 * These files are scanned and made available to other apps through 1048 * {@link MediaStore}. 1049 * <p> 1050 * This is like {@link #getExternalFilesDirs} in that these files will be 1051 * deleted when the application is uninstalled, however there are some 1052 * important differences: 1053 * <ul> 1054 * <li>External files are not always available: they will disappear if the 1055 * user mounts the external storage on a computer or removes it. 1056 * <li>There is no security enforced with these files. 1057 * </ul> 1058 * <p> 1059 * External storage devices returned here are considered a permanent part of 1060 * the device, including both emulated external storage and physical media 1061 * slots, such as SD cards in a battery compartment. The returned paths do 1062 * not include transient devices, such as USB flash drives. 1063 * <p> 1064 * An application may store data on any or all of the returned devices. For 1065 * example, an app may choose to store large files on the device with the 1066 * most available space, as measured by {@link StatFs}. 1067 * <p> 1068 * No permissions are required to read or write to the returned paths; they 1069 * are always accessible to the calling app. Write access outside of these 1070 * paths on secondary external storage devices is not available. 1071 * <p> 1072 * Returned paths may be {@code null} if a storage device is unavailable. 1073 * 1074 * @see Environment#getExternalStorageState(File) 1075 */ 1076 public abstract File[] getExternalMediaDirs(); 1077 1078 /** 1079 * Returns an array of strings naming the private files associated with 1080 * this Context's application package. 1081 * 1082 * @return Array of strings naming the private files. 1083 * 1084 * @see #openFileInput 1085 * @see #openFileOutput 1086 * @see #deleteFile 1087 */ 1088 public abstract String[] fileList(); 1089 1090 /** 1091 * Retrieve, creating if needed, a new directory in which the application 1092 * can place its own custom data files. You can use the returned File 1093 * object to create and access files in this directory. Note that files 1094 * created through a File object will only be accessible by your own 1095 * application; you can only set the mode of the entire directory, not 1096 * of individual files. 1097 * 1098 * @param name Name of the directory to retrieve. This is a directory 1099 * that is created as part of your application data. 1100 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the 1101 * default operation, {@link #MODE_WORLD_READABLE} and 1102 * {@link #MODE_WORLD_WRITEABLE} to control permissions. 1103 * 1104 * @return A {@link File} object for the requested directory. The directory 1105 * will have been created if it does not already exist. 1106 * 1107 * @see #openFileOutput(String, int) 1108 */ 1109 public abstract File getDir(String name, int mode); 1110 1111 /** 1112 * Open a new private SQLiteDatabase associated with this Context's 1113 * application package. Create the database file if it doesn't exist. 1114 * 1115 * @param name The name (unique in the application package) of the database. 1116 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the 1117 * default operation, {@link #MODE_WORLD_READABLE} 1118 * and {@link #MODE_WORLD_WRITEABLE} to control permissions. 1119 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default. 1120 * @param factory An optional factory class that is called to instantiate a 1121 * cursor when query is called. 1122 * 1123 * @return The contents of a newly created database with the given name. 1124 * @throws android.database.sqlite.SQLiteException if the database file could not be opened. 1125 * 1126 * @see #MODE_PRIVATE 1127 * @see #MODE_WORLD_READABLE 1128 * @see #MODE_WORLD_WRITEABLE 1129 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING 1130 * @see #deleteDatabase 1131 */ 1132 public abstract SQLiteDatabase openOrCreateDatabase(String name, 1133 int mode, CursorFactory factory); 1134 1135 /** 1136 * Open a new private SQLiteDatabase associated with this Context's 1137 * application package. Creates the database file if it doesn't exist. 1138 * 1139 * <p>Accepts input param: a concrete instance of {@link DatabaseErrorHandler} to be 1140 * used to handle corruption when sqlite reports database corruption.</p> 1141 * 1142 * @param name The name (unique in the application package) of the database. 1143 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the 1144 * default operation, {@link #MODE_WORLD_READABLE} 1145 * and {@link #MODE_WORLD_WRITEABLE} to control permissions. 1146 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default. 1147 * @param factory An optional factory class that is called to instantiate a 1148 * cursor when query is called. 1149 * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database 1150 * corruption. if null, {@link android.database.DefaultDatabaseErrorHandler} is assumed. 1151 * @return The contents of a newly created database with the given name. 1152 * @throws android.database.sqlite.SQLiteException if the database file could not be opened. 1153 * 1154 * @see #MODE_PRIVATE 1155 * @see #MODE_WORLD_READABLE 1156 * @see #MODE_WORLD_WRITEABLE 1157 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING 1158 * @see #deleteDatabase 1159 */ 1160 public abstract SQLiteDatabase openOrCreateDatabase(String name, 1161 int mode, CursorFactory factory, 1162 @Nullable DatabaseErrorHandler errorHandler); 1163 1164 /** 1165 * Delete an existing private SQLiteDatabase associated with this Context's 1166 * application package. 1167 * 1168 * @param name The name (unique in the application package) of the 1169 * database. 1170 * 1171 * @return {@code true} if the database was successfully deleted; else {@code false}. 1172 * 1173 * @see #openOrCreateDatabase 1174 */ 1175 public abstract boolean deleteDatabase(String name); 1176 1177 /** 1178 * Returns the absolute path on the filesystem where a database created with 1179 * {@link #openOrCreateDatabase} is stored. 1180 * 1181 * @param name The name of the database for which you would like to get 1182 * its path. 1183 * 1184 * @return An absolute path to the given database. 1185 * 1186 * @see #openOrCreateDatabase 1187 */ 1188 public abstract File getDatabasePath(String name); 1189 1190 /** 1191 * Returns an array of strings naming the private databases associated with 1192 * this Context's application package. 1193 * 1194 * @return Array of strings naming the private databases. 1195 * 1196 * @see #openOrCreateDatabase 1197 * @see #deleteDatabase 1198 */ 1199 public abstract String[] databaseList(); 1200 1201 /** 1202 * @deprecated Use {@link android.app.WallpaperManager#getDrawable 1203 * WallpaperManager.get()} instead. 1204 */ 1205 @Deprecated 1206 public abstract Drawable getWallpaper(); 1207 1208 /** 1209 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable 1210 * WallpaperManager.peek()} instead. 1211 */ 1212 @Deprecated 1213 public abstract Drawable peekWallpaper(); 1214 1215 /** 1216 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth() 1217 * WallpaperManager.getDesiredMinimumWidth()} instead. 1218 */ 1219 @Deprecated 1220 public abstract int getWallpaperDesiredMinimumWidth(); 1221 1222 /** 1223 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight() 1224 * WallpaperManager.getDesiredMinimumHeight()} instead. 1225 */ 1226 @Deprecated 1227 public abstract int getWallpaperDesiredMinimumHeight(); 1228 1229 /** 1230 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap) 1231 * WallpaperManager.set()} instead. 1232 * <p>This method requires the caller to hold the permission 1233 * {@link android.Manifest.permission#SET_WALLPAPER}. 1234 */ 1235 @Deprecated 1236 public abstract void setWallpaper(Bitmap bitmap) throws IOException; 1237 1238 /** 1239 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream) 1240 * WallpaperManager.set()} instead. 1241 * <p>This method requires the caller to hold the permission 1242 * {@link android.Manifest.permission#SET_WALLPAPER}. 1243 */ 1244 @Deprecated 1245 public abstract void setWallpaper(InputStream data) throws IOException; 1246 1247 /** 1248 * @deprecated Use {@link android.app.WallpaperManager#clear 1249 * WallpaperManager.clear()} instead. 1250 * <p>This method requires the caller to hold the permission 1251 * {@link android.Manifest.permission#SET_WALLPAPER}. 1252 */ 1253 @Deprecated 1254 public abstract void clearWallpaper() throws IOException; 1255 1256 /** 1257 * Same as {@link #startActivity(Intent, Bundle)} with no options 1258 * specified. 1259 * 1260 * @param intent The description of the activity to start. 1261 * 1262 * @throws ActivityNotFoundException 1263 *` 1264 * @see #startActivity(Intent, Bundle) 1265 * @see PackageManager#resolveActivity 1266 */ 1267 public abstract void startActivity(@RequiresPermission Intent intent); 1268 1269 /** 1270 * Version of {@link #startActivity(Intent)} that allows you to specify the 1271 * user the activity will be started for. This is not available to applications 1272 * that are not pre-installed on the system image. Using it requires holding 1273 * the INTERACT_ACROSS_USERS_FULL permission. 1274 * @param intent The description of the activity to start. 1275 * @param user The UserHandle of the user to start this activity for. 1276 * @throws ActivityNotFoundException 1277 * @hide 1278 */ 1279 public void startActivityAsUser(@RequiresPermission Intent intent, UserHandle user) { 1280 throw new RuntimeException("Not implemented. Must override in a subclass."); 1281 } 1282 1283 /** 1284 * Launch a new activity. You will not receive any information about when 1285 * the activity exits. 1286 * 1287 * <p>Note that if this method is being called from outside of an 1288 * {@link android.app.Activity} Context, then the Intent must include 1289 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because, 1290 * without being started from an existing Activity, there is no existing 1291 * task in which to place the new activity and thus it needs to be placed 1292 * in its own separate task. 1293 * 1294 * <p>This method throws {@link ActivityNotFoundException} 1295 * if there was no Activity found to run the given Intent. 1296 * 1297 * @param intent The description of the activity to start. 1298 * @param options Additional options for how the Activity should be started. 1299 * May be null if there are no options. See {@link android.app.ActivityOptions} 1300 * for how to build the Bundle supplied here; there are no supported definitions 1301 * for building it manually. 1302 * 1303 * @throws ActivityNotFoundException 1304 * 1305 * @see #startActivity(Intent) 1306 * @see PackageManager#resolveActivity 1307 */ 1308 public abstract void startActivity(@RequiresPermission Intent intent, 1309 @Nullable Bundle options); 1310 1311 /** 1312 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the 1313 * user the activity will be started for. This is not available to applications 1314 * that are not pre-installed on the system image. Using it requires holding 1315 * the INTERACT_ACROSS_USERS_FULL permission. 1316 * @param intent The description of the activity to start. 1317 * @param options Additional options for how the Activity should be started. 1318 * May be null if there are no options. See {@link android.app.ActivityOptions} 1319 * for how to build the Bundle supplied here; there are no supported definitions 1320 * for building it manually. 1321 * @param userId The UserHandle of the user to start this activity for. 1322 * @throws ActivityNotFoundException 1323 * @hide 1324 */ 1325 public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options, 1326 UserHandle userId) { 1327 throw new RuntimeException("Not implemented. Must override in a subclass."); 1328 } 1329 1330 /** 1331 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This 1332 * is only supported for Views and Fragments. 1333 * @param who The identifier for the calling element that will receive the result. 1334 * @param intent The intent to start. 1335 * @param requestCode The code that will be returned with onActivityResult() identifying this 1336 * request. 1337 * @param options Additional options for how the Activity should be started. 1338 * May be null if there are no options. See {@link android.app.ActivityOptions} 1339 * for how to build the Bundle supplied here; there are no supported definitions 1340 * for building it manually. 1341 * @hide 1342 */ 1343 public void startActivityForResult( 1344 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) { 1345 throw new RuntimeException("This method is only implemented for Activity-based Contexts. " 1346 + "Check canStartActivityForResult() before calling."); 1347 } 1348 1349 /** 1350 * Identifies whether this Context instance will be able to process calls to 1351 * {@link #startActivityForResult(String, Intent, int, Bundle)}. 1352 * @hide 1353 */ 1354 public boolean canStartActivityForResult() { 1355 return false; 1356 } 1357 1358 /** 1359 * Same as {@link #startActivities(Intent[], Bundle)} with no options 1360 * specified. 1361 * 1362 * @param intents An array of Intents to be started. 1363 * 1364 * @throws ActivityNotFoundException 1365 * 1366 * @see #startActivities(Intent[], Bundle) 1367 * @see PackageManager#resolveActivity 1368 */ 1369 public abstract void startActivities(@RequiresPermission Intent[] intents); 1370 1371 /** 1372 * Launch multiple new activities. This is generally the same as calling 1373 * {@link #startActivity(Intent)} for the first Intent in the array, 1374 * that activity during its creation calling {@link #startActivity(Intent)} 1375 * for the second entry, etc. Note that unlike that approach, generally 1376 * none of the activities except the last in the array will be created 1377 * at this point, but rather will be created when the user first visits 1378 * them (due to pressing back from the activity on top). 1379 * 1380 * <p>This method throws {@link ActivityNotFoundException} 1381 * if there was no Activity found for <em>any</em> given Intent. In this 1382 * case the state of the activity stack is undefined (some Intents in the 1383 * list may be on it, some not), so you probably want to avoid such situations. 1384 * 1385 * @param intents An array of Intents to be started. 1386 * @param options Additional options for how the Activity should be started. 1387 * See {@link android.content.Context#startActivity(Intent, Bundle) 1388 * Context.startActivity(Intent, Bundle)} for more details. 1389 * 1390 * @throws ActivityNotFoundException 1391 * 1392 * @see #startActivities(Intent[]) 1393 * @see PackageManager#resolveActivity 1394 */ 1395 public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options); 1396 1397 /** 1398 * @hide 1399 * Launch multiple new activities. This is generally the same as calling 1400 * {@link #startActivity(Intent)} for the first Intent in the array, 1401 * that activity during its creation calling {@link #startActivity(Intent)} 1402 * for the second entry, etc. Note that unlike that approach, generally 1403 * none of the activities except the last in the array will be created 1404 * at this point, but rather will be created when the user first visits 1405 * them (due to pressing back from the activity on top). 1406 * 1407 * <p>This method throws {@link ActivityNotFoundException} 1408 * if there was no Activity found for <em>any</em> given Intent. In this 1409 * case the state of the activity stack is undefined (some Intents in the 1410 * list may be on it, some not), so you probably want to avoid such situations. 1411 * 1412 * @param intents An array of Intents to be started. 1413 * @param options Additional options for how the Activity should be started. 1414 * @param userHandle The user for whom to launch the activities 1415 * See {@link android.content.Context#startActivity(Intent, Bundle) 1416 * Context.startActivity(Intent, Bundle)} for more details. 1417 * 1418 * @throws ActivityNotFoundException 1419 * 1420 * @see #startActivities(Intent[]) 1421 * @see PackageManager#resolveActivity 1422 */ 1423 public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) { 1424 throw new RuntimeException("Not implemented. Must override in a subclass."); 1425 } 1426 1427 /** 1428 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)} 1429 * with no options specified. 1430 * 1431 * @param intent The IntentSender to launch. 1432 * @param fillInIntent If non-null, this will be provided as the 1433 * intent parameter to {@link IntentSender#sendIntent}. 1434 * @param flagsMask Intent flags in the original IntentSender that you 1435 * would like to change. 1436 * @param flagsValues Desired values for any bits set in 1437 * <var>flagsMask</var> 1438 * @param extraFlags Always set to 0. 1439 * 1440 * @see #startActivity(Intent) 1441 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle) 1442 */ 1443 public abstract void startIntentSender(IntentSender intent, 1444 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) 1445 throws IntentSender.SendIntentException; 1446 1447 /** 1448 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender 1449 * to start. If the IntentSender is for an activity, that activity will be started 1450 * as if you had called the regular {@link #startActivity(Intent)} 1451 * here; otherwise, its associated action will be executed (such as 1452 * sending a broadcast) as if you had called 1453 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it. 1454 * 1455 * @param intent The IntentSender to launch. 1456 * @param fillInIntent If non-null, this will be provided as the 1457 * intent parameter to {@link IntentSender#sendIntent}. 1458 * @param flagsMask Intent flags in the original IntentSender that you 1459 * would like to change. 1460 * @param flagsValues Desired values for any bits set in 1461 * <var>flagsMask</var> 1462 * @param extraFlags Always set to 0. 1463 * @param options Additional options for how the Activity should be started. 1464 * See {@link android.content.Context#startActivity(Intent, Bundle) 1465 * Context.startActivity(Intent, Bundle)} for more details. If options 1466 * have also been supplied by the IntentSender, options given here will 1467 * override any that conflict with those given by the IntentSender. 1468 * 1469 * @see #startActivity(Intent, Bundle) 1470 * @see #startIntentSender(IntentSender, Intent, int, int, int) 1471 */ 1472 public abstract void startIntentSender(IntentSender intent, 1473 @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, 1474 Bundle options) throws IntentSender.SendIntentException; 1475 1476 /** 1477 * Broadcast the given intent to all interested BroadcastReceivers. This 1478 * call is asynchronous; it returns immediately, and you will continue 1479 * executing while the receivers are run. No results are propagated from 1480 * receivers and receivers can not abort the broadcast. If you want 1481 * to allow receivers to propagate results or abort the broadcast, you must 1482 * send an ordered broadcast using 1483 * {@link #sendOrderedBroadcast(Intent, String)}. 1484 * 1485 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1486 * 1487 * @param intent The Intent to broadcast; all receivers matching this 1488 * Intent will receive the broadcast. 1489 * 1490 * @see android.content.BroadcastReceiver 1491 * @see #registerReceiver 1492 * @see #sendBroadcast(Intent, String) 1493 * @see #sendOrderedBroadcast(Intent, String) 1494 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) 1495 */ 1496 public abstract void sendBroadcast(@RequiresPermission Intent intent); 1497 1498 /** 1499 * Broadcast the given intent to all interested BroadcastReceivers, allowing 1500 * an optional required permission to be enforced. This 1501 * call is asynchronous; it returns immediately, and you will continue 1502 * executing while the receivers are run. No results are propagated from 1503 * receivers and receivers can not abort the broadcast. If you want 1504 * to allow receivers to propagate results or abort the broadcast, you must 1505 * send an ordered broadcast using 1506 * {@link #sendOrderedBroadcast(Intent, String)}. 1507 * 1508 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1509 * 1510 * @param intent The Intent to broadcast; all receivers matching this 1511 * Intent will receive the broadcast. 1512 * @param receiverPermission (optional) String naming a permission that 1513 * a receiver must hold in order to receive your broadcast. 1514 * If null, no permission is required. 1515 * 1516 * @see android.content.BroadcastReceiver 1517 * @see #registerReceiver 1518 * @see #sendBroadcast(Intent) 1519 * @see #sendOrderedBroadcast(Intent, String) 1520 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) 1521 */ 1522 public abstract void sendBroadcast(@RequiresPermission Intent intent, 1523 @Nullable String receiverPermission); 1524 1525 1526 /** 1527 * Broadcast the given intent to all interested BroadcastReceivers, allowing 1528 * an array of required permissions to be enforced. This call is asynchronous; it returns 1529 * immediately, and you will continue executing while the receivers are run. No results are 1530 * propagated from receivers and receivers can not abort the broadcast. If you want to allow 1531 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast 1532 * using {@link #sendOrderedBroadcast(Intent, String)}. 1533 * 1534 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1535 * 1536 * @param intent The Intent to broadcast; all receivers matching this 1537 * Intent will receive the broadcast. 1538 * @param receiverPermissions Array of names of permissions that a receiver must hold 1539 * in order to receive your broadcast. 1540 * If null or empty, no permissions are required. 1541 * 1542 * @see android.content.BroadcastReceiver 1543 * @see #registerReceiver 1544 * @see #sendBroadcast(Intent) 1545 * @see #sendOrderedBroadcast(Intent, String) 1546 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) 1547 * @hide 1548 */ 1549 public abstract void sendBroadcastMultiplePermissions(Intent intent, 1550 String[] receiverPermissions); 1551 1552 /** 1553 * Broadcast the given intent to all interested BroadcastReceivers, allowing 1554 * an optional required permission to be enforced. This 1555 * call is asynchronous; it returns immediately, and you will continue 1556 * executing while the receivers are run. No results are propagated from 1557 * receivers and receivers can not abort the broadcast. If you want 1558 * to allow receivers to propagate results or abort the broadcast, you must 1559 * send an ordered broadcast using 1560 * {@link #sendOrderedBroadcast(Intent, String)}. 1561 * 1562 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1563 * 1564 * @param intent The Intent to broadcast; all receivers matching this 1565 * Intent will receive the broadcast. 1566 * @param receiverPermission (optional) String naming a permission that 1567 * a receiver must hold in order to receive your broadcast. 1568 * If null, no permission is required. 1569 * @param options (optional) Additional sending options, generated from a 1570 * {@link android.app.BroadcastOptions}. 1571 * 1572 * @see android.content.BroadcastReceiver 1573 * @see #registerReceiver 1574 * @see #sendBroadcast(Intent) 1575 * @see #sendOrderedBroadcast(Intent, String) 1576 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) 1577 * @hide 1578 */ 1579 @SystemApi 1580 public abstract void sendBroadcast(Intent intent, 1581 @Nullable String receiverPermission, 1582 @Nullable Bundle options); 1583 1584 /** 1585 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification 1586 * of an associated app op as per {@link android.app.AppOpsManager}. 1587 * @hide 1588 */ 1589 public abstract void sendBroadcast(Intent intent, 1590 String receiverPermission, int appOp); 1591 1592 /** 1593 * Broadcast the given intent to all interested BroadcastReceivers, delivering 1594 * them one at a time to allow more preferred receivers to consume the 1595 * broadcast before it is delivered to less preferred receivers. This 1596 * call is asynchronous; it returns immediately, and you will continue 1597 * executing while the receivers are run. 1598 * 1599 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1600 * 1601 * @param intent The Intent to broadcast; all receivers matching this 1602 * Intent will receive the broadcast. 1603 * @param receiverPermission (optional) String naming a permissions that 1604 * a receiver must hold in order to receive your broadcast. 1605 * If null, no permission is required. 1606 * 1607 * @see android.content.BroadcastReceiver 1608 * @see #registerReceiver 1609 * @see #sendBroadcast(Intent) 1610 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) 1611 */ 1612 public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent, 1613 @Nullable String receiverPermission); 1614 1615 /** 1616 * Version of {@link #sendBroadcast(Intent)} that allows you to 1617 * receive data back from the broadcast. This is accomplished by 1618 * supplying your own BroadcastReceiver when calling, which will be 1619 * treated as a final receiver at the end of the broadcast -- its 1620 * {@link BroadcastReceiver#onReceive} method will be called with 1621 * the result values collected from the other receivers. The broadcast will 1622 * be serialized in the same way as calling 1623 * {@link #sendOrderedBroadcast(Intent, String)}. 1624 * 1625 * <p>Like {@link #sendBroadcast(Intent)}, this method is 1626 * asynchronous; it will return before 1627 * resultReceiver.onReceive() is called. 1628 * 1629 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1630 * 1631 * @param intent The Intent to broadcast; all receivers matching this 1632 * Intent will receive the broadcast. 1633 * @param receiverPermission String naming a permissions that 1634 * a receiver must hold in order to receive your broadcast. 1635 * If null, no permission is required. 1636 * @param resultReceiver Your own BroadcastReceiver to treat as the final 1637 * receiver of the broadcast. 1638 * @param scheduler A custom Handler with which to schedule the 1639 * resultReceiver callback; if null it will be 1640 * scheduled in the Context's main thread. 1641 * @param initialCode An initial value for the result code. Often 1642 * Activity.RESULT_OK. 1643 * @param initialData An initial value for the result data. Often 1644 * null. 1645 * @param initialExtras An initial value for the result extras. Often 1646 * null. 1647 * 1648 * @see #sendBroadcast(Intent) 1649 * @see #sendBroadcast(Intent, String) 1650 * @see #sendOrderedBroadcast(Intent, String) 1651 * @see android.content.BroadcastReceiver 1652 * @see #registerReceiver 1653 * @see android.app.Activity#RESULT_OK 1654 */ 1655 public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent, 1656 @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver, 1657 @Nullable Handler scheduler, int initialCode, @Nullable String initialData, 1658 @Nullable Bundle initialExtras); 1659 1660 /** 1661 * Version of {@link #sendBroadcast(Intent)} that allows you to 1662 * receive data back from the broadcast. This is accomplished by 1663 * supplying your own BroadcastReceiver when calling, which will be 1664 * treated as a final receiver at the end of the broadcast -- its 1665 * {@link BroadcastReceiver#onReceive} method will be called with 1666 * the result values collected from the other receivers. The broadcast will 1667 * be serialized in the same way as calling 1668 * {@link #sendOrderedBroadcast(Intent, String)}. 1669 * 1670 * <p>Like {@link #sendBroadcast(Intent)}, this method is 1671 * asynchronous; it will return before 1672 * resultReceiver.onReceive() is called. 1673 * 1674 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1675 * 1676 * 1677 * @param intent The Intent to broadcast; all receivers matching this 1678 * Intent will receive the broadcast. 1679 * @param receiverPermission String naming a permissions that 1680 * a receiver must hold in order to receive your broadcast. 1681 * If null, no permission is required. 1682 * @param options (optional) Additional sending options, generated from a 1683 * {@link android.app.BroadcastOptions}. 1684 * @param resultReceiver Your own BroadcastReceiver to treat as the final 1685 * receiver of the broadcast. 1686 * @param scheduler A custom Handler with which to schedule the 1687 * resultReceiver callback; if null it will be 1688 * scheduled in the Context's main thread. 1689 * @param initialCode An initial value for the result code. Often 1690 * Activity.RESULT_OK. 1691 * @param initialData An initial value for the result data. Often 1692 * null. 1693 * @param initialExtras An initial value for the result extras. Often 1694 * null. 1695 * @see #sendBroadcast(Intent) 1696 * @see #sendBroadcast(Intent, String) 1697 * @see #sendOrderedBroadcast(Intent, String) 1698 * @see android.content.BroadcastReceiver 1699 * @see #registerReceiver 1700 * @see android.app.Activity#RESULT_OK 1701 * @hide 1702 */ 1703 @SystemApi 1704 public abstract void sendOrderedBroadcast(@NonNull Intent intent, 1705 @Nullable String receiverPermission, @Nullable Bundle options, 1706 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler, 1707 int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras); 1708 1709 /** 1710 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler, 1711 * int, String, android.os.Bundle)}, but also allows specification 1712 * of an associated app op as per {@link android.app.AppOpsManager}. 1713 * @hide 1714 */ 1715 public abstract void sendOrderedBroadcast(Intent intent, 1716 String receiverPermission, int appOp, BroadcastReceiver resultReceiver, 1717 Handler scheduler, int initialCode, String initialData, 1718 Bundle initialExtras); 1719 1720 /** 1721 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the 1722 * user the broadcast will be sent to. This is not available to applications 1723 * that are not pre-installed on the system image. Using it requires holding 1724 * the INTERACT_ACROSS_USERS permission. 1725 * @param intent The intent to broadcast 1726 * @param user UserHandle to send the intent to. 1727 * @see #sendBroadcast(Intent) 1728 */ 1729 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent, 1730 UserHandle user); 1731 1732 /** 1733 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the 1734 * user the broadcast will be sent to. This is not available to applications 1735 * that are not pre-installed on the system image. Using it requires holding 1736 * the INTERACT_ACROSS_USERS permission. 1737 * 1738 * @param intent The Intent to broadcast; all receivers matching this 1739 * Intent will receive the broadcast. 1740 * @param user UserHandle to send the intent to. 1741 * @param receiverPermission (optional) String naming a permission that 1742 * a receiver must hold in order to receive your broadcast. 1743 * If null, no permission is required. 1744 * 1745 * @see #sendBroadcast(Intent, String) 1746 */ 1747 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent, 1748 UserHandle user, @Nullable String receiverPermission); 1749 1750 1751 /** 1752 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the 1753 * user the broadcast will be sent to. This is not available to applications 1754 * that are not pre-installed on the system image. Using it requires holding 1755 * the INTERACT_ACROSS_USERS permission. 1756 * 1757 * @param intent The Intent to broadcast; all receivers matching this 1758 * Intent will receive the broadcast. 1759 * @param user UserHandle to send the intent to. 1760 * @param receiverPermission (optional) String naming a permission that 1761 * a receiver must hold in order to receive your broadcast. 1762 * If null, no permission is required. 1763 * @param appOp The app op associated with the broadcast. 1764 * 1765 * @see #sendBroadcast(Intent, String) 1766 * 1767 * @hide 1768 */ 1769 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent, 1770 UserHandle user, @Nullable String receiverPermission, int appOp); 1771 1772 /** 1773 * Version of 1774 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)} 1775 * that allows you to specify the 1776 * user the broadcast will be sent to. This is not available to applications 1777 * that are not pre-installed on the system image. Using it requires holding 1778 * the INTERACT_ACROSS_USERS permission. 1779 * 1780 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1781 * 1782 * @param intent The Intent to broadcast; all receivers matching this 1783 * Intent will receive the broadcast. 1784 * @param user UserHandle to send the intent to. 1785 * @param receiverPermission String naming a permissions that 1786 * a receiver must hold in order to receive your broadcast. 1787 * If null, no permission is required. 1788 * @param resultReceiver Your own BroadcastReceiver to treat as the final 1789 * receiver of the broadcast. 1790 * @param scheduler A custom Handler with which to schedule the 1791 * resultReceiver callback; if null it will be 1792 * scheduled in the Context's main thread. 1793 * @param initialCode An initial value for the result code. Often 1794 * Activity.RESULT_OK. 1795 * @param initialData An initial value for the result data. Often 1796 * null. 1797 * @param initialExtras An initial value for the result extras. Often 1798 * null. 1799 * 1800 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) 1801 */ 1802 public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent, 1803 UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver, 1804 @Nullable Handler scheduler, int initialCode, @Nullable String initialData, 1805 @Nullable Bundle initialExtras); 1806 1807 /** 1808 * Similar to above but takes an appOp as well, to enforce restrictions. 1809 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String, 1810 * BroadcastReceiver, Handler, int, String, Bundle) 1811 * @hide 1812 */ 1813 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, 1814 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver, 1815 @Nullable Handler scheduler, int initialCode, @Nullable String initialData, 1816 @Nullable Bundle initialExtras); 1817 1818 /** 1819 * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle. 1820 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String, 1821 * BroadcastReceiver, Handler, int, String, Bundle) 1822 * @hide 1823 */ 1824 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, 1825 @Nullable String receiverPermission, int appOp, @Nullable Bundle options, 1826 BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, 1827 @Nullable String initialData, @Nullable Bundle initialExtras); 1828 1829 /** 1830 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the 1831 * Intent you are sending stays around after the broadcast is complete, 1832 * so that others can quickly retrieve that data through the return 1833 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In 1834 * all other ways, this behaves the same as 1835 * {@link #sendBroadcast(Intent)}. 1836 * 1837 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY} 1838 * permission in order to use this API. If you do not hold that 1839 * permission, {@link SecurityException} will be thrown. 1840 * 1841 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone 1842 * can access them), no protection (anyone can modify them), and many other problems. 1843 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em> 1844 * has changed, with another mechanism for apps to retrieve the current value whenever 1845 * desired. 1846 * 1847 * @param intent The Intent to broadcast; all receivers matching this 1848 * Intent will receive the broadcast, and the Intent will be held to 1849 * be re-broadcast to future receivers. 1850 * 1851 * @see #sendBroadcast(Intent) 1852 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle) 1853 */ 1854 @Deprecated 1855 public abstract void sendStickyBroadcast(@RequiresPermission Intent intent); 1856 1857 /** 1858 * <p>Version of {@link #sendStickyBroadcast} that allows you to 1859 * receive data back from the broadcast. This is accomplished by 1860 * supplying your own BroadcastReceiver when calling, which will be 1861 * treated as a final receiver at the end of the broadcast -- its 1862 * {@link BroadcastReceiver#onReceive} method will be called with 1863 * the result values collected from the other receivers. The broadcast will 1864 * be serialized in the same way as calling 1865 * {@link #sendOrderedBroadcast(Intent, String)}. 1866 * 1867 * <p>Like {@link #sendBroadcast(Intent)}, this method is 1868 * asynchronous; it will return before 1869 * resultReceiver.onReceive() is called. Note that the sticky data 1870 * stored is only the data you initially supply to the broadcast, not 1871 * the result of any changes made by the receivers. 1872 * 1873 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1874 * 1875 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone 1876 * can access them), no protection (anyone can modify them), and many other problems. 1877 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em> 1878 * has changed, with another mechanism for apps to retrieve the current value whenever 1879 * desired. 1880 * 1881 * @param intent The Intent to broadcast; all receivers matching this 1882 * Intent will receive the broadcast. 1883 * @param resultReceiver Your own BroadcastReceiver to treat as the final 1884 * receiver of the broadcast. 1885 * @param scheduler A custom Handler with which to schedule the 1886 * resultReceiver callback; if null it will be 1887 * scheduled in the Context's main thread. 1888 * @param initialCode An initial value for the result code. Often 1889 * Activity.RESULT_OK. 1890 * @param initialData An initial value for the result data. Often 1891 * null. 1892 * @param initialExtras An initial value for the result extras. Often 1893 * null. 1894 * 1895 * @see #sendBroadcast(Intent) 1896 * @see #sendBroadcast(Intent, String) 1897 * @see #sendOrderedBroadcast(Intent, String) 1898 * @see #sendStickyBroadcast(Intent) 1899 * @see android.content.BroadcastReceiver 1900 * @see #registerReceiver 1901 * @see android.app.Activity#RESULT_OK 1902 */ 1903 @Deprecated 1904 public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent, 1905 BroadcastReceiver resultReceiver, 1906 @Nullable Handler scheduler, int initialCode, @Nullable String initialData, 1907 @Nullable Bundle initialExtras); 1908 1909 /** 1910 * <p>Remove the data previously sent with {@link #sendStickyBroadcast}, 1911 * so that it is as if the sticky broadcast had never happened. 1912 * 1913 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY} 1914 * permission in order to use this API. If you do not hold that 1915 * permission, {@link SecurityException} will be thrown. 1916 * 1917 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone 1918 * can access them), no protection (anyone can modify them), and many other problems. 1919 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em> 1920 * has changed, with another mechanism for apps to retrieve the current value whenever 1921 * desired. 1922 * 1923 * @param intent The Intent that was previously broadcast. 1924 * 1925 * @see #sendStickyBroadcast 1926 */ 1927 @Deprecated 1928 public abstract void removeStickyBroadcast(@RequiresPermission Intent intent); 1929 1930 /** 1931 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the 1932 * user the broadcast will be sent to. This is not available to applications 1933 * that are not pre-installed on the system image. Using it requires holding 1934 * the INTERACT_ACROSS_USERS permission. 1935 * 1936 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone 1937 * can access them), no protection (anyone can modify them), and many other problems. 1938 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em> 1939 * has changed, with another mechanism for apps to retrieve the current value whenever 1940 * desired. 1941 * 1942 * @param intent The Intent to broadcast; all receivers matching this 1943 * Intent will receive the broadcast, and the Intent will be held to 1944 * be re-broadcast to future receivers. 1945 * @param user UserHandle to send the intent to. 1946 * 1947 * @see #sendBroadcast(Intent) 1948 */ 1949 @Deprecated 1950 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent, 1951 UserHandle user); 1952 1953 /** 1954 * <p>Version of 1955 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)} 1956 * that allows you to specify the 1957 * user the broadcast will be sent to. This is not available to applications 1958 * that are not pre-installed on the system image. Using it requires holding 1959 * the INTERACT_ACROSS_USERS permission. 1960 * 1961 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1962 * 1963 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone 1964 * can access them), no protection (anyone can modify them), and many other problems. 1965 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em> 1966 * has changed, with another mechanism for apps to retrieve the current value whenever 1967 * desired. 1968 * 1969 * @param intent The Intent to broadcast; all receivers matching this 1970 * Intent will receive the broadcast. 1971 * @param user UserHandle to send the intent to. 1972 * @param resultReceiver Your own BroadcastReceiver to treat as the final 1973 * receiver of the broadcast. 1974 * @param scheduler A custom Handler with which to schedule the 1975 * resultReceiver callback; if null it will be 1976 * scheduled in the Context's main thread. 1977 * @param initialCode An initial value for the result code. Often 1978 * Activity.RESULT_OK. 1979 * @param initialData An initial value for the result data. Often 1980 * null. 1981 * @param initialExtras An initial value for the result extras. Often 1982 * null. 1983 * 1984 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle) 1985 */ 1986 @Deprecated 1987 public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent, 1988 UserHandle user, BroadcastReceiver resultReceiver, 1989 @Nullable Handler scheduler, int initialCode, @Nullable String initialData, 1990 @Nullable Bundle initialExtras); 1991 1992 /** 1993 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the 1994 * user the broadcast will be sent to. This is not available to applications 1995 * that are not pre-installed on the system image. Using it requires holding 1996 * the INTERACT_ACROSS_USERS permission. 1997 * 1998 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY} 1999 * permission in order to use this API. If you do not hold that 2000 * permission, {@link SecurityException} will be thrown. 2001 * 2002 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone 2003 * can access them), no protection (anyone can modify them), and many other problems. 2004 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em> 2005 * has changed, with another mechanism for apps to retrieve the current value whenever 2006 * desired. 2007 * 2008 * @param intent The Intent that was previously broadcast. 2009 * @param user UserHandle to remove the sticky broadcast from. 2010 * 2011 * @see #sendStickyBroadcastAsUser 2012 */ 2013 @Deprecated 2014 public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent, 2015 UserHandle user); 2016 2017 /** 2018 * Register a BroadcastReceiver to be run in the main activity thread. The 2019 * <var>receiver</var> will be called with any broadcast Intent that 2020 * matches <var>filter</var>, in the main application thread. 2021 * 2022 * <p>The system may broadcast Intents that are "sticky" -- these stay 2023 * around after the broadcast as finished, to be sent to any later 2024 * registrations. If your IntentFilter matches one of these sticky 2025 * Intents, that Intent will be returned by this function 2026 * <strong>and</strong> sent to your <var>receiver</var> as if it had just 2027 * been broadcast. 2028 * 2029 * <p>There may be multiple sticky Intents that match <var>filter</var>, 2030 * in which case each of these will be sent to <var>receiver</var>. In 2031 * this case, only one of these can be returned directly by the function; 2032 * which of these that is returned is arbitrarily decided by the system. 2033 * 2034 * <p>If you know the Intent your are registering for is sticky, you can 2035 * supply null for your <var>receiver</var>. In this case, no receiver is 2036 * registered -- the function simply returns the sticky Intent that 2037 * matches <var>filter</var>. In the case of multiple matches, the same 2038 * rules as described above apply. 2039 * 2040 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 2041 * 2042 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers 2043 * registered with this method will correctly respect the 2044 * {@link Intent#setPackage(String)} specified for an Intent being broadcast. 2045 * Prior to that, it would be ignored and delivered to all matching registered 2046 * receivers. Be careful if using this for security.</p> 2047 * 2048 * <p class="note">Note: this method <em>cannot be called from a 2049 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver 2050 * that is declared in an application's manifest. It is okay, however, to call 2051 * this method from another BroadcastReceiver that has itself been registered 2052 * at run time with {@link #registerReceiver}, since the lifetime of such a 2053 * registered BroadcastReceiver is tied to the object that registered it.</p> 2054 * 2055 * @param receiver The BroadcastReceiver to handle the broadcast. 2056 * @param filter Selects the Intent broadcasts to be received. 2057 * 2058 * @return The first sticky intent found that matches <var>filter</var>, 2059 * or null if there are none. 2060 * 2061 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler) 2062 * @see #sendBroadcast 2063 * @see #unregisterReceiver 2064 */ 2065 @Nullable 2066 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver, 2067 IntentFilter filter); 2068 2069 /** 2070 * Register to receive intent broadcasts, to run in the context of 2071 * <var>scheduler</var>. See 2072 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more 2073 * information. This allows you to enforce permissions on who can 2074 * broadcast intents to your receiver, or have the receiver run in 2075 * a different thread than the main application thread. 2076 * 2077 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 2078 * 2079 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers 2080 * registered with this method will correctly respect the 2081 * {@link Intent#setPackage(String)} specified for an Intent being broadcast. 2082 * Prior to that, it would be ignored and delivered to all matching registered 2083 * receivers. Be careful if using this for security.</p> 2084 * 2085 * @param receiver The BroadcastReceiver to handle the broadcast. 2086 * @param filter Selects the Intent broadcasts to be received. 2087 * @param broadcastPermission String naming a permissions that a 2088 * broadcaster must hold in order to send an Intent to you. If null, 2089 * no permission is required. 2090 * @param scheduler Handler identifying the thread that will receive 2091 * the Intent. If null, the main thread of the process will be used. 2092 * 2093 * @return The first sticky intent found that matches <var>filter</var>, 2094 * or null if there are none. 2095 * 2096 * @see #registerReceiver(BroadcastReceiver, IntentFilter) 2097 * @see #sendBroadcast 2098 * @see #unregisterReceiver 2099 */ 2100 @Nullable 2101 public abstract Intent registerReceiver(BroadcastReceiver receiver, 2102 IntentFilter filter, @Nullable String broadcastPermission, 2103 @Nullable Handler scheduler); 2104 2105 /** 2106 * @hide 2107 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler) 2108 * but for a specific user. This receiver will receiver broadcasts that 2109 * are sent to the requested user. It 2110 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} 2111 * permission. 2112 * 2113 * @param receiver The BroadcastReceiver to handle the broadcast. 2114 * @param user UserHandle to send the intent to. 2115 * @param filter Selects the Intent broadcasts to be received. 2116 * @param broadcastPermission String naming a permissions that a 2117 * broadcaster must hold in order to send an Intent to you. If null, 2118 * no permission is required. 2119 * @param scheduler Handler identifying the thread that will receive 2120 * the Intent. If null, the main thread of the process will be used. 2121 * 2122 * @return The first sticky intent found that matches <var>filter</var>, 2123 * or null if there are none. 2124 * 2125 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler) 2126 * @see #sendBroadcast 2127 * @see #unregisterReceiver 2128 */ 2129 @Nullable 2130 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver, 2131 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission, 2132 @Nullable Handler scheduler); 2133 2134 /** 2135 * Unregister a previously registered BroadcastReceiver. <em>All</em> 2136 * filters that have been registered for this BroadcastReceiver will be 2137 * removed. 2138 * 2139 * @param receiver The BroadcastReceiver to unregister. 2140 * 2141 * @see #registerReceiver 2142 */ 2143 public abstract void unregisterReceiver(BroadcastReceiver receiver); 2144 2145 /** 2146 * Request that a given application service be started. The Intent 2147 * should contain either contain the complete class name of a specific service 2148 * implementation to start or a specific package name to target. If the 2149 * Intent is less specified, it log a warning about this and which of the 2150 * multiple matching services it finds and uses will be undefined. If this service 2151 * is not already running, it will be instantiated and started (creating a 2152 * process for it if needed); if it is running then it remains running. 2153 * 2154 * <p>Every call to this method will result in a corresponding call to 2155 * the target service's {@link android.app.Service#onStartCommand} method, 2156 * with the <var>intent</var> given here. This provides a convenient way 2157 * to submit jobs to a service without having to bind and call on to its 2158 * interface. 2159 * 2160 * <p>Using startService() overrides the default service lifetime that is 2161 * managed by {@link #bindService}: it requires the service to remain 2162 * running until {@link #stopService} is called, regardless of whether 2163 * any clients are connected to it. Note that calls to startService() 2164 * are not nesting: no matter how many times you call startService(), 2165 * a single call to {@link #stopService} will stop it. 2166 * 2167 * <p>The system attempts to keep running services around as much as 2168 * possible. The only time they should be stopped is if the current 2169 * foreground application is using so many resources that the service needs 2170 * to be killed. If any errors happen in the service's process, it will 2171 * automatically be restarted. 2172 * 2173 * <p>This function will throw {@link SecurityException} if you do not 2174 * have permission to start the given service. 2175 * 2176 * @param service Identifies the service to be started. The Intent must be either 2177 * fully explicit (supplying a component name) or specify a specific package 2178 * name it is targetted to. Additional values 2179 * may be included in the Intent extras to supply arguments along with 2180 * this specific start call. 2181 * 2182 * @return If the service is being started or is already running, the 2183 * {@link ComponentName} of the actual service that was started is 2184 * returned; else if the service does not exist null is returned. 2185 * 2186 * @throws SecurityException 2187 * 2188 * @see #stopService 2189 * @see #bindService 2190 */ 2191 @Nullable 2192 public abstract ComponentName startService(Intent service); 2193 2194 /** 2195 * Request that a given application service be stopped. If the service is 2196 * not running, nothing happens. Otherwise it is stopped. Note that calls 2197 * to startService() are not counted -- this stops the service no matter 2198 * how many times it was started. 2199 * 2200 * <p>Note that if a stopped service still has {@link ServiceConnection} 2201 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will 2202 * not be destroyed until all of these bindings are removed. See 2203 * the {@link android.app.Service} documentation for more details on a 2204 * service's lifecycle. 2205 * 2206 * <p>This function will throw {@link SecurityException} if you do not 2207 * have permission to stop the given service. 2208 * 2209 * @param service Description of the service to be stopped. The Intent must be either 2210 * fully explicit (supplying a component name) or specify a specific package 2211 * name it is targetted to. 2212 * 2213 * @return If there is a service matching the given Intent that is already 2214 * running, then it is stopped and {@code true} is returned; else {@code false} is returned. 2215 * 2216 * @throws SecurityException 2217 * 2218 * @see #startService 2219 */ 2220 public abstract boolean stopService(Intent service); 2221 2222 /** 2223 * @hide like {@link #startService(Intent)} but for a specific user. 2224 */ 2225 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user); 2226 2227 /** 2228 * @hide like {@link #stopService(Intent)} but for a specific user. 2229 */ 2230 public abstract boolean stopServiceAsUser(Intent service, UserHandle user); 2231 2232 /** 2233 * Connect to an application service, creating it if needed. This defines 2234 * a dependency between your application and the service. The given 2235 * <var>conn</var> will receive the service object when it is created and be 2236 * told if it dies and restarts. The service will be considered required 2237 * by the system only for as long as the calling context exists. For 2238 * example, if this Context is an Activity that is stopped, the service will 2239 * not be required to continue running until the Activity is resumed. 2240 * 2241 * <p>This function will throw {@link SecurityException} if you do not 2242 * have permission to bind to the given service. 2243 * 2244 * <p class="note">Note: this method <em>can not be called from a 2245 * {@link BroadcastReceiver} component</em>. A pattern you can use to 2246 * communicate from a BroadcastReceiver to a Service is to call 2247 * {@link #startService} with the arguments containing the command to be 2248 * sent, with the service calling its 2249 * {@link android.app.Service#stopSelf(int)} method when done executing 2250 * that command. See the API demo App/Service/Service Start Arguments 2251 * Controller for an illustration of this. It is okay, however, to use 2252 * this method from a BroadcastReceiver that has been registered with 2253 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver 2254 * is tied to another object (the one that registered it).</p> 2255 * 2256 * @param service Identifies the service to connect to. The Intent may 2257 * specify either an explicit component name, or a logical 2258 * description (action, category, etc) to match an 2259 * {@link IntentFilter} published by a service. 2260 * @param conn Receives information as the service is started and stopped. 2261 * This must be a valid ServiceConnection object; it must not be null. 2262 * @param flags Operation options for the binding. May be 0, 2263 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND}, 2264 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT}, 2265 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or 2266 * {@link #BIND_WAIVE_PRIORITY}. 2267 * @return If you have successfully bound to the service, {@code true} is returned; 2268 * {@code false} is returned if the connection is not made so you will not 2269 * receive the service object. 2270 * 2271 * @throws SecurityException 2272 * 2273 * @see #unbindService 2274 * @see #startService 2275 * @see #BIND_AUTO_CREATE 2276 * @see #BIND_DEBUG_UNBIND 2277 * @see #BIND_NOT_FOREGROUND 2278 */ 2279 public abstract boolean bindService(@RequiresPermission Intent service, 2280 @NonNull ServiceConnection conn, @BindServiceFlags int flags); 2281 2282 /** 2283 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle 2284 * argument for use by system server and other multi-user aware code. 2285 * @hide 2286 */ 2287 @SystemApi 2288 @SuppressWarnings("unused") 2289 public boolean bindServiceAsUser(@RequiresPermission Intent service, ServiceConnection conn, 2290 int flags, UserHandle user) { 2291 throw new RuntimeException("Not implemented. Must override in a subclass."); 2292 } 2293 2294 /** 2295 * Disconnect from an application service. You will no longer receive 2296 * calls as the service is restarted, and the service is now allowed to 2297 * stop at any time. 2298 * 2299 * @param conn The connection interface previously supplied to 2300 * bindService(). This parameter must not be null. 2301 * 2302 * @see #bindService 2303 */ 2304 public abstract void unbindService(@NonNull ServiceConnection conn); 2305 2306 /** 2307 * Start executing an {@link android.app.Instrumentation} class. The given 2308 * Instrumentation component will be run by killing its target application 2309 * (if currently running), starting the target process, instantiating the 2310 * instrumentation component, and then letting it drive the application. 2311 * 2312 * <p>This function is not synchronous -- it returns as soon as the 2313 * instrumentation has started and while it is running. 2314 * 2315 * <p>Instrumentation is normally only allowed to run against a package 2316 * that is either unsigned or signed with a signature that the 2317 * the instrumentation package is also signed with (ensuring the target 2318 * trusts the instrumentation). 2319 * 2320 * @param className Name of the Instrumentation component to be run. 2321 * @param profileFile Optional path to write profiling data as the 2322 * instrumentation runs, or null for no profiling. 2323 * @param arguments Additional optional arguments to pass to the 2324 * instrumentation, or null. 2325 * 2326 * @return {@code true} if the instrumentation was successfully started, 2327 * else {@code false} if it could not be found. 2328 */ 2329 public abstract boolean startInstrumentation(@NonNull ComponentName className, 2330 @Nullable String profileFile, @Nullable Bundle arguments); 2331 2332 /** @hide */ 2333 @StringDef({ 2334 POWER_SERVICE, 2335 WINDOW_SERVICE, 2336 LAYOUT_INFLATER_SERVICE, 2337 ACCOUNT_SERVICE, 2338 ACTIVITY_SERVICE, 2339 ALARM_SERVICE, 2340 NOTIFICATION_SERVICE, 2341 ACCESSIBILITY_SERVICE, 2342 CAPTIONING_SERVICE, 2343 KEYGUARD_SERVICE, 2344 LOCATION_SERVICE, 2345 //@hide: COUNTRY_DETECTOR, 2346 SEARCH_SERVICE, 2347 SENSOR_SERVICE, 2348 STORAGE_SERVICE, 2349 WALLPAPER_SERVICE, 2350 VIBRATOR_SERVICE, 2351 //@hide: STATUS_BAR_SERVICE, 2352 CONNECTIVITY_SERVICE, 2353 //@hide: UPDATE_LOCK_SERVICE, 2354 //@hide: NETWORKMANAGEMENT_SERVICE, 2355 NETWORK_STATS_SERVICE, 2356 //@hide: NETWORK_POLICY_SERVICE, 2357 WIFI_SERVICE, 2358 WIFI_PASSPOINT_SERVICE, 2359 WIFI_P2P_SERVICE, 2360 WIFI_SCANNING_SERVICE, 2361 //@hide: WIFI_RTT_SERVICE, 2362 //@hide: ETHERNET_SERVICE, 2363 WIFI_RTT_SERVICE, 2364 NSD_SERVICE, 2365 AUDIO_SERVICE, 2366 FINGERPRINT_SERVICE, 2367 MEDIA_ROUTER_SERVICE, 2368 TELEPHONY_SERVICE, 2369 TELEPHONY_SUBSCRIPTION_SERVICE, 2370 CARRIER_CONFIG_SERVICE, 2371 TELECOM_SERVICE, 2372 CLIPBOARD_SERVICE, 2373 INPUT_METHOD_SERVICE, 2374 TEXT_SERVICES_MANAGER_SERVICE, 2375 APPWIDGET_SERVICE, 2376 //@hide: VOICE_INTERACTION_MANAGER_SERVICE, 2377 //@hide: BACKUP_SERVICE, 2378 DROPBOX_SERVICE, 2379 //@hide: DEVICE_IDLE_CONTROLLER, 2380 DEVICE_POLICY_SERVICE, 2381 UI_MODE_SERVICE, 2382 DOWNLOAD_SERVICE, 2383 NFC_SERVICE, 2384 BLUETOOTH_SERVICE, 2385 //@hide: SIP_SERVICE, 2386 USB_SERVICE, 2387 LAUNCHER_APPS_SERVICE, 2388 //@hide: SERIAL_SERVICE, 2389 //@hide: HDMI_CONTROL_SERVICE, 2390 INPUT_SERVICE, 2391 DISPLAY_SERVICE, 2392 USER_SERVICE, 2393 RESTRICTIONS_SERVICE, 2394 APP_OPS_SERVICE, 2395 CAMERA_SERVICE, 2396 PRINT_SERVICE, 2397 CONSUMER_IR_SERVICE, 2398 //@hide: TRUST_SERVICE, 2399 TV_INPUT_SERVICE, 2400 //@hide: NETWORK_SCORE_SERVICE, 2401 USAGE_STATS_SERVICE, 2402 MEDIA_SESSION_SERVICE, 2403 BATTERY_SERVICE, 2404 JOB_SCHEDULER_SERVICE, 2405 //@hide: PERSISTENT_DATA_BLOCK_SERVICE, 2406 MEDIA_PROJECTION_SERVICE, 2407 MIDI_SERVICE, 2408 RADIO_SERVICE, 2409 }) 2410 @Retention(RetentionPolicy.SOURCE) 2411 public @interface ServiceName {} 2412 2413 /** 2414 * Return the handle to a system-level service by name. The class of the 2415 * returned object varies by the requested name. Currently available names 2416 * are: 2417 * 2418 * <dl> 2419 * <dt> {@link #WINDOW_SERVICE} ("window") 2420 * <dd> The top-level window manager in which you can place custom 2421 * windows. The returned object is a {@link android.view.WindowManager}. 2422 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater") 2423 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources 2424 * in this context. 2425 * <dt> {@link #ACTIVITY_SERVICE} ("activity") 2426 * <dd> A {@link android.app.ActivityManager} for interacting with the 2427 * global activity state of the system. 2428 * <dt> {@link #POWER_SERVICE} ("power") 2429 * <dd> A {@link android.os.PowerManager} for controlling power 2430 * management. 2431 * <dt> {@link #ALARM_SERVICE} ("alarm") 2432 * <dd> A {@link android.app.AlarmManager} for receiving intents at the 2433 * time of your choosing. 2434 * <dt> {@link #NOTIFICATION_SERVICE} ("notification") 2435 * <dd> A {@link android.app.NotificationManager} for informing the user 2436 * of background events. 2437 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard") 2438 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard. 2439 * <dt> {@link #LOCATION_SERVICE} ("location") 2440 * <dd> A {@link android.location.LocationManager} for controlling location 2441 * (e.g., GPS) updates. 2442 * <dt> {@link #SEARCH_SERVICE} ("search") 2443 * <dd> A {@link android.app.SearchManager} for handling search. 2444 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator") 2445 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator 2446 * hardware. 2447 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection") 2448 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for 2449 * handling management of network connections. 2450 * <dt> {@link #WIFI_SERVICE} ("wifi") 2451 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of 2452 * Wi-Fi connectivity. 2453 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p") 2454 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of 2455 * Wi-Fi Direct connectivity. 2456 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method") 2457 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager} 2458 * for management of input methods. 2459 * <dt> {@link #UI_MODE_SERVICE} ("uimode") 2460 * <dd> An {@link android.app.UiModeManager} for controlling UI modes. 2461 * <dt> {@link #DOWNLOAD_SERVICE} ("download") 2462 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads 2463 * <dt> {@link #BATTERY_SERVICE} ("batterymanager") 2464 * <dd> A {@link android.os.BatteryManager} for managing battery state 2465 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager") 2466 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks 2467 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats") 2468 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network 2469 * usage statistics. 2470 * </dl> 2471 * 2472 * <p>Note: System services obtained via this API may be closely associated with 2473 * the Context in which they are obtained from. In general, do not share the 2474 * service objects between various different contexts (Activities, Applications, 2475 * Services, Providers, etc.) 2476 * 2477 * @param name The name of the desired service. 2478 * 2479 * @return The service or null if the name does not exist. 2480 * 2481 * @see #WINDOW_SERVICE 2482 * @see android.view.WindowManager 2483 * @see #LAYOUT_INFLATER_SERVICE 2484 * @see android.view.LayoutInflater 2485 * @see #ACTIVITY_SERVICE 2486 * @see android.app.ActivityManager 2487 * @see #POWER_SERVICE 2488 * @see android.os.PowerManager 2489 * @see #ALARM_SERVICE 2490 * @see android.app.AlarmManager 2491 * @see #NOTIFICATION_SERVICE 2492 * @see android.app.NotificationManager 2493 * @see #KEYGUARD_SERVICE 2494 * @see android.app.KeyguardManager 2495 * @see #LOCATION_SERVICE 2496 * @see android.location.LocationManager 2497 * @see #SEARCH_SERVICE 2498 * @see android.app.SearchManager 2499 * @see #SENSOR_SERVICE 2500 * @see android.hardware.SensorManager 2501 * @see #STORAGE_SERVICE 2502 * @see android.os.storage.StorageManager 2503 * @see #VIBRATOR_SERVICE 2504 * @see android.os.Vibrator 2505 * @see #CONNECTIVITY_SERVICE 2506 * @see android.net.ConnectivityManager 2507 * @see #WIFI_SERVICE 2508 * @see android.net.wifi.WifiManager 2509 * @see #AUDIO_SERVICE 2510 * @see android.media.AudioManager 2511 * @see #MEDIA_ROUTER_SERVICE 2512 * @see android.media.MediaRouter 2513 * @see #TELEPHONY_SERVICE 2514 * @see android.telephony.TelephonyManager 2515 * @see #TELEPHONY_SUBSCRIPTION_SERVICE 2516 * @see android.telephony.SubscriptionManager 2517 * @see #CARRIER_CONFIG_SERVICE 2518 * @see android.telephony.CarrierConfigManager 2519 * @see #INPUT_METHOD_SERVICE 2520 * @see android.view.inputmethod.InputMethodManager 2521 * @see #UI_MODE_SERVICE 2522 * @see android.app.UiModeManager 2523 * @see #DOWNLOAD_SERVICE 2524 * @see android.app.DownloadManager 2525 * @see #BATTERY_SERVICE 2526 * @see android.os.BatteryManager 2527 * @see #JOB_SCHEDULER_SERVICE 2528 * @see android.app.job.JobScheduler 2529 * @see #NETWORK_STATS_SERVICE 2530 * @see android.app.usage.NetworkStatsManager 2531 */ 2532 public abstract Object getSystemService(@ServiceName @NonNull String name); 2533 2534 /** 2535 * Return the handle to a system-level service by class. 2536 * <p> 2537 * Currently available classes are: 2538 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater}, 2539 * {@link android.app.ActivityManager}, {@link android.os.PowerManager}, 2540 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager}, 2541 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager}, 2542 * {@link android.app.SearchManager}, {@link android.os.Vibrator}, 2543 * {@link android.net.ConnectivityManager}, 2544 * {@link android.net.wifi.WifiManager}, 2545 * {@link android.media.AudioManager}, {@link android.media.MediaRouter}, 2546 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager}, 2547 * {@link android.view.inputmethod.InputMethodManager}, 2548 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager}, 2549 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler}, 2550 * {@link android.app.usage.NetworkStatsManager}. 2551 * </p><p> 2552 * Note: System services obtained via this API may be closely associated with 2553 * the Context in which they are obtained from. In general, do not share the 2554 * service objects between various different contexts (Activities, Applications, 2555 * Services, Providers, etc.) 2556 * </p> 2557 * 2558 * @param serviceClass The class of the desired service. 2559 * @return The service or null if the class is not a supported system service. 2560 */ 2561 @SuppressWarnings("unchecked") 2562 public final <T> T getSystemService(Class<T> serviceClass) { 2563 // Because subclasses may override getSystemService(String) we cannot 2564 // perform a lookup by class alone. We must first map the class to its 2565 // service name then invoke the string-based method. 2566 String serviceName = getSystemServiceName(serviceClass); 2567 return serviceName != null ? (T)getSystemService(serviceName) : null; 2568 } 2569 2570 /** 2571 * Gets the name of the system-level service that is represented by the specified class. 2572 * 2573 * @param serviceClass The class of the desired service. 2574 * @return The service name or null if the class is not a supported system service. 2575 */ 2576 public abstract String getSystemServiceName(Class<?> serviceClass); 2577 2578 /** 2579 * Use with {@link #getSystemService} to retrieve a 2580 * {@link android.os.PowerManager} for controlling power management, 2581 * including "wake locks," which let you keep the device on while 2582 * you're running long tasks. 2583 */ 2584 public static final String POWER_SERVICE = "power"; 2585 2586 /** 2587 * Use with {@link #getSystemService} to retrieve a 2588 * {@link android.view.WindowManager} for accessing the system's window 2589 * manager. 2590 * 2591 * @see #getSystemService 2592 * @see android.view.WindowManager 2593 */ 2594 public static final String WINDOW_SERVICE = "window"; 2595 2596 /** 2597 * Use with {@link #getSystemService} to retrieve a 2598 * {@link android.view.LayoutInflater} for inflating layout resources in this 2599 * context. 2600 * 2601 * @see #getSystemService 2602 * @see android.view.LayoutInflater 2603 */ 2604 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater"; 2605 2606 /** 2607 * Use with {@link #getSystemService} to retrieve a 2608 * {@link android.accounts.AccountManager} for receiving intents at a 2609 * time of your choosing. 2610 * 2611 * @see #getSystemService 2612 * @see android.accounts.AccountManager 2613 */ 2614 public static final String ACCOUNT_SERVICE = "account"; 2615 2616 /** 2617 * Use with {@link #getSystemService} to retrieve a 2618 * {@link android.app.ActivityManager} for interacting with the global 2619 * system state. 2620 * 2621 * @see #getSystemService 2622 * @see android.app.ActivityManager 2623 */ 2624 public static final String ACTIVITY_SERVICE = "activity"; 2625 2626 /** 2627 * Use with {@link #getSystemService} to retrieve a 2628 * {@link android.app.AlarmManager} for receiving intents at a 2629 * time of your choosing. 2630 * 2631 * @see #getSystemService 2632 * @see android.app.AlarmManager 2633 */ 2634 public static final String ALARM_SERVICE = "alarm"; 2635 2636 /** 2637 * Use with {@link #getSystemService} to retrieve a 2638 * {@link android.app.NotificationManager} for informing the user of 2639 * background events. 2640 * 2641 * @see #getSystemService 2642 * @see android.app.NotificationManager 2643 */ 2644 public static final String NOTIFICATION_SERVICE = "notification"; 2645 2646 /** 2647 * Use with {@link #getSystemService} to retrieve a 2648 * {@link android.view.accessibility.AccessibilityManager} for giving the user 2649 * feedback for UI events through the registered event listeners. 2650 * 2651 * @see #getSystemService 2652 * @see android.view.accessibility.AccessibilityManager 2653 */ 2654 public static final String ACCESSIBILITY_SERVICE = "accessibility"; 2655 2656 /** 2657 * Use with {@link #getSystemService} to retrieve a 2658 * {@link android.view.accessibility.CaptioningManager} for obtaining 2659 * captioning properties and listening for changes in captioning 2660 * preferences. 2661 * 2662 * @see #getSystemService 2663 * @see android.view.accessibility.CaptioningManager 2664 */ 2665 public static final String CAPTIONING_SERVICE = "captioning"; 2666 2667 /** 2668 * Use with {@link #getSystemService} to retrieve a 2669 * {@link android.app.NotificationManager} for controlling keyguard. 2670 * 2671 * @see #getSystemService 2672 * @see android.app.KeyguardManager 2673 */ 2674 public static final String KEYGUARD_SERVICE = "keyguard"; 2675 2676 /** 2677 * Use with {@link #getSystemService} to retrieve a {@link 2678 * android.location.LocationManager} for controlling location 2679 * updates. 2680 * 2681 * @see #getSystemService 2682 * @see android.location.LocationManager 2683 */ 2684 public static final String LOCATION_SERVICE = "location"; 2685 2686 /** 2687 * Use with {@link #getSystemService} to retrieve a 2688 * {@link android.location.CountryDetector} for detecting the country that 2689 * the user is in. 2690 * 2691 * @hide 2692 */ 2693 public static final String COUNTRY_DETECTOR = "country_detector"; 2694 2695 /** 2696 * Use with {@link #getSystemService} to retrieve a {@link 2697 * android.app.SearchManager} for handling searches. 2698 * 2699 * @see #getSystemService 2700 * @see android.app.SearchManager 2701 */ 2702 public static final String SEARCH_SERVICE = "search"; 2703 2704 /** 2705 * Use with {@link #getSystemService} to retrieve a {@link 2706 * android.hardware.SensorManager} for accessing sensors. 2707 * 2708 * @see #getSystemService 2709 * @see android.hardware.SensorManager 2710 */ 2711 public static final String SENSOR_SERVICE = "sensor"; 2712 2713 /** 2714 * Use with {@link #getSystemService} to retrieve a {@link 2715 * android.os.storage.StorageManager} for accessing system storage 2716 * functions. 2717 * 2718 * @see #getSystemService 2719 * @see android.os.storage.StorageManager 2720 */ 2721 public static final String STORAGE_SERVICE = "storage"; 2722 2723 /** 2724 * Use with {@link #getSystemService} to retrieve a 2725 * com.android.server.WallpaperService for accessing wallpapers. 2726 * 2727 * @see #getSystemService 2728 */ 2729 public static final String WALLPAPER_SERVICE = "wallpaper"; 2730 2731 /** 2732 * Use with {@link #getSystemService} to retrieve a {@link 2733 * android.os.Vibrator} for interacting with the vibration hardware. 2734 * 2735 * @see #getSystemService 2736 * @see android.os.Vibrator 2737 */ 2738 public static final String VIBRATOR_SERVICE = "vibrator"; 2739 2740 /** 2741 * Use with {@link #getSystemService} to retrieve a {@link 2742 * android.app.StatusBarManager} for interacting with the status bar. 2743 * 2744 * @see #getSystemService 2745 * @see android.app.StatusBarManager 2746 * @hide 2747 */ 2748 public static final String STATUS_BAR_SERVICE = "statusbar"; 2749 2750 /** 2751 * Use with {@link #getSystemService} to retrieve a {@link 2752 * android.net.ConnectivityManager} for handling management of 2753 * network connections. 2754 * 2755 * @see #getSystemService 2756 * @see android.net.ConnectivityManager 2757 */ 2758 public static final String CONNECTIVITY_SERVICE = "connectivity"; 2759 2760 /** 2761 * Use with {@link #getSystemService} to retrieve a {@link 2762 * android.os.IUpdateLock} for managing runtime sequences that 2763 * must not be interrupted by headless OTA application or similar. 2764 * 2765 * @hide 2766 * @see #getSystemService 2767 * @see android.os.UpdateLock 2768 */ 2769 public static final String UPDATE_LOCK_SERVICE = "updatelock"; 2770 2771 /** 2772 * Constant for the internal network management service, not really a Context service. 2773 * @hide 2774 */ 2775 public static final String NETWORKMANAGEMENT_SERVICE = "network_management"; 2776 2777 /** 2778 * Use with {@link #getSystemService} to retrieve a {@link 2779 * android.app.usage.NetworkStatsManager} for querying network usage stats. 2780 * 2781 * @see #getSystemService 2782 * @see android.app.usage.NetworkStatsManager 2783 */ 2784 public static final String NETWORK_STATS_SERVICE = "netstats"; 2785 /** {@hide} */ 2786 public static final String NETWORK_POLICY_SERVICE = "netpolicy"; 2787 2788 /** 2789 * Use with {@link #getSystemService} to retrieve a {@link 2790 * android.net.wifi.WifiManager} for handling management of 2791 * Wi-Fi access. 2792 * 2793 * @see #getSystemService 2794 * @see android.net.wifi.WifiManager 2795 */ 2796 public static final String WIFI_SERVICE = "wifi"; 2797 2798 /** 2799 * Use with {@link #getSystemService} to retrieve a {@link 2800 * android.net.wifi.passpoint.WifiPasspointManager} for handling management of 2801 * Wi-Fi passpoint access. 2802 * 2803 * @see #getSystemService 2804 * @see android.net.wifi.passpoint.WifiPasspointManager 2805 * @hide 2806 */ 2807 public static final String WIFI_PASSPOINT_SERVICE = "wifipasspoint"; 2808 2809 /** 2810 * Use with {@link #getSystemService} to retrieve a {@link 2811 * android.net.wifi.p2p.WifiP2pManager} for handling management of 2812 * Wi-Fi peer-to-peer connections. 2813 * 2814 * @see #getSystemService 2815 * @see android.net.wifi.p2p.WifiP2pManager 2816 */ 2817 public static final String WIFI_P2P_SERVICE = "wifip2p"; 2818 2819 /** 2820 * Use with {@link #getSystemService} to retrieve a {@link 2821 * android.net.wifi.WifiScanner} for scanning the wifi universe 2822 * 2823 * @see #getSystemService 2824 * @see android.net.wifi.WifiScanner 2825 * @hide 2826 */ 2827 @SystemApi 2828 public static final String WIFI_SCANNING_SERVICE = "wifiscanner"; 2829 2830 /** 2831 * Use with {@link #getSystemService} to retrieve a {@link 2832 * android.net.wifi.RttManager} for ranging devices with wifi 2833 * 2834 * @see #getSystemService 2835 * @see android.net.wifi.RttManager 2836 * @hide 2837 */ 2838 @SystemApi 2839 public static final String WIFI_RTT_SERVICE = "rttmanager"; 2840 2841 /** 2842 * Use with {@link #getSystemService} to retrieve a {@link 2843 * android.net.EthernetManager} for handling management of 2844 * Ethernet access. 2845 * 2846 * @see #getSystemService 2847 * @see android.net.EthernetManager 2848 * 2849 * @hide 2850 */ 2851 public static final String ETHERNET_SERVICE = "ethernet"; 2852 2853 /** 2854 * Use with {@link #getSystemService} to retrieve a {@link 2855 * android.net.nsd.NsdManager} for handling management of network service 2856 * discovery 2857 * 2858 * @see #getSystemService 2859 * @see android.net.nsd.NsdManager 2860 */ 2861 public static final String NSD_SERVICE = "servicediscovery"; 2862 2863 /** 2864 * Use with {@link #getSystemService} to retrieve a 2865 * {@link android.media.AudioManager} for handling management of volume, 2866 * ringer modes and audio routing. 2867 * 2868 * @see #getSystemService 2869 * @see android.media.AudioManager 2870 */ 2871 public static final String AUDIO_SERVICE = "audio"; 2872 2873 /** 2874 * Use with {@link #getSystemService} to retrieve a 2875 * {@link android.hardware.fingerprint.FingerprintManager} for handling management 2876 * of fingerprints. 2877 * 2878 * @see #getSystemService 2879 * @see android.hardware.fingerprint.FingerprintManager 2880 */ 2881 public static final String FINGERPRINT_SERVICE = "fingerprint"; 2882 2883 /** 2884 * Use with {@link #getSystemService} to retrieve a 2885 * {@link android.media.MediaRouter} for controlling and managing 2886 * routing of media. 2887 * 2888 * @see #getSystemService 2889 * @see android.media.MediaRouter 2890 */ 2891 public static final String MEDIA_ROUTER_SERVICE = "media_router"; 2892 2893 /** 2894 * Use with {@link #getSystemService} to retrieve a 2895 * {@link android.media.session.MediaSessionManager} for managing media Sessions. 2896 * 2897 * @see #getSystemService 2898 * @see android.media.session.MediaSessionManager 2899 */ 2900 public static final String MEDIA_SESSION_SERVICE = "media_session"; 2901 2902 /** 2903 * Use with {@link #getSystemService} to retrieve a 2904 * {@link android.telephony.TelephonyManager} for handling management the 2905 * telephony features of the device. 2906 * 2907 * @see #getSystemService 2908 * @see android.telephony.TelephonyManager 2909 */ 2910 public static final String TELEPHONY_SERVICE = "phone"; 2911 2912 /** 2913 * Use with {@link #getSystemService} to retrieve a 2914 * {@link android.telephony.SubscriptionManager} for handling management the 2915 * telephony subscriptions of the device. 2916 * 2917 * @see #getSystemService 2918 * @see android.telephony.SubscriptionManager 2919 */ 2920 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service"; 2921 2922 /** 2923 * Use with {@link #getSystemService} to retrieve a 2924 * {@link android.telecom.TelecomManager} to manage telecom-related features 2925 * of the device. 2926 * 2927 * @see #getSystemService 2928 * @see android.telecom.TelecomManager 2929 */ 2930 public static final String TELECOM_SERVICE = "telecom"; 2931 2932 /** 2933 * Use with {@link #getSystemService} to retrieve a 2934 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values. 2935 * 2936 * @see #getSystemService 2937 * @see android.telephony.CarrierConfigManager 2938 */ 2939 public static final String CARRIER_CONFIG_SERVICE = "carrier_config"; 2940 2941 /** 2942 * Use with {@link #getSystemService} to retrieve a 2943 * {@link android.text.ClipboardManager} for accessing and modifying 2944 * {@link android.content.ClipboardManager} for accessing and modifying 2945 * the contents of the global clipboard. 2946 * 2947 * @see #getSystemService 2948 * @see android.content.ClipboardManager 2949 */ 2950 public static final String CLIPBOARD_SERVICE = "clipboard"; 2951 2952 /** 2953 * Use with {@link #getSystemService} to retrieve a 2954 * {@link android.view.inputmethod.InputMethodManager} for accessing input 2955 * methods. 2956 * 2957 * @see #getSystemService 2958 */ 2959 public static final String INPUT_METHOD_SERVICE = "input_method"; 2960 2961 /** 2962 * Use with {@link #getSystemService} to retrieve a 2963 * {@link android.view.textservice.TextServicesManager} for accessing 2964 * text services. 2965 * 2966 * @see #getSystemService 2967 */ 2968 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices"; 2969 2970 /** 2971 * Use with {@link #getSystemService} to retrieve a 2972 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets. 2973 * 2974 * @see #getSystemService 2975 */ 2976 public static final String APPWIDGET_SERVICE = "appwidget"; 2977 2978 /** 2979 * Official published name of the (internal) voice interaction manager service. 2980 * 2981 * @hide 2982 * @see #getSystemService 2983 */ 2984 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction"; 2985 2986 /** 2987 * Use with {@link #getSystemService} to retrieve an 2988 * {@link android.app.backup.IBackupManager IBackupManager} for communicating 2989 * with the backup mechanism. 2990 * @hide 2991 * 2992 * @see #getSystemService 2993 */ 2994 @SystemApi 2995 public static final String BACKUP_SERVICE = "backup"; 2996 2997 /** 2998 * Use with {@link #getSystemService} to retrieve a 2999 * {@link android.os.DropBoxManager} instance for recording 3000 * diagnostic logs. 3001 * @see #getSystemService 3002 */ 3003 public static final String DROPBOX_SERVICE = "dropbox"; 3004 3005 /** 3006 * System service name for the DeviceIdleController. There is no Java API for this. 3007 * @see #getSystemService 3008 * @hide 3009 */ 3010 public static final String DEVICE_IDLE_CONTROLLER = "deviceidle"; 3011 3012 /** 3013 * Use with {@link #getSystemService} to retrieve a 3014 * {@link android.app.admin.DevicePolicyManager} for working with global 3015 * device policy management. 3016 * 3017 * @see #getSystemService 3018 */ 3019 public static final String DEVICE_POLICY_SERVICE = "device_policy"; 3020 3021 /** 3022 * Use with {@link #getSystemService} to retrieve a 3023 * {@link android.app.UiModeManager} for controlling UI modes. 3024 * 3025 * @see #getSystemService 3026 */ 3027 public static final String UI_MODE_SERVICE = "uimode"; 3028 3029 /** 3030 * Use with {@link #getSystemService} to retrieve a 3031 * {@link android.app.DownloadManager} for requesting HTTP downloads. 3032 * 3033 * @see #getSystemService 3034 */ 3035 public static final String DOWNLOAD_SERVICE = "download"; 3036 3037 /** 3038 * Use with {@link #getSystemService} to retrieve a 3039 * {@link android.os.BatteryManager} for managing battery state. 3040 * 3041 * @see #getSystemService 3042 */ 3043 public static final String BATTERY_SERVICE = "batterymanager"; 3044 3045 /** 3046 * Use with {@link #getSystemService} to retrieve a 3047 * {@link android.nfc.NfcManager} for using NFC. 3048 * 3049 * @see #getSystemService 3050 */ 3051 public static final String NFC_SERVICE = "nfc"; 3052 3053 /** 3054 * Use with {@link #getSystemService} to retrieve a 3055 * {@link android.bluetooth.BluetoothManager} for using Bluetooth. 3056 * 3057 * @see #getSystemService 3058 */ 3059 public static final String BLUETOOTH_SERVICE = "bluetooth"; 3060 3061 /** 3062 * Use with {@link #getSystemService} to retrieve a 3063 * {@link android.net.sip.SipManager} for accessing the SIP related service. 3064 * 3065 * @see #getSystemService 3066 */ 3067 /** @hide */ 3068 public static final String SIP_SERVICE = "sip"; 3069 3070 /** 3071 * Use with {@link #getSystemService} to retrieve a {@link 3072 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host) 3073 * and for controlling this device's behavior as a USB device. 3074 * 3075 * @see #getSystemService 3076 * @see android.hardware.usb.UsbManager 3077 */ 3078 public static final String USB_SERVICE = "usb"; 3079 3080 /** 3081 * Use with {@link #getSystemService} to retrieve a {@link 3082 * android.hardware.SerialManager} for access to serial ports. 3083 * 3084 * @see #getSystemService 3085 * @see android.hardware.SerialManager 3086 * 3087 * @hide 3088 */ 3089 public static final String SERIAL_SERVICE = "serial"; 3090 3091 /** 3092 * Use with {@link #getSystemService} to retrieve a 3093 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing 3094 * HDMI-CEC protocol. 3095 * 3096 * @see #getSystemService 3097 * @see android.hardware.hdmi.HdmiControlManager 3098 * @hide 3099 */ 3100 @SystemApi 3101 public static final String HDMI_CONTROL_SERVICE = "hdmi_control"; 3102 3103 /** 3104 * Use with {@link #getSystemService} to retrieve a 3105 * {@link android.hardware.input.InputManager} for interacting with input devices. 3106 * 3107 * @see #getSystemService 3108 * @see android.hardware.input.InputManager 3109 */ 3110 public static final String INPUT_SERVICE = "input"; 3111 3112 /** 3113 * Use with {@link #getSystemService} to retrieve a 3114 * {@link android.hardware.display.DisplayManager} for interacting with display devices. 3115 * 3116 * @see #getSystemService 3117 * @see android.hardware.display.DisplayManager 3118 */ 3119 public static final String DISPLAY_SERVICE = "display"; 3120 3121 /** 3122 * Use with {@link #getSystemService} to retrieve a 3123 * {@link android.os.UserManager} for managing users on devices that support multiple users. 3124 * 3125 * @see #getSystemService 3126 * @see android.os.UserManager 3127 */ 3128 public static final String USER_SERVICE = "user"; 3129 3130 /** 3131 * Use with {@link #getSystemService} to retrieve a 3132 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across 3133 * profiles of a user. 3134 * 3135 * @see #getSystemService 3136 * @see android.content.pm.LauncherApps 3137 */ 3138 public static final String LAUNCHER_APPS_SERVICE = "launcherapps"; 3139 3140 /** 3141 * Use with {@link #getSystemService} to retrieve a 3142 * {@link android.content.RestrictionsManager} for retrieving application restrictions 3143 * and requesting permissions for restricted operations. 3144 * @see #getSystemService 3145 * @see android.content.RestrictionsManager 3146 */ 3147 public static final String RESTRICTIONS_SERVICE = "restrictions"; 3148 3149 /** 3150 * Use with {@link #getSystemService} to retrieve a 3151 * {@link android.app.AppOpsManager} for tracking application operations 3152 * on the device. 3153 * 3154 * @see #getSystemService 3155 * @see android.app.AppOpsManager 3156 */ 3157 public static final String APP_OPS_SERVICE = "appops"; 3158 3159 /** 3160 * Use with {@link #getSystemService} to retrieve a 3161 * {@link android.hardware.camera2.CameraManager} for interacting with 3162 * camera devices. 3163 * 3164 * @see #getSystemService 3165 * @see android.hardware.camera2.CameraManager 3166 */ 3167 public static final String CAMERA_SERVICE = "camera"; 3168 3169 /** 3170 * {@link android.print.PrintManager} for printing and managing 3171 * printers and print tasks. 3172 * 3173 * @see #getSystemService 3174 * @see android.print.PrintManager 3175 */ 3176 public static final String PRINT_SERVICE = "print"; 3177 3178 /** 3179 * Use with {@link #getSystemService} to retrieve a 3180 * {@link android.hardware.ConsumerIrManager} for transmitting infrared 3181 * signals from the device. 3182 * 3183 * @see #getSystemService 3184 * @see android.hardware.ConsumerIrManager 3185 */ 3186 public static final String CONSUMER_IR_SERVICE = "consumer_ir"; 3187 3188 /** 3189 * {@link android.app.trust.TrustManager} for managing trust agents. 3190 * @see #getSystemService 3191 * @see android.app.trust.TrustManager 3192 * @hide 3193 */ 3194 public static final String TRUST_SERVICE = "trust"; 3195 3196 /** 3197 * Use with {@link #getSystemService} to retrieve a 3198 * {@link android.media.tv.TvInputManager} for interacting with TV inputs 3199 * on the device. 3200 * 3201 * @see #getSystemService 3202 * @see android.media.tv.TvInputManager 3203 */ 3204 public static final String TV_INPUT_SERVICE = "tv_input"; 3205 3206 /** 3207 * {@link android.net.NetworkScoreManager} for managing network scoring. 3208 * @see #getSystemService 3209 * @see android.net.NetworkScoreManager 3210 * @hide 3211 */ 3212 @SystemApi 3213 public static final String NETWORK_SCORE_SERVICE = "network_score"; 3214 3215 /** 3216 * Use with {@link #getSystemService} to retrieve a {@link 3217 * android.app.usage.UsageStatsManager} for querying device usage stats. 3218 * 3219 * @see #getSystemService 3220 * @see android.app.usage.UsageStatsManager 3221 */ 3222 public static final String USAGE_STATS_SERVICE = "usagestats"; 3223 3224 /** 3225 * Use with {@link #getSystemService} to retrieve a {@link 3226 * android.app.job.JobScheduler} instance for managing occasional 3227 * background tasks. 3228 * @see #getSystemService 3229 * @see android.app.job.JobScheduler 3230 */ 3231 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler"; 3232 3233 /** 3234 * Use with {@link #getSystemService} to retrieve a {@link 3235 * android.service.persistentdata.PersistentDataBlockManager} instance 3236 * for interacting with a storage device that lives across factory resets. 3237 * 3238 * @see #getSystemService 3239 * @see android.service.persistentdata.PersistentDataBlockManager 3240 * @hide 3241 */ 3242 @SystemApi 3243 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block"; 3244 3245 /** 3246 * Use with {@link #getSystemService} to retrieve a {@link 3247 * android.media.projection.MediaProjectionManager} instance for managing 3248 * media projection sessions. 3249 * @see #getSystemService 3250 * @see android.media.projection.MediaProjectionManager 3251 */ 3252 public static final String MEDIA_PROJECTION_SERVICE = "media_projection"; 3253 3254 /** 3255 * Use with {@link #getSystemService} to retrieve a 3256 * {@link android.media.midi.MidiManager} for accessing the MIDI service. 3257 * 3258 * @see #getSystemService 3259 */ 3260 public static final String MIDI_SERVICE = "midi"; 3261 3262 3263 /** 3264 * Use with {@link #getSystemService} to retrieve a 3265 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service. 3266 * 3267 * @see #getSystemService 3268 * @hide 3269 */ 3270 public static final String RADIO_SERVICE = "radio"; 3271 3272 /** 3273 * Determine whether the given permission is allowed for a particular 3274 * process and user ID running in the system. 3275 * 3276 * @param permission The name of the permission being checked. 3277 * @param pid The process ID being checked against. Must be > 0. 3278 * @param uid The user ID being checked against. A uid of 0 is the root 3279 * user, which will pass every permission check. 3280 * 3281 * @return {@link PackageManager#PERMISSION_GRANTED} if the given 3282 * pid/uid is allowed that permission, or 3283 * {@link PackageManager#PERMISSION_DENIED} if it is not. 3284 * 3285 * @see PackageManager#checkPermission(String, String) 3286 * @see #checkCallingPermission 3287 */ 3288 @CheckResult(suggest="#enforcePermission(String,int,int,String)") 3289 @PackageManager.PermissionResult 3290 public abstract int checkPermission(@NonNull String permission, int pid, int uid); 3291 3292 /** @hide */ 3293 @PackageManager.PermissionResult 3294 public abstract int checkPermission(@NonNull String permission, int pid, int uid, 3295 IBinder callerToken); 3296 3297 /** 3298 * Determine whether the calling process of an IPC you are handling has been 3299 * granted a particular permission. This is basically the same as calling 3300 * {@link #checkPermission(String, int, int)} with the pid and uid returned 3301 * by {@link android.os.Binder#getCallingPid} and 3302 * {@link android.os.Binder#getCallingUid}. One important difference 3303 * is that if you are not currently processing an IPC, this function 3304 * will always fail. This is done to protect against accidentally 3305 * leaking permissions; you can use {@link #checkCallingOrSelfPermission} 3306 * to avoid this protection. 3307 * 3308 * @param permission The name of the permission being checked. 3309 * 3310 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling 3311 * pid/uid is allowed that permission, or 3312 * {@link PackageManager#PERMISSION_DENIED} if it is not. 3313 * 3314 * @see PackageManager#checkPermission(String, String) 3315 * @see #checkPermission 3316 * @see #checkCallingOrSelfPermission 3317 */ 3318 @CheckResult(suggest="#enforceCallingPermission(String,String)") 3319 @PackageManager.PermissionResult 3320 public abstract int checkCallingPermission(@NonNull String permission); 3321 3322 /** 3323 * Determine whether the calling process of an IPC <em>or you</em> have been 3324 * granted a particular permission. This is the same as 3325 * {@link #checkCallingPermission}, except it grants your own permissions 3326 * if you are not currently processing an IPC. Use with care! 3327 * 3328 * @param permission The name of the permission being checked. 3329 * 3330 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling 3331 * pid/uid is allowed that permission, or 3332 * {@link PackageManager#PERMISSION_DENIED} if it is not. 3333 * 3334 * @see PackageManager#checkPermission(String, String) 3335 * @see #checkPermission 3336 * @see #checkCallingPermission 3337 */ 3338 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)") 3339 @PackageManager.PermissionResult 3340 public abstract int checkCallingOrSelfPermission(@NonNull String permission); 3341 3342 /** 3343 * Determine whether <em>you</em> have been granted a particular permission. 3344 * 3345 * @param permission The name of the permission being checked. 3346 * 3347 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the 3348 * permission, or {@link PackageManager#PERMISSION_DENIED} if not. 3349 * 3350 * @see PackageManager#checkPermission(String, String) 3351 * @see #checkCallingPermission(String) 3352 */ 3353 @PackageManager.PermissionResult 3354 public abstract int checkSelfPermission(@NonNull String permission); 3355 3356 /** 3357 * If the given permission is not allowed for a particular process 3358 * and user ID running in the system, throw a {@link SecurityException}. 3359 * 3360 * @param permission The name of the permission being checked. 3361 * @param pid The process ID being checked against. Must be > 0. 3362 * @param uid The user ID being checked against. A uid of 0 is the root 3363 * user, which will pass every permission check. 3364 * @param message A message to include in the exception if it is thrown. 3365 * 3366 * @see #checkPermission(String, int, int) 3367 */ 3368 public abstract void enforcePermission( 3369 @NonNull String permission, int pid, int uid, @Nullable String message); 3370 3371 /** 3372 * If the calling process of an IPC you are handling has not been 3373 * granted a particular permission, throw a {@link 3374 * SecurityException}. This is basically the same as calling 3375 * {@link #enforcePermission(String, int, int, String)} with the 3376 * pid and uid returned by {@link android.os.Binder#getCallingPid} 3377 * and {@link android.os.Binder#getCallingUid}. One important 3378 * difference is that if you are not currently processing an IPC, 3379 * this function will always throw the SecurityException. This is 3380 * done to protect against accidentally leaking permissions; you 3381 * can use {@link #enforceCallingOrSelfPermission} to avoid this 3382 * protection. 3383 * 3384 * @param permission The name of the permission being checked. 3385 * @param message A message to include in the exception if it is thrown. 3386 * 3387 * @see #checkCallingPermission(String) 3388 */ 3389 public abstract void enforceCallingPermission( 3390 @NonNull String permission, @Nullable String message); 3391 3392 /** 3393 * If neither you nor the calling process of an IPC you are 3394 * handling has been granted a particular permission, throw a 3395 * {@link SecurityException}. This is the same as {@link 3396 * #enforceCallingPermission}, except it grants your own 3397 * permissions if you are not currently processing an IPC. Use 3398 * with care! 3399 * 3400 * @param permission The name of the permission being checked. 3401 * @param message A message to include in the exception if it is thrown. 3402 * 3403 * @see #checkCallingOrSelfPermission(String) 3404 */ 3405 public abstract void enforceCallingOrSelfPermission( 3406 @NonNull String permission, @Nullable String message); 3407 3408 /** 3409 * Grant permission to access a specific Uri to another package, regardless 3410 * of whether that package has general permission to access the Uri's 3411 * content provider. This can be used to grant specific, temporary 3412 * permissions, typically in response to user interaction (such as the 3413 * user opening an attachment that you would like someone else to 3414 * display). 3415 * 3416 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION 3417 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3418 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION 3419 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to 3420 * start an activity instead of this function directly. If you use this 3421 * function directly, you should be sure to call 3422 * {@link #revokeUriPermission} when the target should no longer be allowed 3423 * to access it. 3424 * 3425 * <p>To succeed, the content provider owning the Uri must have set the 3426 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions 3427 * grantUriPermissions} attribute in its manifest or included the 3428 * {@link android.R.styleable#AndroidManifestGrantUriPermission 3429 * <grant-uri-permissions>} tag. 3430 * 3431 * @param toPackage The package you would like to allow to access the Uri. 3432 * @param uri The Uri you would like to grant access to. 3433 * @param modeFlags The desired access modes. Any combination of 3434 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION 3435 * Intent.FLAG_GRANT_READ_URI_PERMISSION}, 3436 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION 3437 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}, 3438 * {@link Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION 3439 * Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION}, or 3440 * {@link Intent#FLAG_GRANT_PREFIX_URI_PERMISSION 3441 * Intent.FLAG_GRANT_PREFIX_URI_PERMISSION}. 3442 * 3443 * @see #revokeUriPermission 3444 */ 3445 public abstract void grantUriPermission(String toPackage, Uri uri, 3446 @Intent.GrantUriMode int modeFlags); 3447 3448 /** 3449 * Remove all permissions to access a particular content provider Uri 3450 * that were previously added with {@link #grantUriPermission}. The given 3451 * Uri will match all previously granted Uris that are the same or a 3452 * sub-path of the given Uri. That is, revoking "content://foo/target" will 3453 * revoke both "content://foo/target" and "content://foo/target/sub", but not 3454 * "content://foo". It will not remove any prefix grants that exist at a 3455 * higher level. 3456 * 3457 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have 3458 * regular permission access to a Uri, but had received access to it through 3459 * a specific Uri permission grant, you could not revoke that grant with this 3460 * function and a {@link SecurityException} would be thrown. As of 3461 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security exception, 3462 * but will remove whatever permission grants to the Uri had been given to the app 3463 * (or none).</p> 3464 * 3465 * @param uri The Uri you would like to revoke access to. 3466 * @param modeFlags The desired access modes. Any combination of 3467 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION 3468 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3469 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION 3470 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 3471 * 3472 * @see #grantUriPermission 3473 */ 3474 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags); 3475 3476 /** 3477 * Determine whether a particular process and user ID has been granted 3478 * permission to access a specific URI. This only checks for permissions 3479 * that have been explicitly granted -- if the given process/uid has 3480 * more general access to the URI's content provider then this check will 3481 * always fail. 3482 * 3483 * @param uri The uri that is being checked. 3484 * @param pid The process ID being checked against. Must be > 0. 3485 * @param uid The user ID being checked against. A uid of 0 is the root 3486 * user, which will pass every permission check. 3487 * @param modeFlags The type of access to grant. May be one or both of 3488 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3489 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 3490 * 3491 * @return {@link PackageManager#PERMISSION_GRANTED} if the given 3492 * pid/uid is allowed to access that uri, or 3493 * {@link PackageManager#PERMISSION_DENIED} if it is not. 3494 * 3495 * @see #checkCallingUriPermission 3496 */ 3497 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)") 3498 public abstract int checkUriPermission(Uri uri, int pid, int uid, 3499 @Intent.AccessUriMode int modeFlags); 3500 3501 /** @hide */ 3502 public abstract int checkUriPermission(Uri uri, int pid, int uid, 3503 @Intent.AccessUriMode int modeFlags, IBinder callerToken); 3504 3505 /** 3506 * Determine whether the calling process and user ID has been 3507 * granted permission to access a specific URI. This is basically 3508 * the same as calling {@link #checkUriPermission(Uri, int, int, 3509 * int)} with the pid and uid returned by {@link 3510 * android.os.Binder#getCallingPid} and {@link 3511 * android.os.Binder#getCallingUid}. One important difference is 3512 * that if you are not currently processing an IPC, this function 3513 * will always fail. 3514 * 3515 * @param uri The uri that is being checked. 3516 * @param modeFlags The type of access to grant. May be one or both of 3517 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3518 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 3519 * 3520 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller 3521 * is allowed to access that uri, or 3522 * {@link PackageManager#PERMISSION_DENIED} if it is not. 3523 * 3524 * @see #checkUriPermission(Uri, int, int, int) 3525 */ 3526 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)") 3527 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags); 3528 3529 /** 3530 * Determine whether the calling process of an IPC <em>or you</em> has been granted 3531 * permission to access a specific URI. This is the same as 3532 * {@link #checkCallingUriPermission}, except it grants your own permissions 3533 * if you are not currently processing an IPC. Use with care! 3534 * 3535 * @param uri The uri that is being checked. 3536 * @param modeFlags The type of access to grant. May be one or both of 3537 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3538 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 3539 * 3540 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller 3541 * is allowed to access that uri, or 3542 * {@link PackageManager#PERMISSION_DENIED} if it is not. 3543 * 3544 * @see #checkCallingUriPermission 3545 */ 3546 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)") 3547 public abstract int checkCallingOrSelfUriPermission(Uri uri, 3548 @Intent.AccessUriMode int modeFlags); 3549 3550 /** 3551 * Check both a Uri and normal permission. This allows you to perform 3552 * both {@link #checkPermission} and {@link #checkUriPermission} in one 3553 * call. 3554 * 3555 * @param uri The Uri whose permission is to be checked, or null to not 3556 * do this check. 3557 * @param readPermission The permission that provides overall read access, 3558 * or null to not do this check. 3559 * @param writePermission The permission that provides overall write 3560 * access, or null to not do this check. 3561 * @param pid The process ID being checked against. Must be > 0. 3562 * @param uid The user ID being checked against. A uid of 0 is the root 3563 * user, which will pass every permission check. 3564 * @param modeFlags The type of access to grant. May be one or both of 3565 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3566 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 3567 * 3568 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller 3569 * is allowed to access that uri or holds one of the given permissions, or 3570 * {@link PackageManager#PERMISSION_DENIED} if it is not. 3571 */ 3572 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)") 3573 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission, 3574 @Nullable String writePermission, int pid, int uid, 3575 @Intent.AccessUriMode int modeFlags); 3576 3577 /** 3578 * If a particular process and user ID has not been granted 3579 * permission to access a specific URI, throw {@link 3580 * SecurityException}. This only checks for permissions that have 3581 * been explicitly granted -- if the given process/uid has more 3582 * general access to the URI's content provider then this check 3583 * will always fail. 3584 * 3585 * @param uri The uri that is being checked. 3586 * @param pid The process ID being checked against. Must be > 0. 3587 * @param uid The user ID being checked against. A uid of 0 is the root 3588 * user, which will pass every permission check. 3589 * @param modeFlags The type of access to grant. May be one or both of 3590 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3591 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 3592 * @param message A message to include in the exception if it is thrown. 3593 * 3594 * @see #checkUriPermission(Uri, int, int, int) 3595 */ 3596 public abstract void enforceUriPermission( 3597 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message); 3598 3599 /** 3600 * If the calling process and user ID has not been granted 3601 * permission to access a specific URI, throw {@link 3602 * SecurityException}. This is basically the same as calling 3603 * {@link #enforceUriPermission(Uri, int, int, int, String)} with 3604 * the pid and uid returned by {@link 3605 * android.os.Binder#getCallingPid} and {@link 3606 * android.os.Binder#getCallingUid}. One important difference is 3607 * that if you are not currently processing an IPC, this function 3608 * will always throw a SecurityException. 3609 * 3610 * @param uri The uri that is being checked. 3611 * @param modeFlags The type of access to grant. May be one or both of 3612 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3613 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 3614 * @param message A message to include in the exception if it is thrown. 3615 * 3616 * @see #checkCallingUriPermission(Uri, int) 3617 */ 3618 public abstract void enforceCallingUriPermission( 3619 Uri uri, @Intent.AccessUriMode int modeFlags, String message); 3620 3621 /** 3622 * If the calling process of an IPC <em>or you</em> has not been 3623 * granted permission to access a specific URI, throw {@link 3624 * SecurityException}. This is the same as {@link 3625 * #enforceCallingUriPermission}, except it grants your own 3626 * permissions if you are not currently processing an IPC. Use 3627 * with care! 3628 * 3629 * @param uri The uri that is being checked. 3630 * @param modeFlags The type of access to grant. May be one or both of 3631 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3632 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 3633 * @param message A message to include in the exception if it is thrown. 3634 * 3635 * @see #checkCallingOrSelfUriPermission(Uri, int) 3636 */ 3637 public abstract void enforceCallingOrSelfUriPermission( 3638 Uri uri, @Intent.AccessUriMode int modeFlags, String message); 3639 3640 /** 3641 * Enforce both a Uri and normal permission. This allows you to perform 3642 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one 3643 * call. 3644 * 3645 * @param uri The Uri whose permission is to be checked, or null to not 3646 * do this check. 3647 * @param readPermission The permission that provides overall read access, 3648 * or null to not do this check. 3649 * @param writePermission The permission that provides overall write 3650 * access, or null to not do this check. 3651 * @param pid The process ID being checked against. Must be > 0. 3652 * @param uid The user ID being checked against. A uid of 0 is the root 3653 * user, which will pass every permission check. 3654 * @param modeFlags The type of access to grant. May be one or both of 3655 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 3656 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 3657 * @param message A message to include in the exception if it is thrown. 3658 * 3659 * @see #checkUriPermission(Uri, String, String, int, int, int) 3660 */ 3661 public abstract void enforceUriPermission( 3662 @Nullable Uri uri, @Nullable String readPermission, 3663 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags, 3664 @Nullable String message); 3665 3666 /** @hide */ 3667 @IntDef(flag = true, 3668 value = {CONTEXT_INCLUDE_CODE, CONTEXT_IGNORE_SECURITY, CONTEXT_RESTRICTED}) 3669 @Retention(RetentionPolicy.SOURCE) 3670 public @interface CreatePackageOptions {} 3671 3672 /** 3673 * Flag for use with {@link #createPackageContext}: include the application 3674 * code with the context. This means loading code into the caller's 3675 * process, so that {@link #getClassLoader()} can be used to instantiate 3676 * the application's classes. Setting this flags imposes security 3677 * restrictions on what application context you can access; if the 3678 * requested application can not be safely loaded into your process, 3679 * java.lang.SecurityException will be thrown. If this flag is not set, 3680 * there will be no restrictions on the packages that can be loaded, 3681 * but {@link #getClassLoader} will always return the default system 3682 * class loader. 3683 */ 3684 public static final int CONTEXT_INCLUDE_CODE = 0x00000001; 3685 3686 /** 3687 * Flag for use with {@link #createPackageContext}: ignore any security 3688 * restrictions on the Context being requested, allowing it to always 3689 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code 3690 * to be loaded into a process even when it isn't safe to do so. Use 3691 * with extreme care! 3692 */ 3693 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002; 3694 3695 /** 3696 * Flag for use with {@link #createPackageContext}: a restricted context may 3697 * disable specific features. For instance, a View associated with a restricted 3698 * context would ignore particular XML attributes. 3699 */ 3700 public static final int CONTEXT_RESTRICTED = 0x00000004; 3701 3702 /** 3703 * @hide Used to indicate we should tell the activity manager about the process 3704 * loading this code. 3705 */ 3706 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000; 3707 3708 /** 3709 * Return a new Context object for the given application name. This 3710 * Context is the same as what the named application gets when it is 3711 * launched, containing the same resources and class loader. Each call to 3712 * this method returns a new instance of a Context object; Context objects 3713 * are not shared, however they share common state (Resources, ClassLoader, 3714 * etc) so the Context instance itself is fairly lightweight. 3715 * 3716 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no 3717 * application with the given package name. 3718 * 3719 * <p>Throws {@link java.lang.SecurityException} if the Context requested 3720 * can not be loaded into the caller's process for security reasons (see 3721 * {@link #CONTEXT_INCLUDE_CODE} for more information}. 3722 * 3723 * @param packageName Name of the application's package. 3724 * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE} 3725 * or {@link #CONTEXT_IGNORE_SECURITY}. 3726 * 3727 * @return A {@link Context} for the application. 3728 * 3729 * @throws SecurityException 3730 * @throws PackageManager.NameNotFoundException if there is no application with 3731 * the given package name. 3732 */ 3733 public abstract Context createPackageContext(String packageName, 3734 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException; 3735 3736 /** 3737 * Similar to {@link #createPackageContext(String, int)}, but with a 3738 * different {@link UserHandle}. For example, {@link #getContentResolver()} 3739 * will open any {@link Uri} as the given user. 3740 * 3741 * @hide 3742 */ 3743 public abstract Context createPackageContextAsUser( 3744 String packageName, int flags, UserHandle user) 3745 throws PackageManager.NameNotFoundException; 3746 3747 /** 3748 * Creates a context given an {@link android.content.pm.ApplicationInfo}. 3749 * 3750 * @hide 3751 */ 3752 public abstract Context createApplicationContext(ApplicationInfo application, 3753 int flags) throws PackageManager.NameNotFoundException; 3754 3755 /** 3756 * Get the userId associated with this context 3757 * @return user id 3758 * 3759 * @hide 3760 */ 3761 public abstract int getUserId(); 3762 3763 /** 3764 * Return a new Context object for the current Context but whose resources 3765 * are adjusted to match the given Configuration. Each call to this method 3766 * returns a new instance of a Context object; Context objects are not 3767 * shared, however common state (ClassLoader, other Resources for the 3768 * same configuration) may be so the Context itself can be fairly lightweight. 3769 * 3770 * @param overrideConfiguration A {@link Configuration} specifying what 3771 * values to modify in the base Configuration of the original Context's 3772 * resources. If the base configuration changes (such as due to an 3773 * orientation change), the resources of this context will also change except 3774 * for those that have been explicitly overridden with a value here. 3775 * 3776 * @return A {@link Context} with the given configuration override. 3777 */ 3778 public abstract Context createConfigurationContext( 3779 @NonNull Configuration overrideConfiguration); 3780 3781 /** 3782 * Return a new Context object for the current Context but whose resources 3783 * are adjusted to match the metrics of the given Display. Each call to this method 3784 * returns a new instance of a Context object; Context objects are not 3785 * shared, however common state (ClassLoader, other Resources for the 3786 * same configuration) may be so the Context itself can be fairly lightweight. 3787 * 3788 * The returned display Context provides a {@link WindowManager} 3789 * (see {@link #getSystemService(String)}) that is configured to show windows 3790 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay} 3791 * method can be used to retrieve the Display from the returned Context. 3792 * 3793 * @param display A {@link Display} object specifying the display 3794 * for whose metrics the Context's resources should be tailored and upon which 3795 * new windows should be shown. 3796 * 3797 * @return A {@link Context} for the display. 3798 */ 3799 public abstract Context createDisplayContext(@NonNull Display display); 3800 3801 /** 3802 * Gets the display adjustments holder for this context. This information 3803 * is provided on a per-application or activity basis and is used to simulate lower density 3804 * display metrics for legacy applications and restricted screen sizes. 3805 * 3806 * @param displayId The display id for which to get compatibility info. 3807 * @return The compatibility info holder, or null if not required by the application. 3808 * @hide 3809 */ 3810 public abstract DisplayAdjustments getDisplayAdjustments(int displayId); 3811 3812 /** 3813 * Indicates whether this Context is restricted. 3814 * 3815 * @return {@code true} if this Context is restricted, {@code false} otherwise. 3816 * 3817 * @see #CONTEXT_RESTRICTED 3818 */ 3819 public boolean isRestricted() { 3820 return false; 3821 } 3822} 3823