Context.java revision ea7e91514ee1968d15713e82a5cca745e2c46a05
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.content.pm.ApplicationInfo; 20import android.content.pm.PackageManager; 21import android.content.res.AssetManager; 22import android.content.res.Configuration; 23import android.content.res.Resources; 24import android.content.res.TypedArray; 25import android.database.DatabaseErrorHandler; 26import android.database.sqlite.SQLiteDatabase; 27import android.database.sqlite.SQLiteDatabase.CursorFactory; 28import android.graphics.Bitmap; 29import android.graphics.drawable.Drawable; 30import android.media.MediaScannerConnection.OnScanCompletedListener; 31import android.net.Uri; 32import android.os.Bundle; 33import android.os.Handler; 34import android.os.Looper; 35import android.os.UserHandle; 36import android.util.AttributeSet; 37import android.view.CompatibilityInfoHolder; 38import android.view.Display; 39import android.view.WindowManager; 40 41import java.io.File; 42import java.io.FileInputStream; 43import java.io.FileNotFoundException; 44import java.io.FileOutputStream; 45import java.io.IOException; 46import java.io.InputStream; 47 48/** 49 * Interface to global information about an application environment. This is 50 * an abstract class whose implementation is provided by 51 * the Android system. It 52 * allows access to application-specific resources and classes, as well as 53 * up-calls for application-level operations such as launching activities, 54 * broadcasting and receiving intents, etc. 55 */ 56public abstract class Context { 57 /** 58 * File creation mode: the default mode, where the created file can only 59 * be accessed by the calling application (or all applications sharing the 60 * same user ID). 61 * @see #MODE_WORLD_READABLE 62 * @see #MODE_WORLD_WRITEABLE 63 */ 64 public static final int MODE_PRIVATE = 0x0000; 65 /** 66 * @deprecated Creating world-readable files is very dangerous, and likely 67 * to cause security holes in applications. It is strongly discouraged; 68 * instead, applications should use more formal mechanism for interactions 69 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and 70 * {@link android.app.Service}. There are no guarantees that this 71 * access mode will remain on a file, such as when it goes through a 72 * backup and restore. 73 * File creation mode: allow all other applications to have read access 74 * to the created file. 75 * @see #MODE_PRIVATE 76 * @see #MODE_WORLD_WRITEABLE 77 */ 78 @Deprecated 79 public static final int MODE_WORLD_READABLE = 0x0001; 80 /** 81 * @deprecated Creating world-writable files is very dangerous, and likely 82 * to cause security holes in applications. It is strongly discouraged; 83 * instead, applications should use more formal mechanism for interactions 84 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and 85 * {@link android.app.Service}. There are no guarantees that this 86 * access mode will remain on a file, such as when it goes through a 87 * backup and restore. 88 * File creation mode: allow all other applications to have write access 89 * to the created file. 90 * @see #MODE_PRIVATE 91 * @see #MODE_WORLD_READABLE 92 */ 93 @Deprecated 94 public static final int MODE_WORLD_WRITEABLE = 0x0002; 95 /** 96 * File creation mode: for use with {@link #openFileOutput}, if the file 97 * already exists then write data to the end of the existing file 98 * instead of erasing it. 99 * @see #openFileOutput 100 */ 101 public static final int MODE_APPEND = 0x8000; 102 103 /** 104 * SharedPreference loading flag: when set, the file on disk will 105 * be checked for modification even if the shared preferences 106 * instance is already loaded in this process. This behavior is 107 * sometimes desired in cases where the application has multiple 108 * processes, all writing to the same SharedPreferences file. 109 * Generally there are better forms of communication between 110 * processes, though. 111 * 112 * <p>This was the legacy (but undocumented) behavior in and 113 * before Gingerbread (Android 2.3) and this flag is implied when 114 * targetting such releases. For applications targetting SDK 115 * versions <em>greater than</em> Android 2.3, this flag must be 116 * explicitly set if desired. 117 * 118 * @see #getSharedPreferences 119 */ 120 public static final int MODE_MULTI_PROCESS = 0x0004; 121 122 /** 123 * Database open flag: when set, the database is opened with write-ahead 124 * logging enabled by default. 125 * 126 * @see #openOrCreateDatabase(String, int, CursorFactory) 127 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler) 128 * @see SQLiteDatabase#enableWriteAheadLogging 129 */ 130 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008; 131 132 /** 133 * Flag for {@link #bindService}: automatically create the service as long 134 * as the binding exists. Note that while this will create the service, 135 * its {@link android.app.Service#onStartCommand} 136 * method will still only be called due to an 137 * explicit call to {@link #startService}. Even without that, though, 138 * this still provides you with access to the service object while the 139 * service is created. 140 * 141 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, 142 * not supplying this flag would also impact how important the system 143 * consider's the target service's process to be. When set, the only way 144 * for it to be raised was by binding from a service in which case it will 145 * only be important when that activity is in the foreground. Now to 146 * achieve this behavior you must explicitly supply the new flag 147 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications 148 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have 149 * the flags {@link #BIND_WAIVE_PRIORITY} and 150 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve 151 * the same result. 152 */ 153 public static final int BIND_AUTO_CREATE = 0x0001; 154 155 /** 156 * Flag for {@link #bindService}: include debugging help for mismatched 157 * calls to unbind. When this flag is set, the callstack of the following 158 * {@link #unbindService} call is retained, to be printed if a later 159 * incorrect unbind call is made. Note that doing this requires retaining 160 * information about the binding that was made for the lifetime of the app, 161 * resulting in a leak -- this should only be used for debugging. 162 */ 163 public static final int BIND_DEBUG_UNBIND = 0x0002; 164 165 /** 166 * Flag for {@link #bindService}: don't allow this binding to raise 167 * the target service's process to the foreground scheduling priority. 168 * It will still be raised to at least the same memory priority 169 * as the client (so that its process will not be killable in any 170 * situation where the client is not killable), but for CPU scheduling 171 * purposes it may be left in the background. This only has an impact 172 * in the situation where the binding client is a foreground process 173 * and the target service is in a background process. 174 */ 175 public static final int BIND_NOT_FOREGROUND = 0x0004; 176 177 /** 178 * Flag for {@link #bindService}: indicates that the client application 179 * binding to this service considers the service to be more important than 180 * the app itself. When set, the platform will try to have the out of 181 * memory kill the app before it kills the service it is bound to, though 182 * this is not guaranteed to be the case. 183 */ 184 public static final int BIND_ABOVE_CLIENT = 0x0008; 185 186 /** 187 * Flag for {@link #bindService}: allow the process hosting the bound 188 * service to go through its normal memory management. It will be 189 * treated more like a running service, allowing the system to 190 * (temporarily) expunge the process if low on memory or for some other 191 * whim it may have, and being more aggressive about making it a candidate 192 * to be killed (and restarted) if running for a long time. 193 */ 194 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010; 195 196 /** 197 * Flag for {@link #bindService}: don't impact the scheduling or 198 * memory management priority of the target service's hosting process. 199 * Allows the service's process to be managed on the background LRU list 200 * just like a regular application process in the background. 201 */ 202 public static final int BIND_WAIVE_PRIORITY = 0x0020; 203 204 /** 205 * Flag for {@link #bindService}: this service is very important to 206 * the client, so should be brought to the foreground process level 207 * when the client is. Normally a process can only be raised to the 208 * visibility level by a client, even if that client is in the foreground. 209 */ 210 public static final int BIND_IMPORTANT = 0x0040; 211 212 /** 213 * Flag for {@link #bindService}: If binding from an activity, allow the 214 * target service's process importance to be raised based on whether the 215 * activity is visible to the user, regardless whether another flag is 216 * used to reduce the amount that the client process's overall importance 217 * is used to impact it. 218 */ 219 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080; 220 221 /** 222 * Flag for {@link #bindService}: Don't consider the bound service to be 223 * visible, even if the caller is visible. 224 * @hide 225 */ 226 public static final int BIND_NOT_VISIBLE = 0x40000000; 227 228 /** Return an AssetManager instance for your application's package. */ 229 public abstract AssetManager getAssets(); 230 231 /** Return a Resources instance for your application's package. */ 232 public abstract Resources getResources(); 233 234 /** Return PackageManager instance to find global package information. */ 235 public abstract PackageManager getPackageManager(); 236 237 /** Return a ContentResolver instance for your application's package. */ 238 public abstract ContentResolver getContentResolver(); 239 240 /** 241 * Return the Looper for the main thread of the current process. This is 242 * the thread used to dispatch calls to application components (activities, 243 * services, etc). 244 */ 245 public abstract Looper getMainLooper(); 246 247 /** 248 * Return the context of the single, global Application object of the 249 * current process. This generally should only be used if you need a 250 * Context whose lifecycle is separate from the current context, that is 251 * tied to the lifetime of the process rather than the current component. 252 * 253 * <p>Consider for example how this interacts with 254 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}: 255 * <ul> 256 * <li> <p>If used from an Activity context, the receiver is being registered 257 * within that activity. This means that you are expected to unregister 258 * before the activity is done being destroyed; in fact if you do not do 259 * so, the framework will clean up your leaked registration as it removes 260 * the activity and log an error. Thus, if you use the Activity context 261 * to register a receiver that is static (global to the process, not 262 * associated with an Activity instance) then that registration will be 263 * removed on you at whatever point the activity you used is destroyed. 264 * <li> <p>If used from the Context returned here, the receiver is being 265 * registered with the global state associated with your application. Thus 266 * it will never be unregistered for you. This is necessary if the receiver 267 * is associated with static data, not a particular component. However 268 * using the ApplicationContext elsewhere can easily lead to serious leaks 269 * if you forget to unregister, unbind, etc. 270 * </ul> 271 */ 272 public abstract Context getApplicationContext(); 273 274 /** 275 * Add a new {@link ComponentCallbacks} to the base application of the 276 * Context, which will be called at the same times as the ComponentCallbacks 277 * methods of activities and other components are called. Note that you 278 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when 279 * appropriate in the future; this will not be removed for you. 280 * 281 * @param callback The interface to call. This can be either a 282 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface. 283 */ 284 public void registerComponentCallbacks(ComponentCallbacks callback) { 285 getApplicationContext().registerComponentCallbacks(callback); 286 } 287 288 /** 289 * Remove a {@link ComponentCallbacks} objec that was previously registered 290 * with {@link #registerComponentCallbacks(ComponentCallbacks)}. 291 */ 292 public void unregisterComponentCallbacks(ComponentCallbacks callback) { 293 getApplicationContext().unregisterComponentCallbacks(callback); 294 } 295 296 /** 297 * Return a localized, styled CharSequence from the application's package's 298 * default string table. 299 * 300 * @param resId Resource id for the CharSequence text 301 */ 302 public final CharSequence getText(int resId) { 303 return getResources().getText(resId); 304 } 305 306 /** 307 * Return a localized string from the application's package's 308 * default string table. 309 * 310 * @param resId Resource id for the string 311 */ 312 public final String getString(int resId) { 313 return getResources().getString(resId); 314 } 315 316 /** 317 * Return a localized formatted string from the application's package's 318 * default string table, substituting the format arguments as defined in 319 * {@link java.util.Formatter} and {@link java.lang.String#format}. 320 * 321 * @param resId Resource id for the format string 322 * @param formatArgs The format arguments that will be used for substitution. 323 */ 324 325 public final String getString(int resId, Object... formatArgs) { 326 return getResources().getString(resId, formatArgs); 327 } 328 329 /** 330 * Set the base theme for this context. Note that this should be called 331 * before any views are instantiated in the Context (for example before 332 * calling {@link android.app.Activity#setContentView} or 333 * {@link android.view.LayoutInflater#inflate}). 334 * 335 * @param resid The style resource describing the theme. 336 */ 337 public abstract void setTheme(int resid); 338 339 /** @hide Needed for some internal implementation... not public because 340 * you can't assume this actually means anything. */ 341 public int getThemeResId() { 342 return 0; 343 } 344 345 /** 346 * Return the Theme object associated with this Context. 347 */ 348 public abstract Resources.Theme getTheme(); 349 350 /** 351 * Retrieve styled attribute information in this Context's theme. See 352 * {@link Resources.Theme#obtainStyledAttributes(int[])} 353 * for more information. 354 * 355 * @see Resources.Theme#obtainStyledAttributes(int[]) 356 */ 357 public final TypedArray obtainStyledAttributes( 358 int[] attrs) { 359 return getTheme().obtainStyledAttributes(attrs); 360 } 361 362 /** 363 * Retrieve styled attribute information in this Context's theme. See 364 * {@link Resources.Theme#obtainStyledAttributes(int, int[])} 365 * for more information. 366 * 367 * @see Resources.Theme#obtainStyledAttributes(int, int[]) 368 */ 369 public final TypedArray obtainStyledAttributes( 370 int resid, int[] attrs) throws Resources.NotFoundException { 371 return getTheme().obtainStyledAttributes(resid, attrs); 372 } 373 374 /** 375 * Retrieve styled attribute information in this Context's theme. See 376 * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)} 377 * for more information. 378 * 379 * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int) 380 */ 381 public final TypedArray obtainStyledAttributes( 382 AttributeSet set, int[] attrs) { 383 return getTheme().obtainStyledAttributes(set, attrs, 0, 0); 384 } 385 386 /** 387 * Retrieve styled attribute information in this Context's theme. See 388 * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)} 389 * for more information. 390 * 391 * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int) 392 */ 393 public final TypedArray obtainStyledAttributes( 394 AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) { 395 return getTheme().obtainStyledAttributes( 396 set, attrs, defStyleAttr, defStyleRes); 397 } 398 399 /** 400 * Return a class loader you can use to retrieve classes in this package. 401 */ 402 public abstract ClassLoader getClassLoader(); 403 404 /** Return the name of this application's package. */ 405 public abstract String getPackageName(); 406 407 /** Return the full application info for this context's package. */ 408 public abstract ApplicationInfo getApplicationInfo(); 409 410 /** 411 * Return the full path to this context's primary Android package. 412 * The Android package is a ZIP file which contains the application's 413 * primary resources. 414 * 415 * <p>Note: this is not generally useful for applications, since they should 416 * not be directly accessing the file system. 417 * 418 * @return String Path to the resources. 419 */ 420 public abstract String getPackageResourcePath(); 421 422 /** 423 * Return the full path to this context's primary Android package. 424 * The Android package is a ZIP file which contains application's 425 * primary code and assets. 426 * 427 * <p>Note: this is not generally useful for applications, since they should 428 * not be directly accessing the file system. 429 * 430 * @return String Path to the code and assets. 431 */ 432 public abstract String getPackageCodePath(); 433 434 /** 435 * {@hide} 436 * Return the full path to the shared prefs file for the given prefs group name. 437 * 438 * <p>Note: this is not generally useful for applications, since they should 439 * not be directly accessing the file system. 440 */ 441 public abstract File getSharedPrefsFile(String name); 442 443 /** 444 * Retrieve and hold the contents of the preferences file 'name', returning 445 * a SharedPreferences through which you can retrieve and modify its 446 * values. Only one instance of the SharedPreferences object is returned 447 * to any callers for the same name, meaning they will see each other's 448 * edits as soon as they are made. 449 * 450 * @param name Desired preferences file. If a preferences file by this name 451 * does not exist, it will be created when you retrieve an 452 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()). 453 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the 454 * default operation, {@link #MODE_WORLD_READABLE} 455 * and {@link #MODE_WORLD_WRITEABLE} to control permissions. The bit 456 * {@link #MODE_MULTI_PROCESS} can also be used if multiple processes 457 * are mutating the same SharedPreferences file. {@link #MODE_MULTI_PROCESS} 458 * is always on in apps targetting Gingerbread (Android 2.3) and below, and 459 * off by default in later versions. 460 * 461 * @return Returns the single SharedPreferences instance that can be used 462 * to retrieve and modify the preference values. 463 * 464 * @see #MODE_PRIVATE 465 * @see #MODE_WORLD_READABLE 466 * @see #MODE_WORLD_WRITEABLE 467 * @see #MODE_MULTI_PROCESS 468 */ 469 public abstract SharedPreferences getSharedPreferences(String name, 470 int mode); 471 472 /** 473 * Open a private file associated with this Context's application package 474 * for reading. 475 * 476 * @param name The name of the file to open; can not contain path 477 * separators. 478 * 479 * @return FileInputStream Resulting input stream. 480 * 481 * @see #openFileOutput 482 * @see #fileList 483 * @see #deleteFile 484 * @see java.io.FileInputStream#FileInputStream(String) 485 */ 486 public abstract FileInputStream openFileInput(String name) 487 throws FileNotFoundException; 488 489 /** 490 * Open a private file associated with this Context's application package 491 * for writing. Creates the file if it doesn't already exist. 492 * 493 * @param name The name of the file to open; can not contain path 494 * separators. 495 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the 496 * default operation, {@link #MODE_APPEND} to append to an existing file, 497 * {@link #MODE_WORLD_READABLE} and {@link #MODE_WORLD_WRITEABLE} to control 498 * permissions. 499 * 500 * @return FileOutputStream Resulting output stream. 501 * 502 * @see #MODE_APPEND 503 * @see #MODE_PRIVATE 504 * @see #MODE_WORLD_READABLE 505 * @see #MODE_WORLD_WRITEABLE 506 * @see #openFileInput 507 * @see #fileList 508 * @see #deleteFile 509 * @see java.io.FileOutputStream#FileOutputStream(String) 510 */ 511 public abstract FileOutputStream openFileOutput(String name, int mode) 512 throws FileNotFoundException; 513 514 /** 515 * Delete the given private file associated with this Context's 516 * application package. 517 * 518 * @param name The name of the file to delete; can not contain path 519 * separators. 520 * 521 * @return True if the file was successfully deleted; else 522 * false. 523 * 524 * @see #openFileInput 525 * @see #openFileOutput 526 * @see #fileList 527 * @see java.io.File#delete() 528 */ 529 public abstract boolean deleteFile(String name); 530 531 /** 532 * Returns the absolute path on the filesystem where a file created with 533 * {@link #openFileOutput} is stored. 534 * 535 * @param name The name of the file for which you would like to get 536 * its path. 537 * 538 * @return Returns an absolute path to the given file. 539 * 540 * @see #openFileOutput 541 * @see #getFilesDir 542 * @see #getDir 543 */ 544 public abstract File getFileStreamPath(String name); 545 546 /** 547 * Returns the absolute path to the directory on the filesystem where 548 * files created with {@link #openFileOutput} are stored. 549 * 550 * @return Returns the path of the directory holding application files. 551 * 552 * @see #openFileOutput 553 * @see #getFileStreamPath 554 * @see #getDir 555 */ 556 public abstract File getFilesDir(); 557 558 /** 559 * Returns the absolute path to the directory on the external filesystem 560 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory() 561 * Environment.getExternalStorageDirectory()}) where the application can 562 * place persistent files it owns. These files are private to the 563 * applications, and not typically visible to the user as media. 564 * 565 * <p>This is like {@link #getFilesDir()} in that these 566 * files will be deleted when the application is uninstalled, however there 567 * are some important differences: 568 * 569 * <ul> 570 * <li>External files are not always available: they will disappear if the 571 * user mounts the external storage on a computer or removes it. See the 572 * APIs on {@link android.os.Environment} for information in the storage state. 573 * <li>There is no security enforced with these files. All applications 574 * can read and write files placed here. 575 * </ul> 576 * 577 * <p>Here is an example of typical code to manipulate a file in 578 * an application's private storage:</p> 579 * 580 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java 581 * private_file} 582 * 583 * <p>If you supply a non-null <var>type</var> to this function, the returned 584 * file will be a path to a sub-directory of the given type. Though these files 585 * are not automatically scanned by the media scanner, you can explicitly 586 * add them to the media database with 587 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], 588 * OnScanCompletedListener) MediaScannerConnection.scanFile}. 589 * Note that this is not the same as 590 * {@link android.os.Environment#getExternalStoragePublicDirectory 591 * Environment.getExternalStoragePublicDirectory()}, which provides 592 * directories of media shared by all applications. The 593 * directories returned here are 594 * owned by the application, and their contents will be removed when the 595 * application is uninstalled. Unlike 596 * {@link android.os.Environment#getExternalStoragePublicDirectory 597 * Environment.getExternalStoragePublicDirectory()}, the directory 598 * returned here will be automatically created for you. 599 * 600 * <p>Here is an example of typical code to manipulate a picture in 601 * an application's private storage and add it to the media database:</p> 602 * 603 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java 604 * private_picture} 605 * 606 * @param type The type of files directory to return. May be null for 607 * the root of the files directory or one of 608 * the following Environment constants for a subdirectory: 609 * {@link android.os.Environment#DIRECTORY_MUSIC}, 610 * {@link android.os.Environment#DIRECTORY_PODCASTS}, 611 * {@link android.os.Environment#DIRECTORY_RINGTONES}, 612 * {@link android.os.Environment#DIRECTORY_ALARMS}, 613 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS}, 614 * {@link android.os.Environment#DIRECTORY_PICTURES}, or 615 * {@link android.os.Environment#DIRECTORY_MOVIES}. 616 * 617 * @return Returns the path of the directory holding application files 618 * on external storage. Returns null if external storage is not currently 619 * mounted so it could not ensure the path exists; you will need to call 620 * this method again when it is available. 621 * 622 * @see #getFilesDir 623 * @see android.os.Environment#getExternalStoragePublicDirectory 624 */ 625 public abstract File getExternalFilesDir(String type); 626 627 /** 628 * Return the directory where this application's OBB files (if there 629 * are any) can be found. Note if the application does not have any OBB 630 * files, this directory may not exist. 631 */ 632 public abstract File getObbDir(); 633 634 /** 635 * Returns the absolute path to the application specific cache directory 636 * on the filesystem. These files will be ones that get deleted first when the 637 * device runs low on storage. 638 * There is no guarantee when these files will be deleted. 639 * 640 * <strong>Note: you should not <em>rely</em> on the system deleting these 641 * files for you; you should always have a reasonable maximum, such as 1 MB, 642 * for the amount of space you consume with cache files, and prune those 643 * files when exceeding that space.</strong> 644 * 645 * @return Returns the path of the directory holding application cache files. 646 * 647 * @see #openFileOutput 648 * @see #getFileStreamPath 649 * @see #getDir 650 */ 651 public abstract File getCacheDir(); 652 653 /** 654 * Returns the absolute path to the directory on the external filesystem 655 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory() 656 * Environment.getExternalStorageDirectory()} where the application can 657 * place cache files it owns. 658 * 659 * <p>This is like {@link #getCacheDir()} in that these 660 * files will be deleted when the application is uninstalled, however there 661 * are some important differences: 662 * 663 * <ul> 664 * <li>The platform does not always monitor the space available in external 665 * storage, and thus may not automatically delete these files. Currently 666 * the only time files here will be deleted by the platform is when running 667 * on {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and 668 * {@link android.os.Environment#isExternalStorageEmulated() 669 * Environment.isExternalStorageEmulated()} returns true. Note that you should 670 * be managing the maximum space you will use for these anyway, just like 671 * with {@link #getCacheDir()}. 672 * <li>External files are not always available: they will disappear if the 673 * user mounts the external storage on a computer or removes it. See the 674 * APIs on {@link android.os.Environment} for information in the storage state. 675 * <li>There is no security enforced with these files. All applications 676 * can read and write files placed here. 677 * </ul> 678 * 679 * @return Returns the path of the directory holding application cache files 680 * on external storage. Returns null if external storage is not currently 681 * mounted so it could not ensure the path exists; you will need to call 682 * this method again when it is available. 683 * 684 * @see #getCacheDir 685 */ 686 public abstract File getExternalCacheDir(); 687 688 /** 689 * Returns an array of strings naming the private files associated with 690 * this Context's application package. 691 * 692 * @return Array of strings naming the private files. 693 * 694 * @see #openFileInput 695 * @see #openFileOutput 696 * @see #deleteFile 697 */ 698 public abstract String[] fileList(); 699 700 /** 701 * Retrieve, creating if needed, a new directory in which the application 702 * can place its own custom data files. You can use the returned File 703 * object to create and access files in this directory. Note that files 704 * created through a File object will only be accessible by your own 705 * application; you can only set the mode of the entire directory, not 706 * of individual files. 707 * 708 * @param name Name of the directory to retrieve. This is a directory 709 * that is created as part of your application data. 710 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the 711 * default operation, {@link #MODE_WORLD_READABLE} and 712 * {@link #MODE_WORLD_WRITEABLE} to control permissions. 713 * 714 * @return Returns a File object for the requested directory. The directory 715 * will have been created if it does not already exist. 716 * 717 * @see #openFileOutput(String, int) 718 */ 719 public abstract File getDir(String name, int mode); 720 721 /** 722 * Open a new private SQLiteDatabase associated with this Context's 723 * application package. Create the database file if it doesn't exist. 724 * 725 * @param name The name (unique in the application package) of the database. 726 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the 727 * default operation, {@link #MODE_WORLD_READABLE} 728 * and {@link #MODE_WORLD_WRITEABLE} to control permissions. 729 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default. 730 * @param factory An optional factory class that is called to instantiate a 731 * cursor when query is called. 732 * 733 * @return The contents of a newly created database with the given name. 734 * @throws android.database.sqlite.SQLiteException if the database file could not be opened. 735 * 736 * @see #MODE_PRIVATE 737 * @see #MODE_WORLD_READABLE 738 * @see #MODE_WORLD_WRITEABLE 739 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING 740 * @see #deleteDatabase 741 */ 742 public abstract SQLiteDatabase openOrCreateDatabase(String name, 743 int mode, CursorFactory factory); 744 745 /** 746 * Open a new private SQLiteDatabase associated with this Context's 747 * application package. Creates the database file if it doesn't exist. 748 * 749 * <p>Accepts input param: a concrete instance of {@link DatabaseErrorHandler} to be 750 * used to handle corruption when sqlite reports database corruption.</p> 751 * 752 * @param name The name (unique in the application package) of the database. 753 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the 754 * default operation, {@link #MODE_WORLD_READABLE} 755 * and {@link #MODE_WORLD_WRITEABLE} to control permissions. 756 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default. 757 * @param factory An optional factory class that is called to instantiate a 758 * cursor when query is called. 759 * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database 760 * corruption. if null, {@link android.database.DefaultDatabaseErrorHandler} is assumed. 761 * @return The contents of a newly created database with the given name. 762 * @throws android.database.sqlite.SQLiteException if the database file could not be opened. 763 * 764 * @see #MODE_PRIVATE 765 * @see #MODE_WORLD_READABLE 766 * @see #MODE_WORLD_WRITEABLE 767 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING 768 * @see #deleteDatabase 769 */ 770 public abstract SQLiteDatabase openOrCreateDatabase(String name, 771 int mode, CursorFactory factory, DatabaseErrorHandler errorHandler); 772 773 /** 774 * Delete an existing private SQLiteDatabase associated with this Context's 775 * application package. 776 * 777 * @param name The name (unique in the application package) of the 778 * database. 779 * 780 * @return True if the database was successfully deleted; else false. 781 * 782 * @see #openOrCreateDatabase 783 */ 784 public abstract boolean deleteDatabase(String name); 785 786 /** 787 * Returns the absolute path on the filesystem where a database created with 788 * {@link #openOrCreateDatabase} is stored. 789 * 790 * @param name The name of the database for which you would like to get 791 * its path. 792 * 793 * @return Returns an absolute path to the given database. 794 * 795 * @see #openOrCreateDatabase 796 */ 797 public abstract File getDatabasePath(String name); 798 799 /** 800 * Returns an array of strings naming the private databases associated with 801 * this Context's application package. 802 * 803 * @return Array of strings naming the private databases. 804 * 805 * @see #openOrCreateDatabase 806 * @see #deleteDatabase 807 */ 808 public abstract String[] databaseList(); 809 810 /** 811 * @deprecated Use {@link android.app.WallpaperManager#getDrawable 812 * WallpaperManager.get()} instead. 813 */ 814 @Deprecated 815 public abstract Drawable getWallpaper(); 816 817 /** 818 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable 819 * WallpaperManager.peek()} instead. 820 */ 821 @Deprecated 822 public abstract Drawable peekWallpaper(); 823 824 /** 825 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth() 826 * WallpaperManager.getDesiredMinimumWidth()} instead. 827 */ 828 @Deprecated 829 public abstract int getWallpaperDesiredMinimumWidth(); 830 831 /** 832 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight() 833 * WallpaperManager.getDesiredMinimumHeight()} instead. 834 */ 835 @Deprecated 836 public abstract int getWallpaperDesiredMinimumHeight(); 837 838 /** 839 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap) 840 * WallpaperManager.set()} instead. 841 * <p>This method requires the caller to hold the permission 842 * {@link android.Manifest.permission#SET_WALLPAPER}. 843 */ 844 @Deprecated 845 public abstract void setWallpaper(Bitmap bitmap) throws IOException; 846 847 /** 848 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream) 849 * WallpaperManager.set()} instead. 850 * <p>This method requires the caller to hold the permission 851 * {@link android.Manifest.permission#SET_WALLPAPER}. 852 */ 853 @Deprecated 854 public abstract void setWallpaper(InputStream data) throws IOException; 855 856 /** 857 * @deprecated Use {@link android.app.WallpaperManager#clear 858 * WallpaperManager.clear()} instead. 859 * <p>This method requires the caller to hold the permission 860 * {@link android.Manifest.permission#SET_WALLPAPER}. 861 */ 862 @Deprecated 863 public abstract void clearWallpaper() throws IOException; 864 865 /** 866 * Same as {@link #startActivity(Intent, Bundle)} with no options 867 * specified. 868 * 869 * @param intent The description of the activity to start. 870 * 871 * @throws ActivityNotFoundException 872 * 873 * @see {@link #startActivity(Intent, Bundle)} 874 * @see PackageManager#resolveActivity 875 */ 876 public abstract void startActivity(Intent intent); 877 878 /** 879 * Version of {@link #startActivity(Intent)} that allows you to specify the 880 * user the activity will be started for. This is not available to applications 881 * that are not pre-installed on the system image. Using it requires holding 882 * the INTERACT_ACROSS_USERS_FULL permission. 883 * @param intent The description of the activity to start. 884 * @param user The UserHandle of the user to start this activity for. 885 * @throws ActivityNotFoundException 886 * @hide 887 */ 888 public void startActivityAsUser(Intent intent, UserHandle user) { 889 throw new RuntimeException("Not implemented. Must override in a subclass."); 890 } 891 892 /** 893 * Launch a new activity. You will not receive any information about when 894 * the activity exits. 895 * 896 * <p>Note that if this method is being called from outside of an 897 * {@link android.app.Activity} Context, then the Intent must include 898 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because, 899 * without being started from an existing Activity, there is no existing 900 * task in which to place the new activity and thus it needs to be placed 901 * in its own separate task. 902 * 903 * <p>This method throws {@link ActivityNotFoundException} 904 * if there was no Activity found to run the given Intent. 905 * 906 * @param intent The description of the activity to start. 907 * @param options Additional options for how the Activity should be started. 908 * May be null if there are no options. See {@link android.app.ActivityOptions} 909 * for how to build the Bundle supplied here; there are no supported definitions 910 * for building it manually. 911 * 912 * @throws ActivityNotFoundException 913 * 914 * @see #startActivity(Intent) 915 * @see PackageManager#resolveActivity 916 */ 917 public abstract void startActivity(Intent intent, Bundle options); 918 919 /** 920 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the 921 * user the activity will be started for. This is not available to applications 922 * that are not pre-installed on the system image. Using it requires holding 923 * the INTERACT_ACROSS_USERS_FULL permission. 924 * @param intent The description of the activity to start. 925 * @param options Additional options for how the Activity should be started. 926 * May be null if there are no options. See {@link android.app.ActivityOptions} 927 * for how to build the Bundle supplied here; there are no supported definitions 928 * for building it manually. 929 * @param user The UserHandle of the user to start this activity for. 930 * @throws ActivityNotFoundException 931 * @hide 932 */ 933 public void startActivityAsUser(Intent intent, Bundle options, UserHandle userId) { 934 throw new RuntimeException("Not implemented. Must override in a subclass."); 935 } 936 937 /** 938 * Same as {@link #startActivities(Intent[], Bundle)} with no options 939 * specified. 940 * 941 * @param intents An array of Intents to be started. 942 * 943 * @throws ActivityNotFoundException 944 * 945 * @see {@link #startActivities(Intent[], Bundle)} 946 * @see PackageManager#resolveActivity 947 */ 948 public abstract void startActivities(Intent[] intents); 949 950 /** 951 * Launch multiple new activities. This is generally the same as calling 952 * {@link #startActivity(Intent)} for the first Intent in the array, 953 * that activity during its creation calling {@link #startActivity(Intent)} 954 * for the second entry, etc. Note that unlike that approach, generally 955 * none of the activities except the last in the array will be created 956 * at this point, but rather will be created when the user first visits 957 * them (due to pressing back from the activity on top). 958 * 959 * <p>This method throws {@link ActivityNotFoundException} 960 * if there was no Activity found for <em>any</em> given Intent. In this 961 * case the state of the activity stack is undefined (some Intents in the 962 * list may be on it, some not), so you probably want to avoid such situations. 963 * 964 * @param intents An array of Intents to be started. 965 * @param options Additional options for how the Activity should be started. 966 * See {@link android.content.Context#startActivity(Intent, Bundle) 967 * Context.startActivity(Intent, Bundle)} for more details. 968 * 969 * @throws ActivityNotFoundException 970 * 971 * @see {@link #startActivities(Intent[])} 972 * @see PackageManager#resolveActivity 973 */ 974 public abstract void startActivities(Intent[] intents, Bundle options); 975 976 /** 977 * @hide 978 * Launch multiple new activities. This is generally the same as calling 979 * {@link #startActivity(Intent)} for the first Intent in the array, 980 * that activity during its creation calling {@link #startActivity(Intent)} 981 * for the second entry, etc. Note that unlike that approach, generally 982 * none of the activities except the last in the array will be created 983 * at this point, but rather will be created when the user first visits 984 * them (due to pressing back from the activity on top). 985 * 986 * <p>This method throws {@link ActivityNotFoundException} 987 * if there was no Activity found for <em>any</em> given Intent. In this 988 * case the state of the activity stack is undefined (some Intents in the 989 * list may be on it, some not), so you probably want to avoid such situations. 990 * 991 * @param intents An array of Intents to be started. 992 * @param options Additional options for how the Activity should be started. 993 * @param userHandle The user for whom to launch the activities 994 * See {@link android.content.Context#startActivity(Intent, Bundle) 995 * Context.startActivity(Intent, Bundle)} for more details. 996 * 997 * @throws ActivityNotFoundException 998 * 999 * @see {@link #startActivities(Intent[])} 1000 * @see PackageManager#resolveActivity 1001 */ 1002 public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) { 1003 throw new RuntimeException("Not implemented. Must override in a subclass."); 1004 } 1005 1006 /** 1007 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)} 1008 * with no options specified. 1009 * 1010 * @param intent The IntentSender to launch. 1011 * @param fillInIntent If non-null, this will be provided as the 1012 * intent parameter to {@link IntentSender#sendIntent}. 1013 * @param flagsMask Intent flags in the original IntentSender that you 1014 * would like to change. 1015 * @param flagsValues Desired values for any bits set in 1016 * <var>flagsMask</var> 1017 * @param extraFlags Always set to 0. 1018 * 1019 * @see #startActivity(Intent) 1020 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle) 1021 */ 1022 public abstract void startIntentSender(IntentSender intent, 1023 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) 1024 throws IntentSender.SendIntentException; 1025 1026 /** 1027 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender 1028 * to start. If the IntentSender is for an activity, that activity will be started 1029 * as if you had called the regular {@link #startActivity(Intent)} 1030 * here; otherwise, its associated action will be executed (such as 1031 * sending a broadcast) as if you had called 1032 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it. 1033 * 1034 * @param intent The IntentSender to launch. 1035 * @param fillInIntent If non-null, this will be provided as the 1036 * intent parameter to {@link IntentSender#sendIntent}. 1037 * @param flagsMask Intent flags in the original IntentSender that you 1038 * would like to change. 1039 * @param flagsValues Desired values for any bits set in 1040 * <var>flagsMask</var> 1041 * @param extraFlags Always set to 0. 1042 * @param options Additional options for how the Activity should be started. 1043 * See {@link android.content.Context#startActivity(Intent, Bundle) 1044 * Context.startActivity(Intent, Bundle)} for more details. If options 1045 * have also been supplied by the IntentSender, options given here will 1046 * override any that conflict with those given by the IntentSender. 1047 * 1048 * @see #startActivity(Intent, Bundle) 1049 * @see #startIntentSender(IntentSender, Intent, int, int, int) 1050 */ 1051 public abstract void startIntentSender(IntentSender intent, 1052 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, 1053 Bundle options) throws IntentSender.SendIntentException; 1054 1055 /** 1056 * Broadcast the given intent to all interested BroadcastReceivers. This 1057 * call is asynchronous; it returns immediately, and you will continue 1058 * executing while the receivers are run. No results are propagated from 1059 * receivers and receivers can not abort the broadcast. If you want 1060 * to allow receivers to propagate results or abort the broadcast, you must 1061 * send an ordered broadcast using 1062 * {@link #sendOrderedBroadcast(Intent, String)}. 1063 * 1064 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1065 * 1066 * @param intent The Intent to broadcast; all receivers matching this 1067 * Intent will receive the broadcast. 1068 * 1069 * @see android.content.BroadcastReceiver 1070 * @see #registerReceiver 1071 * @see #sendBroadcast(Intent, String) 1072 * @see #sendOrderedBroadcast(Intent, String) 1073 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) 1074 */ 1075 public abstract void sendBroadcast(Intent intent); 1076 1077 /** 1078 * Broadcast the given intent to all interested BroadcastReceivers, allowing 1079 * an optional required permission to be enforced. This 1080 * call is asynchronous; it returns immediately, and you will continue 1081 * executing while the receivers are run. No results are propagated from 1082 * receivers and receivers can not abort the broadcast. If you want 1083 * to allow receivers to propagate results or abort the broadcast, you must 1084 * send an ordered broadcast using 1085 * {@link #sendOrderedBroadcast(Intent, String)}. 1086 * 1087 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1088 * 1089 * @param intent The Intent to broadcast; all receivers matching this 1090 * Intent will receive the broadcast. 1091 * @param receiverPermission (optional) String naming a permission that 1092 * a receiver must hold in order to receive your broadcast. 1093 * If null, no permission is required. 1094 * 1095 * @see android.content.BroadcastReceiver 1096 * @see #registerReceiver 1097 * @see #sendBroadcast(Intent) 1098 * @see #sendOrderedBroadcast(Intent, String) 1099 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) 1100 */ 1101 public abstract void sendBroadcast(Intent intent, 1102 String receiverPermission); 1103 1104 /** 1105 * Broadcast the given intent to all interested BroadcastReceivers, delivering 1106 * them one at a time to allow more preferred receivers to consume the 1107 * broadcast before it is delivered to less preferred receivers. This 1108 * call is asynchronous; it returns immediately, and you will continue 1109 * executing while the receivers are run. 1110 * 1111 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1112 * 1113 * @param intent The Intent to broadcast; all receivers matching this 1114 * Intent will receive the broadcast. 1115 * @param receiverPermission (optional) String naming a permissions that 1116 * a receiver must hold in order to receive your broadcast. 1117 * If null, no permission is required. 1118 * 1119 * @see android.content.BroadcastReceiver 1120 * @see #registerReceiver 1121 * @see #sendBroadcast(Intent) 1122 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) 1123 */ 1124 public abstract void sendOrderedBroadcast(Intent intent, 1125 String receiverPermission); 1126 1127 /** 1128 * Version of {@link #sendBroadcast(Intent)} that allows you to 1129 * receive data back from the broadcast. This is accomplished by 1130 * supplying your own BroadcastReceiver when calling, which will be 1131 * treated as a final receiver at the end of the broadcast -- its 1132 * {@link BroadcastReceiver#onReceive} method will be called with 1133 * the result values collected from the other receivers. The broadcast will 1134 * be serialized in the same way as calling 1135 * {@link #sendOrderedBroadcast(Intent, String)}. 1136 * 1137 * <p>Like {@link #sendBroadcast(Intent)}, this method is 1138 * asynchronous; it will return before 1139 * resultReceiver.onReceive() is called. 1140 * 1141 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1142 * 1143 * @param intent The Intent to broadcast; all receivers matching this 1144 * Intent will receive the broadcast. 1145 * @param receiverPermission String naming a permissions that 1146 * a receiver must hold in order to receive your broadcast. 1147 * If null, no permission is required. 1148 * @param resultReceiver Your own BroadcastReceiver to treat as the final 1149 * receiver of the broadcast. 1150 * @param scheduler A custom Handler with which to schedule the 1151 * resultReceiver callback; if null it will be 1152 * scheduled in the Context's main thread. 1153 * @param initialCode An initial value for the result code. Often 1154 * Activity.RESULT_OK. 1155 * @param initialData An initial value for the result data. Often 1156 * null. 1157 * @param initialExtras An initial value for the result extras. Often 1158 * null. 1159 * 1160 * @see #sendBroadcast(Intent) 1161 * @see #sendBroadcast(Intent, String) 1162 * @see #sendOrderedBroadcast(Intent, String) 1163 * @see #sendStickyBroadcast(Intent) 1164 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle) 1165 * @see android.content.BroadcastReceiver 1166 * @see #registerReceiver 1167 * @see android.app.Activity#RESULT_OK 1168 */ 1169 public abstract void sendOrderedBroadcast(Intent intent, 1170 String receiverPermission, BroadcastReceiver resultReceiver, 1171 Handler scheduler, int initialCode, String initialData, 1172 Bundle initialExtras); 1173 1174 /** 1175 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the 1176 * user the broadcast will be sent to. This is not available to applications 1177 * that are not pre-installed on the system image. Using it requires holding 1178 * the INTERACT_ACROSS_USERS permission. 1179 * @param intent The intent to broadcast 1180 * @param user UserHandle to send the intent to. 1181 * @see #sendBroadcast(Intent) 1182 */ 1183 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user); 1184 1185 /** 1186 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the 1187 * user the broadcast will be sent to. This is not available to applications 1188 * that are not pre-installed on the system image. Using it requires holding 1189 * the INTERACT_ACROSS_USERS permission. 1190 * 1191 * @param intent The Intent to broadcast; all receivers matching this 1192 * Intent will receive the broadcast. 1193 * @param user UserHandle to send the intent to. 1194 * @param receiverPermission (optional) String naming a permission that 1195 * a receiver must hold in order to receive your broadcast. 1196 * If null, no permission is required. 1197 * 1198 * @see #sendBroadcast(Intent, String) 1199 */ 1200 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user, 1201 String receiverPermission); 1202 1203 /** 1204 * Version of 1205 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)} 1206 * that allows you to specify the 1207 * user the broadcast will be sent to. This is not available to applications 1208 * that are not pre-installed on the system image. Using it requires holding 1209 * the INTERACT_ACROSS_USERS permission. 1210 * 1211 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1212 * 1213 * @param intent The Intent to broadcast; all receivers matching this 1214 * Intent will receive the broadcast. 1215 * @param user UserHandle to send the intent to. 1216 * @param receiverPermission String naming a permissions that 1217 * a receiver must hold in order to receive your broadcast. 1218 * If null, no permission is required. 1219 * @param resultReceiver Your own BroadcastReceiver to treat as the final 1220 * receiver of the broadcast. 1221 * @param scheduler A custom Handler with which to schedule the 1222 * resultReceiver callback; if null it will be 1223 * scheduled in the Context's main thread. 1224 * @param initialCode An initial value for the result code. Often 1225 * Activity.RESULT_OK. 1226 * @param initialData An initial value for the result data. Often 1227 * null. 1228 * @param initialExtras An initial value for the result extras. Often 1229 * null. 1230 * 1231 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) 1232 */ 1233 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, 1234 String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, 1235 int initialCode, String initialData, Bundle initialExtras); 1236 1237 /** 1238 * Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the 1239 * Intent you are sending stays around after the broadcast is complete, 1240 * so that others can quickly retrieve that data through the return 1241 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In 1242 * all other ways, this behaves the same as 1243 * {@link #sendBroadcast(Intent)}. 1244 * 1245 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY} 1246 * permission in order to use this API. If you do not hold that 1247 * permission, {@link SecurityException} will be thrown. 1248 * 1249 * @param intent The Intent to broadcast; all receivers matching this 1250 * Intent will receive the broadcast, and the Intent will be held to 1251 * be re-broadcast to future receivers. 1252 * 1253 * @see #sendBroadcast(Intent) 1254 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle) 1255 */ 1256 public abstract void sendStickyBroadcast(Intent intent); 1257 1258 /** 1259 * Version of {@link #sendStickyBroadcast} that allows you to 1260 * receive data back from the broadcast. This is accomplished by 1261 * supplying your own BroadcastReceiver when calling, which will be 1262 * treated as a final receiver at the end of the broadcast -- its 1263 * {@link BroadcastReceiver#onReceive} method will be called with 1264 * the result values collected from the other receivers. The broadcast will 1265 * be serialized in the same way as calling 1266 * {@link #sendOrderedBroadcast(Intent, String)}. 1267 * 1268 * <p>Like {@link #sendBroadcast(Intent)}, this method is 1269 * asynchronous; it will return before 1270 * resultReceiver.onReceive() is called. Note that the sticky data 1271 * stored is only the data you initially supply to the broadcast, not 1272 * the result of any changes made by the receivers. 1273 * 1274 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1275 * 1276 * @param intent The Intent to broadcast; all receivers matching this 1277 * Intent will receive the broadcast. 1278 * @param resultReceiver Your own BroadcastReceiver to treat as the final 1279 * receiver of the broadcast. 1280 * @param scheduler A custom Handler with which to schedule the 1281 * resultReceiver callback; if null it will be 1282 * scheduled in the Context's main thread. 1283 * @param initialCode An initial value for the result code. Often 1284 * Activity.RESULT_OK. 1285 * @param initialData An initial value for the result data. Often 1286 * null. 1287 * @param initialExtras An initial value for the result extras. Often 1288 * null. 1289 * 1290 * @see #sendBroadcast(Intent) 1291 * @see #sendBroadcast(Intent, String) 1292 * @see #sendOrderedBroadcast(Intent, String) 1293 * @see #sendStickyBroadcast(Intent) 1294 * @see android.content.BroadcastReceiver 1295 * @see #registerReceiver 1296 * @see android.app.Activity#RESULT_OK 1297 */ 1298 public abstract void sendStickyOrderedBroadcast(Intent intent, 1299 BroadcastReceiver resultReceiver, 1300 Handler scheduler, int initialCode, String initialData, 1301 Bundle initialExtras); 1302 1303 /** 1304 * Remove the data previously sent with {@link #sendStickyBroadcast}, 1305 * so that it is as if the sticky broadcast had never happened. 1306 * 1307 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY} 1308 * permission in order to use this API. If you do not hold that 1309 * permission, {@link SecurityException} will be thrown. 1310 * 1311 * @param intent The Intent that was previously broadcast. 1312 * 1313 * @see #sendStickyBroadcast 1314 */ 1315 public abstract void removeStickyBroadcast(Intent intent); 1316 1317 /** 1318 * Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the 1319 * user the broadcast will be sent to. This is not available to applications 1320 * that are not pre-installed on the system image. Using it requires holding 1321 * the INTERACT_ACROSS_USERS permission. 1322 * 1323 * @param intent The Intent to broadcast; all receivers matching this 1324 * Intent will receive the broadcast, and the Intent will be held to 1325 * be re-broadcast to future receivers. 1326 * @param user UserHandle to send the intent to. 1327 * 1328 * @see #sendBroadcast(Intent) 1329 */ 1330 public abstract void sendStickyBroadcastAsUser(Intent intent, UserHandle user); 1331 1332 /** 1333 * Version of 1334 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)} 1335 * that allows you to specify the 1336 * user the broadcast will be sent to. This is not available to applications 1337 * that are not pre-installed on the system image. Using it requires holding 1338 * the INTERACT_ACROSS_USERS permission. 1339 * 1340 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1341 * 1342 * @param intent The Intent to broadcast; all receivers matching this 1343 * Intent will receive the broadcast. 1344 * @param user UserHandle to send the intent to. 1345 * @param resultReceiver Your own BroadcastReceiver to treat as the final 1346 * receiver of the broadcast. 1347 * @param scheduler A custom Handler with which to schedule the 1348 * resultReceiver callback; if null it will be 1349 * scheduled in the Context's main thread. 1350 * @param initialCode An initial value for the result code. Often 1351 * Activity.RESULT_OK. 1352 * @param initialData An initial value for the result data. Often 1353 * null. 1354 * @param initialExtras An initial value for the result extras. Often 1355 * null. 1356 * 1357 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle) 1358 */ 1359 public abstract void sendStickyOrderedBroadcastAsUser(Intent intent, 1360 UserHandle user, BroadcastReceiver resultReceiver, 1361 Handler scheduler, int initialCode, String initialData, 1362 Bundle initialExtras); 1363 1364 /** 1365 * Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the 1366 * user the broadcast will be sent to. This is not available to applications 1367 * that are not pre-installed on the system image. Using it requires holding 1368 * the INTERACT_ACROSS_USERS permission. 1369 * 1370 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY} 1371 * permission in order to use this API. If you do not hold that 1372 * permission, {@link SecurityException} will be thrown. 1373 * 1374 * @param intent The Intent that was previously broadcast. 1375 * @param user UserHandle to remove the sticky broadcast from. 1376 * 1377 * @see #sendStickyBroadcastAsUser 1378 */ 1379 public abstract void removeStickyBroadcastAsUser(Intent intent, UserHandle user); 1380 1381 /** 1382 * Register a BroadcastReceiver to be run in the main activity thread. The 1383 * <var>receiver</var> will be called with any broadcast Intent that 1384 * matches <var>filter</var>, in the main application thread. 1385 * 1386 * <p>The system may broadcast Intents that are "sticky" -- these stay 1387 * around after the broadcast as finished, to be sent to any later 1388 * registrations. If your IntentFilter matches one of these sticky 1389 * Intents, that Intent will be returned by this function 1390 * <strong>and</strong> sent to your <var>receiver</var> as if it had just 1391 * been broadcast. 1392 * 1393 * <p>There may be multiple sticky Intents that match <var>filter</var>, 1394 * in which case each of these will be sent to <var>receiver</var>. In 1395 * this case, only one of these can be returned directly by the function; 1396 * which of these that is returned is arbitrarily decided by the system. 1397 * 1398 * <p>If you know the Intent your are registering for is sticky, you can 1399 * supply null for your <var>receiver</var>. In this case, no receiver is 1400 * registered -- the function simply returns the sticky Intent that 1401 * matches <var>filter</var>. In the case of multiple matches, the same 1402 * rules as described above apply. 1403 * 1404 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1405 * 1406 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers 1407 * registered with this method will correctly respect the 1408 * {@link Intent#setPackage(String)} specified for an Intent being broadcast. 1409 * Prior to that, it would be ignored and delivered to all matching registered 1410 * receivers. Be careful if using this for security.</p> 1411 * 1412 * <p class="note">Note: this method <em>cannot be called from a 1413 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver 1414 * that is declared in an application's manifest. It is okay, however, to call 1415 * this method from another BroadcastReceiver that has itself been registered 1416 * at run time with {@link #registerReceiver}, since the lifetime of such a 1417 * registered BroadcastReceiver is tied to the object that registered it.</p> 1418 * 1419 * @param receiver The BroadcastReceiver to handle the broadcast. 1420 * @param filter Selects the Intent broadcasts to be received. 1421 * 1422 * @return The first sticky intent found that matches <var>filter</var>, 1423 * or null if there are none. 1424 * 1425 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler) 1426 * @see #sendBroadcast 1427 * @see #unregisterReceiver 1428 */ 1429 public abstract Intent registerReceiver(BroadcastReceiver receiver, 1430 IntentFilter filter); 1431 1432 /** 1433 * Register to receive intent broadcasts, to run in the context of 1434 * <var>scheduler</var>. See 1435 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more 1436 * information. This allows you to enforce permissions on who can 1437 * broadcast intents to your receiver, or have the receiver run in 1438 * a different thread than the main application thread. 1439 * 1440 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. 1441 * 1442 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers 1443 * registered with this method will correctly respect the 1444 * {@link Intent#setPackage(String)} specified for an Intent being broadcast. 1445 * Prior to that, it would be ignored and delivered to all matching registered 1446 * receivers. Be careful if using this for security.</p> 1447 * 1448 * @param receiver The BroadcastReceiver to handle the broadcast. 1449 * @param filter Selects the Intent broadcasts to be received. 1450 * @param broadcastPermission String naming a permissions that a 1451 * broadcaster must hold in order to send an Intent to you. If null, 1452 * no permission is required. 1453 * @param scheduler Handler identifying the thread that will receive 1454 * the Intent. If null, the main thread of the process will be used. 1455 * 1456 * @return The first sticky intent found that matches <var>filter</var>, 1457 * or null if there are none. 1458 * 1459 * @see #registerReceiver(BroadcastReceiver, IntentFilter) 1460 * @see #sendBroadcast 1461 * @see #unregisterReceiver 1462 */ 1463 public abstract Intent registerReceiver(BroadcastReceiver receiver, 1464 IntentFilter filter, String broadcastPermission, Handler scheduler); 1465 1466 /** 1467 * @hide 1468 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler) 1469 * but for a specific user. This receiver will receiver broadcasts that 1470 * are sent to the requested user. It 1471 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} 1472 * permission. 1473 * 1474 * @param receiver The BroadcastReceiver to handle the broadcast. 1475 * @param user UserHandle to send the intent to. 1476 * @param filter Selects the Intent broadcasts to be received. 1477 * @param broadcastPermission String naming a permissions that a 1478 * broadcaster must hold in order to send an Intent to you. If null, 1479 * no permission is required. 1480 * @param scheduler Handler identifying the thread that will receive 1481 * the Intent. If null, the main thread of the process will be used. 1482 * 1483 * @return The first sticky intent found that matches <var>filter</var>, 1484 * or null if there are none. 1485 * 1486 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler 1487 * @see #sendBroadcast 1488 * @see #unregisterReceiver 1489 */ 1490 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver, 1491 UserHandle user, IntentFilter filter, String broadcastPermission, 1492 Handler scheduler); 1493 1494 /** 1495 * Unregister a previously registered BroadcastReceiver. <em>All</em> 1496 * filters that have been registered for this BroadcastReceiver will be 1497 * removed. 1498 * 1499 * @param receiver The BroadcastReceiver to unregister. 1500 * 1501 * @see #registerReceiver 1502 */ 1503 public abstract void unregisterReceiver(BroadcastReceiver receiver); 1504 1505 /** 1506 * Request that a given application service be started. The Intent 1507 * can either contain the complete class name of a specific service 1508 * implementation to start, or an abstract definition through the 1509 * action and other fields of the kind of service to start. If this service 1510 * is not already running, it will be instantiated and started (creating a 1511 * process for it if needed); if it is running then it remains running. 1512 * 1513 * <p>Every call to this method will result in a corresponding call to 1514 * the target service's {@link android.app.Service#onStartCommand} method, 1515 * with the <var>intent</var> given here. This provides a convenient way 1516 * to submit jobs to a service without having to bind and call on to its 1517 * interface. 1518 * 1519 * <p>Using startService() overrides the default service lifetime that is 1520 * managed by {@link #bindService}: it requires the service to remain 1521 * running until {@link #stopService} is called, regardless of whether 1522 * any clients are connected to it. Note that calls to startService() 1523 * are not nesting: no matter how many times you call startService(), 1524 * a single call to {@link #stopService} will stop it. 1525 * 1526 * <p>The system attempts to keep running services around as much as 1527 * possible. The only time they should be stopped is if the current 1528 * foreground application is using so many resources that the service needs 1529 * to be killed. If any errors happen in the service's process, it will 1530 * automatically be restarted. 1531 * 1532 * <p>This function will throw {@link SecurityException} if you do not 1533 * have permission to start the given service. 1534 * 1535 * @param service Identifies the service to be started. The Intent may 1536 * specify either an explicit component name to start, or a logical 1537 * description (action, category, etc) to match an 1538 * {@link IntentFilter} published by a service. Additional values 1539 * may be included in the Intent extras to supply arguments along with 1540 * this specific start call. 1541 * 1542 * @return If the service is being started or is already running, the 1543 * {@link ComponentName} of the actual service that was started is 1544 * returned; else if the service does not exist null is returned. 1545 * 1546 * @throws SecurityException 1547 * 1548 * @see #stopService 1549 * @see #bindService 1550 */ 1551 public abstract ComponentName startService(Intent service); 1552 1553 /** 1554 * Request that a given application service be stopped. If the service is 1555 * not running, nothing happens. Otherwise it is stopped. Note that calls 1556 * to startService() are not counted -- this stops the service no matter 1557 * how many times it was started. 1558 * 1559 * <p>Note that if a stopped service still has {@link ServiceConnection} 1560 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will 1561 * not be destroyed until all of these bindings are removed. See 1562 * the {@link android.app.Service} documentation for more details on a 1563 * service's lifecycle. 1564 * 1565 * <p>This function will throw {@link SecurityException} if you do not 1566 * have permission to stop the given service. 1567 * 1568 * @param service Description of the service to be stopped. The Intent may 1569 * specify either an explicit component name to start, or a logical 1570 * description (action, category, etc) to match an 1571 * {@link IntentFilter} published by a service. 1572 * 1573 * @return If there is a service matching the given Intent that is already 1574 * running, then it is stopped and true is returned; else false is returned. 1575 * 1576 * @throws SecurityException 1577 * 1578 * @see #startService 1579 */ 1580 public abstract boolean stopService(Intent service); 1581 1582 /** 1583 * @hide like {@link #startService(Intent)} but for a specific user. 1584 */ 1585 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user); 1586 1587 /** 1588 * @hide like {@link #stopService(Intent)} but for a specific user. 1589 */ 1590 public abstract boolean stopServiceAsUser(Intent service, UserHandle user); 1591 1592 /** 1593 * Connect to an application service, creating it if needed. This defines 1594 * a dependency between your application and the service. The given 1595 * <var>conn</var> will receive the service object when it is created and be 1596 * told if it dies and restarts. The service will be considered required 1597 * by the system only for as long as the calling context exists. For 1598 * example, if this Context is an Activity that is stopped, the service will 1599 * not be required to continue running until the Activity is resumed. 1600 * 1601 * <p>This function will throw {@link SecurityException} if you do not 1602 * have permission to bind to the given service. 1603 * 1604 * <p class="note">Note: this method <em>can not be called from a 1605 * {@link BroadcastReceiver} component</em>. A pattern you can use to 1606 * communicate from a BroadcastReceiver to a Service is to call 1607 * {@link #startService} with the arguments containing the command to be 1608 * sent, with the service calling its 1609 * {@link android.app.Service#stopSelf(int)} method when done executing 1610 * that command. See the API demo App/Service/Service Start Arguments 1611 * Controller for an illustration of this. It is okay, however, to use 1612 * this method from a BroadcastReceiver that has been registered with 1613 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver 1614 * is tied to another object (the one that registered it).</p> 1615 * 1616 * @param service Identifies the service to connect to. The Intent may 1617 * specify either an explicit component name, or a logical 1618 * description (action, category, etc) to match an 1619 * {@link IntentFilter} published by a service. 1620 * @param conn Receives information as the service is started and stopped. 1621 * This must be a valid ServiceConnection object; it must not be null. 1622 * @param flags Operation options for the binding. May be 0, 1623 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND}, 1624 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT}, 1625 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or 1626 * {@link #BIND_WAIVE_PRIORITY}. 1627 * @return If you have successfully bound to the service, true is returned; 1628 * false is returned if the connection is not made so you will not 1629 * receive the service object. 1630 * 1631 * @throws SecurityException 1632 * 1633 * @see #unbindService 1634 * @see #startService 1635 * @see #BIND_AUTO_CREATE 1636 * @see #BIND_DEBUG_UNBIND 1637 * @see #BIND_NOT_FOREGROUND 1638 */ 1639 public abstract boolean bindService(Intent service, ServiceConnection conn, 1640 int flags); 1641 1642 /** 1643 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle 1644 * argument for use by system server and other multi-user aware code. 1645 * @hide 1646 */ 1647 public boolean bindService(Intent service, ServiceConnection conn, int flags, int userHandle) { 1648 throw new RuntimeException("Not implemented. Must override in a subclass."); 1649 } 1650 1651 /** 1652 * Disconnect from an application service. You will no longer receive 1653 * calls as the service is restarted, and the service is now allowed to 1654 * stop at any time. 1655 * 1656 * @param conn The connection interface previously supplied to 1657 * bindService(). This parameter must not be null. 1658 * 1659 * @see #bindService 1660 */ 1661 public abstract void unbindService(ServiceConnection conn); 1662 1663 /** 1664 * Start executing an {@link android.app.Instrumentation} class. The given 1665 * Instrumentation component will be run by killing its target application 1666 * (if currently running), starting the target process, instantiating the 1667 * instrumentation component, and then letting it drive the application. 1668 * 1669 * <p>This function is not synchronous -- it returns as soon as the 1670 * instrumentation has started and while it is running. 1671 * 1672 * <p>Instrumentation is normally only allowed to run against a package 1673 * that is either unsigned or signed with a signature that the 1674 * the instrumentation package is also signed with (ensuring the target 1675 * trusts the instrumentation). 1676 * 1677 * @param className Name of the Instrumentation component to be run. 1678 * @param profileFile Optional path to write profiling data as the 1679 * instrumentation runs, or null for no profiling. 1680 * @param arguments Additional optional arguments to pass to the 1681 * instrumentation, or null. 1682 * 1683 * @return Returns true if the instrumentation was successfully started, 1684 * else false if it could not be found. 1685 */ 1686 public abstract boolean startInstrumentation(ComponentName className, 1687 String profileFile, Bundle arguments); 1688 1689 /** 1690 * Return the handle to a system-level service by name. The class of the 1691 * returned object varies by the requested name. Currently available names 1692 * are: 1693 * 1694 * <dl> 1695 * <dt> {@link #WINDOW_SERVICE} ("window") 1696 * <dd> The top-level window manager in which you can place custom 1697 * windows. The returned object is a {@link android.view.WindowManager}. 1698 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater") 1699 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources 1700 * in this context. 1701 * <dt> {@link #ACTIVITY_SERVICE} ("activity") 1702 * <dd> A {@link android.app.ActivityManager} for interacting with the 1703 * global activity state of the system. 1704 * <dt> {@link #POWER_SERVICE} ("power") 1705 * <dd> A {@link android.os.PowerManager} for controlling power 1706 * management. 1707 * <dt> {@link #ALARM_SERVICE} ("alarm") 1708 * <dd> A {@link android.app.AlarmManager} for receiving intents at the 1709 * time of your choosing. 1710 * <dt> {@link #NOTIFICATION_SERVICE} ("notification") 1711 * <dd> A {@link android.app.NotificationManager} for informing the user 1712 * of background events. 1713 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard") 1714 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard. 1715 * <dt> {@link #LOCATION_SERVICE} ("location") 1716 * <dd> A {@link android.location.LocationManager} for controlling location 1717 * (e.g., GPS) updates. 1718 * <dt> {@link #SEARCH_SERVICE} ("search") 1719 * <dd> A {@link android.app.SearchManager} for handling search. 1720 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator") 1721 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator 1722 * hardware. 1723 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection") 1724 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for 1725 * handling management of network connections. 1726 * <dt> {@link #WIFI_SERVICE} ("wifi") 1727 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of 1728 * Wi-Fi connectivity. 1729 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method") 1730 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager} 1731 * for management of input methods. 1732 * <dt> {@link #UI_MODE_SERVICE} ("uimode") 1733 * <dd> An {@link android.app.UiModeManager} for controlling UI modes. 1734 * <dt> {@link #DOWNLOAD_SERVICE} ("download") 1735 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads 1736 * </dl> 1737 * 1738 * <p>Note: System services obtained via this API may be closely associated with 1739 * the Context in which they are obtained from. In general, do not share the 1740 * service objects between various different contexts (Activities, Applications, 1741 * Services, Providers, etc.) 1742 * 1743 * @param name The name of the desired service. 1744 * 1745 * @return The service or null if the name does not exist. 1746 * 1747 * @see #WINDOW_SERVICE 1748 * @see android.view.WindowManager 1749 * @see #LAYOUT_INFLATER_SERVICE 1750 * @see android.view.LayoutInflater 1751 * @see #ACTIVITY_SERVICE 1752 * @see android.app.ActivityManager 1753 * @see #POWER_SERVICE 1754 * @see android.os.PowerManager 1755 * @see #ALARM_SERVICE 1756 * @see android.app.AlarmManager 1757 * @see #NOTIFICATION_SERVICE 1758 * @see android.app.NotificationManager 1759 * @see #KEYGUARD_SERVICE 1760 * @see android.app.KeyguardManager 1761 * @see #LOCATION_SERVICE 1762 * @see android.location.LocationManager 1763 * @see #SEARCH_SERVICE 1764 * @see android.app.SearchManager 1765 * @see #SENSOR_SERVICE 1766 * @see android.hardware.SensorManager 1767 * @see #STORAGE_SERVICE 1768 * @see android.os.storage.StorageManager 1769 * @see #VIBRATOR_SERVICE 1770 * @see android.os.Vibrator 1771 * @see #CONNECTIVITY_SERVICE 1772 * @see android.net.ConnectivityManager 1773 * @see #WIFI_SERVICE 1774 * @see android.net.wifi.WifiManager 1775 * @see #AUDIO_SERVICE 1776 * @see android.media.AudioManager 1777 * @see #MEDIA_ROUTER_SERVICE 1778 * @see android.media.MediaRouter 1779 * @see #TELEPHONY_SERVICE 1780 * @see android.telephony.TelephonyManager 1781 * @see #INPUT_METHOD_SERVICE 1782 * @see android.view.inputmethod.InputMethodManager 1783 * @see #UI_MODE_SERVICE 1784 * @see android.app.UiModeManager 1785 * @see #DOWNLOAD_SERVICE 1786 * @see android.app.DownloadManager 1787 */ 1788 public abstract Object getSystemService(String name); 1789 1790 /** 1791 * Use with {@link #getSystemService} to retrieve a 1792 * {@link android.os.PowerManager} for controlling power management, 1793 * including "wake locks," which let you keep the device on while 1794 * you're running long tasks. 1795 */ 1796 public static final String POWER_SERVICE = "power"; 1797 1798 /** 1799 * Use with {@link #getSystemService} to retrieve a 1800 * {@link android.view.WindowManager} for accessing the system's window 1801 * manager. 1802 * 1803 * @see #getSystemService 1804 * @see android.view.WindowManager 1805 */ 1806 public static final String WINDOW_SERVICE = "window"; 1807 1808 /** 1809 * Use with {@link #getSystemService} to retrieve a 1810 * {@link android.view.LayoutInflater} for inflating layout resources in this 1811 * context. 1812 * 1813 * @see #getSystemService 1814 * @see android.view.LayoutInflater 1815 */ 1816 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater"; 1817 1818 /** 1819 * Use with {@link #getSystemService} to retrieve a 1820 * {@link android.accounts.AccountManager} for receiving intents at a 1821 * time of your choosing. 1822 * 1823 * @see #getSystemService 1824 * @see android.accounts.AccountManager 1825 */ 1826 public static final String ACCOUNT_SERVICE = "account"; 1827 1828 /** 1829 * Use with {@link #getSystemService} to retrieve a 1830 * {@link android.app.ActivityManager} for interacting with the global 1831 * system state. 1832 * 1833 * @see #getSystemService 1834 * @see android.app.ActivityManager 1835 */ 1836 public static final String ACTIVITY_SERVICE = "activity"; 1837 1838 /** 1839 * Use with {@link #getSystemService} to retrieve a 1840 * {@link android.app.AlarmManager} for receiving intents at a 1841 * time of your choosing. 1842 * 1843 * @see #getSystemService 1844 * @see android.app.AlarmManager 1845 */ 1846 public static final String ALARM_SERVICE = "alarm"; 1847 1848 /** 1849 * Use with {@link #getSystemService} to retrieve a 1850 * {@link android.app.NotificationManager} for informing the user of 1851 * background events. 1852 * 1853 * @see #getSystemService 1854 * @see android.app.NotificationManager 1855 */ 1856 public static final String NOTIFICATION_SERVICE = "notification"; 1857 1858 /** 1859 * Use with {@link #getSystemService} to retrieve a 1860 * {@link android.view.accessibility.AccessibilityManager} for giving the user 1861 * feedback for UI events through the registered event listeners. 1862 * 1863 * @see #getSystemService 1864 * @see android.view.accessibility.AccessibilityManager 1865 */ 1866 public static final String ACCESSIBILITY_SERVICE = "accessibility"; 1867 1868 /** 1869 * Use with {@link #getSystemService} to retrieve a 1870 * {@link android.app.NotificationManager} for controlling keyguard. 1871 * 1872 * @see #getSystemService 1873 * @see android.app.KeyguardManager 1874 */ 1875 public static final String KEYGUARD_SERVICE = "keyguard"; 1876 1877 /** 1878 * Use with {@link #getSystemService} to retrieve a {@link 1879 * android.location.LocationManager} for controlling location 1880 * updates. 1881 * 1882 * @see #getSystemService 1883 * @see android.location.LocationManager 1884 */ 1885 public static final String LOCATION_SERVICE = "location"; 1886 1887 /** 1888 * Use with {@link #getSystemService} to retrieve a 1889 * {@link android.location.CountryDetector} for detecting the country that 1890 * the user is in. 1891 * 1892 * @hide 1893 */ 1894 public static final String COUNTRY_DETECTOR = "country_detector"; 1895 1896 /** 1897 * Use with {@link #getSystemService} to retrieve a {@link 1898 * android.app.SearchManager} for handling searches. 1899 * 1900 * @see #getSystemService 1901 * @see android.app.SearchManager 1902 */ 1903 public static final String SEARCH_SERVICE = "search"; 1904 1905 /** 1906 * Use with {@link #getSystemService} to retrieve a {@link 1907 * android.hardware.SensorManager} for accessing sensors. 1908 * 1909 * @see #getSystemService 1910 * @see android.hardware.SensorManager 1911 */ 1912 public static final String SENSOR_SERVICE = "sensor"; 1913 1914 /** 1915 * Use with {@link #getSystemService} to retrieve a {@link 1916 * android.os.storage.StorageManager} for accessing system storage 1917 * functions. 1918 * 1919 * @see #getSystemService 1920 * @see android.os.storage.StorageManager 1921 */ 1922 public static final String STORAGE_SERVICE = "storage"; 1923 1924 /** 1925 * Use with {@link #getSystemService} to retrieve a 1926 * com.android.server.WallpaperService for accessing wallpapers. 1927 * 1928 * @see #getSystemService 1929 */ 1930 public static final String WALLPAPER_SERVICE = "wallpaper"; 1931 1932 /** 1933 * Use with {@link #getSystemService} to retrieve a {@link 1934 * android.os.Vibrator} for interacting with the vibration hardware. 1935 * 1936 * @see #getSystemService 1937 * @see android.os.Vibrator 1938 */ 1939 public static final String VIBRATOR_SERVICE = "vibrator"; 1940 1941 /** 1942 * Use with {@link #getSystemService} to retrieve a {@link 1943 * android.app.StatusBarManager} for interacting with the status bar. 1944 * 1945 * @see #getSystemService 1946 * @see android.app.StatusBarManager 1947 * @hide 1948 */ 1949 public static final String STATUS_BAR_SERVICE = "statusbar"; 1950 1951 /** 1952 * Use with {@link #getSystemService} to retrieve a {@link 1953 * android.net.ConnectivityManager} for handling management of 1954 * network connections. 1955 * 1956 * @see #getSystemService 1957 * @see android.net.ConnectivityManager 1958 */ 1959 public static final String CONNECTIVITY_SERVICE = "connectivity"; 1960 1961 /** 1962 * Use with {@link #getSystemService} to retrieve a {@link 1963 * android.net.ThrottleManager} for handling management of 1964 * throttling. 1965 * 1966 * @hide 1967 * @see #getSystemService 1968 * @see android.net.ThrottleManager 1969 */ 1970 public static final String THROTTLE_SERVICE = "throttle"; 1971 1972 /** 1973 * Use with {@link #getSystemService} to retrieve a {@link 1974 * android.os.IUpdateLock} for managing runtime sequences that 1975 * must not be interrupted by headless OTA application or similar. 1976 * 1977 * @hide 1978 * @see #getSystemService 1979 * @see android.os.UpdateLock 1980 */ 1981 public static final String UPDATE_LOCK_SERVICE = "updatelock"; 1982 1983 /** 1984 * Use with {@link #getSystemService} to retrieve a {@link 1985 * android.net.NetworkManagementService} for handling management of 1986 * system network services 1987 * 1988 * @hide 1989 * @see #getSystemService 1990 * @see android.net.NetworkManagementService 1991 */ 1992 public static final String NETWORKMANAGEMENT_SERVICE = "network_management"; 1993 1994 /** {@hide} */ 1995 public static final String NETWORK_STATS_SERVICE = "netstats"; 1996 /** {@hide} */ 1997 public static final String NETWORK_POLICY_SERVICE = "netpolicy"; 1998 1999 /** 2000 * Use with {@link #getSystemService} to retrieve a {@link 2001 * android.net.wifi.WifiManager} for handling management of 2002 * Wi-Fi access. 2003 * 2004 * @see #getSystemService 2005 * @see android.net.wifi.WifiManager 2006 */ 2007 public static final String WIFI_SERVICE = "wifi"; 2008 2009 /** 2010 * Use with {@link #getSystemService} to retrieve a {@link 2011 * android.net.wifi.p2p.WifiP2pManager} for handling management of 2012 * Wi-Fi peer-to-peer connections. 2013 * 2014 * @see #getSystemService 2015 * @see android.net.wifi.p2p.WifiP2pManager 2016 */ 2017 public static final String WIFI_P2P_SERVICE = "wifip2p"; 2018 2019 /** 2020 * Use with {@link #getSystemService} to retrieve a {@link 2021 * android.net.nsd.NsdManager} for handling management of network service 2022 * discovery 2023 * 2024 * @see #getSystemService 2025 * @see android.net.nsd.NsdManager 2026 */ 2027 public static final String NSD_SERVICE = "servicediscovery"; 2028 2029 /** 2030 * Use with {@link #getSystemService} to retrieve a 2031 * {@link android.media.AudioManager} for handling management of volume, 2032 * ringer modes and audio routing. 2033 * 2034 * @see #getSystemService 2035 * @see android.media.AudioManager 2036 */ 2037 public static final String AUDIO_SERVICE = "audio"; 2038 2039 /** 2040 * Use with {@link #getSystemService} to retrieve a 2041 * {@link android.media.MediaRouter} for controlling and managing 2042 * routing of media. 2043 * 2044 * @see #getSystemService 2045 * @see android.media.MediaRouter 2046 */ 2047 public static final String MEDIA_ROUTER_SERVICE = "media_router"; 2048 2049 /** 2050 * Use with {@link #getSystemService} to retrieve a 2051 * {@link android.telephony.TelephonyManager} for handling management the 2052 * telephony features of the device. 2053 * 2054 * @see #getSystemService 2055 * @see android.telephony.TelephonyManager 2056 */ 2057 public static final String TELEPHONY_SERVICE = "phone"; 2058 2059 /** 2060 * Use with {@link #getSystemService} to retrieve a 2061 * {@link android.text.ClipboardManager} for accessing and modifying 2062 * the contents of the global clipboard. 2063 * 2064 * @see #getSystemService 2065 * @see android.text.ClipboardManager 2066 */ 2067 public static final String CLIPBOARD_SERVICE = "clipboard"; 2068 2069 /** 2070 * Use with {@link #getSystemService} to retrieve a 2071 * {@link android.view.inputmethod.InputMethodManager} for accessing input 2072 * methods. 2073 * 2074 * @see #getSystemService 2075 */ 2076 public static final String INPUT_METHOD_SERVICE = "input_method"; 2077 2078 /** 2079 * Use with {@link #getSystemService} to retrieve a 2080 * {@link android.view.textservice.TextServicesManager} for accessing 2081 * text services. 2082 * 2083 * @see #getSystemService 2084 */ 2085 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices"; 2086 2087 /** 2088 * Use with {@link #getSystemService} to retrieve a 2089 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets. 2090 * 2091 * @hide 2092 * @see #getSystemService 2093 */ 2094 public static final String APPWIDGET_SERVICE = "appwidget"; 2095 2096 /** 2097 * Use with {@link #getSystemService} to retrieve an 2098 * {@link android.app.backup.IBackupManager IBackupManager} for communicating 2099 * with the backup mechanism. 2100 * @hide 2101 * 2102 * @see #getSystemService 2103 */ 2104 public static final String BACKUP_SERVICE = "backup"; 2105 2106 /** 2107 * Use with {@link #getSystemService} to retrieve a 2108 * {@link android.os.DropBoxManager} instance for recording 2109 * diagnostic logs. 2110 * @see #getSystemService 2111 */ 2112 public static final String DROPBOX_SERVICE = "dropbox"; 2113 2114 /** 2115 * Use with {@link #getSystemService} to retrieve a 2116 * {@link android.app.admin.DevicePolicyManager} for working with global 2117 * device policy management. 2118 * 2119 * @see #getSystemService 2120 */ 2121 public static final String DEVICE_POLICY_SERVICE = "device_policy"; 2122 2123 /** 2124 * Use with {@link #getSystemService} to retrieve a 2125 * {@link android.app.UiModeManager} for controlling UI modes. 2126 * 2127 * @see #getSystemService 2128 */ 2129 public static final String UI_MODE_SERVICE = "uimode"; 2130 2131 /** 2132 * Use with {@link #getSystemService} to retrieve a 2133 * {@link android.app.DownloadManager} for requesting HTTP downloads. 2134 * 2135 * @see #getSystemService 2136 */ 2137 public static final String DOWNLOAD_SERVICE = "download"; 2138 2139 /** 2140 * Use with {@link #getSystemService} to retrieve a 2141 * {@link android.nfc.NfcManager} for using NFC. 2142 * 2143 * @see #getSystemService 2144 */ 2145 public static final String NFC_SERVICE = "nfc"; 2146 2147 /** 2148 * Use with {@link #getSystemService} to retrieve a 2149 * {@link android.bluetooth.BluetoothAdapter} for using Bluetooth. 2150 * 2151 * @see #getSystemService 2152 * @hide 2153 */ 2154 public static final String BLUETOOTH_SERVICE = "bluetooth"; 2155 2156 /** 2157 * Use with {@link #getSystemService} to retrieve a 2158 * {@link android.net.sip.SipManager} for accessing the SIP related service. 2159 * 2160 * @see #getSystemService 2161 */ 2162 /** @hide */ 2163 public static final String SIP_SERVICE = "sip"; 2164 2165 /** 2166 * Use with {@link #getSystemService} to retrieve a {@link 2167 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host) 2168 * and for controlling this device's behavior as a USB device. 2169 * 2170 * @see #getSystemService 2171 * @see android.harware.usb.UsbManager 2172 */ 2173 public static final String USB_SERVICE = "usb"; 2174 2175 /** 2176 * Use with {@link #getSystemService} to retrieve a {@link 2177 * android.hardware.SerialManager} for access to serial ports. 2178 * 2179 * @see #getSystemService 2180 * @see android.harware.SerialManager 2181 * 2182 * @hide 2183 */ 2184 public static final String SERIAL_SERVICE = "serial"; 2185 2186 /** 2187 * Use with {@link #getSystemService} to retrieve a 2188 * {@link android.hardware.input.InputManager} for interacting with input devices. 2189 * 2190 * @see #getSystemService 2191 * @see android.hardware.input.InputManager 2192 */ 2193 public static final String INPUT_SERVICE = "input"; 2194 2195 /** 2196 * Use with {@link #getSystemService} to retrieve a 2197 * {@link android.hardware.display.DisplayManager} for interacting with display devices. 2198 * 2199 * @see #getSystemService 2200 * @see android.hardware.display.DisplayManager 2201 */ 2202 public static final String DISPLAY_SERVICE = "display"; 2203 2204 /** 2205 * Use with {@link #getSystemService} to retrieve a 2206 * {@link android.os.SchedulingPolicyService} for managing scheduling policy. 2207 * 2208 * @see #getSystemService 2209 * @see android.os.SchedulingPolicyService 2210 * 2211 * @hide 2212 */ 2213 public static final String SCHEDULING_POLICY_SERVICE = "scheduling_policy"; 2214 2215 /** 2216 * Use with {@link #getSystemService} to retrieve a 2217 * {@link android.os.UserManager} for managing users on devices that support multiple users. 2218 * 2219 * @see #getSystemService 2220 * @see android.os.UserManager 2221 */ 2222 public static final String USER_SERVICE = "user"; 2223 2224 /** 2225 * Determine whether the given permission is allowed for a particular 2226 * process and user ID running in the system. 2227 * 2228 * @param permission The name of the permission being checked. 2229 * @param pid The process ID being checked against. Must be > 0. 2230 * @param uid The user ID being checked against. A uid of 0 is the root 2231 * user, which will pass every permission check. 2232 * 2233 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the given 2234 * pid/uid is allowed that permission, or 2235 * {@link PackageManager#PERMISSION_DENIED} if it is not. 2236 * 2237 * @see PackageManager#checkPermission(String, String) 2238 * @see #checkCallingPermission 2239 */ 2240 public abstract int checkPermission(String permission, int pid, int uid); 2241 2242 /** 2243 * Determine whether the calling process of an IPC you are handling has been 2244 * granted a particular permission. This is basically the same as calling 2245 * {@link #checkPermission(String, int, int)} with the pid and uid returned 2246 * by {@link android.os.Binder#getCallingPid} and 2247 * {@link android.os.Binder#getCallingUid}. One important difference 2248 * is that if you are not currently processing an IPC, this function 2249 * will always fail. This is done to protect against accidentally 2250 * leaking permissions; you can use {@link #checkCallingOrSelfPermission} 2251 * to avoid this protection. 2252 * 2253 * @param permission The name of the permission being checked. 2254 * 2255 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the calling 2256 * pid/uid is allowed that permission, or 2257 * {@link PackageManager#PERMISSION_DENIED} if it is not. 2258 * 2259 * @see PackageManager#checkPermission(String, String) 2260 * @see #checkPermission 2261 * @see #checkCallingOrSelfPermission 2262 */ 2263 public abstract int checkCallingPermission(String permission); 2264 2265 /** 2266 * Determine whether the calling process of an IPC <em>or you</em> have been 2267 * granted a particular permission. This is the same as 2268 * {@link #checkCallingPermission}, except it grants your own permissions 2269 * if you are not currently processing an IPC. Use with care! 2270 * 2271 * @param permission The name of the permission being checked. 2272 * 2273 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the calling 2274 * pid/uid is allowed that permission, or 2275 * {@link PackageManager#PERMISSION_DENIED} if it is not. 2276 * 2277 * @see PackageManager#checkPermission(String, String) 2278 * @see #checkPermission 2279 * @see #checkCallingPermission 2280 */ 2281 public abstract int checkCallingOrSelfPermission(String permission); 2282 2283 /** 2284 * If the given permission is not allowed for a particular process 2285 * and user ID running in the system, throw a {@link SecurityException}. 2286 * 2287 * @param permission The name of the permission being checked. 2288 * @param pid The process ID being checked against. Must be > 0. 2289 * @param uid The user ID being checked against. A uid of 0 is the root 2290 * user, which will pass every permission check. 2291 * @param message A message to include in the exception if it is thrown. 2292 * 2293 * @see #checkPermission(String, int, int) 2294 */ 2295 public abstract void enforcePermission( 2296 String permission, int pid, int uid, String message); 2297 2298 /** 2299 * If the calling process of an IPC you are handling has not been 2300 * granted a particular permission, throw a {@link 2301 * SecurityException}. This is basically the same as calling 2302 * {@link #enforcePermission(String, int, int, String)} with the 2303 * pid and uid returned by {@link android.os.Binder#getCallingPid} 2304 * and {@link android.os.Binder#getCallingUid}. One important 2305 * difference is that if you are not currently processing an IPC, 2306 * this function will always throw the SecurityException. This is 2307 * done to protect against accidentally leaking permissions; you 2308 * can use {@link #enforceCallingOrSelfPermission} to avoid this 2309 * protection. 2310 * 2311 * @param permission The name of the permission being checked. 2312 * @param message A message to include in the exception if it is thrown. 2313 * 2314 * @see #checkCallingPermission(String) 2315 */ 2316 public abstract void enforceCallingPermission( 2317 String permission, String message); 2318 2319 /** 2320 * If neither you nor the calling process of an IPC you are 2321 * handling has been granted a particular permission, throw a 2322 * {@link SecurityException}. This is the same as {@link 2323 * #enforceCallingPermission}, except it grants your own 2324 * permissions if you are not currently processing an IPC. Use 2325 * with care! 2326 * 2327 * @param permission The name of the permission being checked. 2328 * @param message A message to include in the exception if it is thrown. 2329 * 2330 * @see #checkCallingOrSelfPermission(String) 2331 */ 2332 public abstract void enforceCallingOrSelfPermission( 2333 String permission, String message); 2334 2335 /** 2336 * Grant permission to access a specific Uri to another package, regardless 2337 * of whether that package has general permission to access the Uri's 2338 * content provider. This can be used to grant specific, temporary 2339 * permissions, typically in response to user interaction (such as the 2340 * user opening an attachment that you would like someone else to 2341 * display). 2342 * 2343 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION 2344 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or 2345 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION 2346 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to 2347 * start an activity instead of this function directly. If you use this 2348 * function directly, you should be sure to call 2349 * {@link #revokeUriPermission} when the target should no longer be allowed 2350 * to access it. 2351 * 2352 * <p>To succeed, the content provider owning the Uri must have set the 2353 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions 2354 * grantUriPermissions} attribute in its manifest or included the 2355 * {@link android.R.styleable#AndroidManifestGrantUriPermission 2356 * <grant-uri-permissions>} tag. 2357 * 2358 * @param toPackage The package you would like to allow to access the Uri. 2359 * @param uri The Uri you would like to grant access to. 2360 * @param modeFlags The desired access modes. Any combination of 2361 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION 2362 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or 2363 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION 2364 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 2365 * 2366 * @see #revokeUriPermission 2367 */ 2368 public abstract void grantUriPermission(String toPackage, Uri uri, 2369 int modeFlags); 2370 2371 /** 2372 * Remove all permissions to access a particular content provider Uri 2373 * that were previously added with {@link #grantUriPermission}. The given 2374 * Uri will match all previously granted Uris that are the same or a 2375 * sub-path of the given Uri. That is, revoking "content://foo/one" will 2376 * revoke both "content://foo/target" and "content://foo/target/sub", but not 2377 * "content://foo". 2378 * 2379 * @param uri The Uri you would like to revoke access to. 2380 * @param modeFlags The desired access modes. Any combination of 2381 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION 2382 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or 2383 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION 2384 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 2385 * 2386 * @see #grantUriPermission 2387 */ 2388 public abstract void revokeUriPermission(Uri uri, int modeFlags); 2389 2390 /** 2391 * Determine whether a particular process and user ID has been granted 2392 * permission to access a specific URI. This only checks for permissions 2393 * that have been explicitly granted -- if the given process/uid has 2394 * more general access to the URI's content provider then this check will 2395 * always fail. 2396 * 2397 * @param uri The uri that is being checked. 2398 * @param pid The process ID being checked against. Must be > 0. 2399 * @param uid The user ID being checked against. A uid of 0 is the root 2400 * user, which will pass every permission check. 2401 * @param modeFlags The type of access to grant. May be one or both of 2402 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 2403 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 2404 * 2405 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the given 2406 * pid/uid is allowed to access that uri, or 2407 * {@link PackageManager#PERMISSION_DENIED} if it is not. 2408 * 2409 * @see #checkCallingUriPermission 2410 */ 2411 public abstract int checkUriPermission(Uri uri, int pid, int uid, int modeFlags); 2412 2413 /** 2414 * Determine whether the calling process and user ID has been 2415 * granted permission to access a specific URI. This is basically 2416 * the same as calling {@link #checkUriPermission(Uri, int, int, 2417 * int)} with the pid and uid returned by {@link 2418 * android.os.Binder#getCallingPid} and {@link 2419 * android.os.Binder#getCallingUid}. One important difference is 2420 * that if you are not currently processing an IPC, this function 2421 * will always fail. 2422 * 2423 * @param uri The uri that is being checked. 2424 * @param modeFlags The type of access to grant. May be one or both of 2425 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 2426 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 2427 * 2428 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller 2429 * is allowed to access that uri, or 2430 * {@link PackageManager#PERMISSION_DENIED} if it is not. 2431 * 2432 * @see #checkUriPermission(Uri, int, int, int) 2433 */ 2434 public abstract int checkCallingUriPermission(Uri uri, int modeFlags); 2435 2436 /** 2437 * Determine whether the calling process of an IPC <em>or you</em> has been granted 2438 * permission to access a specific URI. This is the same as 2439 * {@link #checkCallingUriPermission}, except it grants your own permissions 2440 * if you are not currently processing an IPC. Use with care! 2441 * 2442 * @param uri The uri that is being checked. 2443 * @param modeFlags The type of access to grant. May be one or both of 2444 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 2445 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 2446 * 2447 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller 2448 * is allowed to access that uri, or 2449 * {@link PackageManager#PERMISSION_DENIED} if it is not. 2450 * 2451 * @see #checkCallingUriPermission 2452 */ 2453 public abstract int checkCallingOrSelfUriPermission(Uri uri, int modeFlags); 2454 2455 /** 2456 * Check both a Uri and normal permission. This allows you to perform 2457 * both {@link #checkPermission} and {@link #checkUriPermission} in one 2458 * call. 2459 * 2460 * @param uri The Uri whose permission is to be checked, or null to not 2461 * do this check. 2462 * @param readPermission The permission that provides overall read access, 2463 * or null to not do this check. 2464 * @param writePermission The permission that provides overall write 2465 * acess, or null to not do this check. 2466 * @param pid The process ID being checked against. Must be > 0. 2467 * @param uid The user ID being checked against. A uid of 0 is the root 2468 * user, which will pass every permission check. 2469 * @param modeFlags The type of access to grant. May be one or both of 2470 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 2471 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 2472 * 2473 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller 2474 * is allowed to access that uri or holds one of the given permissions, or 2475 * {@link PackageManager#PERMISSION_DENIED} if it is not. 2476 */ 2477 public abstract int checkUriPermission(Uri uri, String readPermission, 2478 String writePermission, int pid, int uid, int modeFlags); 2479 2480 /** 2481 * If a particular process and user ID has not been granted 2482 * permission to access a specific URI, throw {@link 2483 * SecurityException}. This only checks for permissions that have 2484 * been explicitly granted -- if the given process/uid has more 2485 * general access to the URI's content provider then this check 2486 * will always fail. 2487 * 2488 * @param uri The uri that is being checked. 2489 * @param pid The process ID being checked against. Must be > 0. 2490 * @param uid The user ID being checked against. A uid of 0 is the root 2491 * user, which will pass every permission check. 2492 * @param modeFlags The type of access to grant. May be one or both of 2493 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 2494 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 2495 * @param message A message to include in the exception if it is thrown. 2496 * 2497 * @see #checkUriPermission(Uri, int, int, int) 2498 */ 2499 public abstract void enforceUriPermission( 2500 Uri uri, int pid, int uid, int modeFlags, String message); 2501 2502 /** 2503 * If the calling process and user ID has not been granted 2504 * permission to access a specific URI, throw {@link 2505 * SecurityException}. This is basically the same as calling 2506 * {@link #enforceUriPermission(Uri, int, int, int, String)} with 2507 * the pid and uid returned by {@link 2508 * android.os.Binder#getCallingPid} and {@link 2509 * android.os.Binder#getCallingUid}. One important difference is 2510 * that if you are not currently processing an IPC, this function 2511 * will always throw a SecurityException. 2512 * 2513 * @param uri The uri that is being checked. 2514 * @param modeFlags The type of access to grant. May be one or both of 2515 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 2516 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 2517 * @param message A message to include in the exception if it is thrown. 2518 * 2519 * @see #checkCallingUriPermission(Uri, int) 2520 */ 2521 public abstract void enforceCallingUriPermission( 2522 Uri uri, int modeFlags, String message); 2523 2524 /** 2525 * If the calling process of an IPC <em>or you</em> has not been 2526 * granted permission to access a specific URI, throw {@link 2527 * SecurityException}. This is the same as {@link 2528 * #enforceCallingUriPermission}, except it grants your own 2529 * permissions if you are not currently processing an IPC. Use 2530 * with care! 2531 * 2532 * @param uri The uri that is being checked. 2533 * @param modeFlags The type of access to grant. May be one or both of 2534 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 2535 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 2536 * @param message A message to include in the exception if it is thrown. 2537 * 2538 * @see #checkCallingOrSelfUriPermission(Uri, int) 2539 */ 2540 public abstract void enforceCallingOrSelfUriPermission( 2541 Uri uri, int modeFlags, String message); 2542 2543 /** 2544 * Enforce both a Uri and normal permission. This allows you to perform 2545 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one 2546 * call. 2547 * 2548 * @param uri The Uri whose permission is to be checked, or null to not 2549 * do this check. 2550 * @param readPermission The permission that provides overall read access, 2551 * or null to not do this check. 2552 * @param writePermission The permission that provides overall write 2553 * acess, or null to not do this check. 2554 * @param pid The process ID being checked against. Must be > 0. 2555 * @param uid The user ID being checked against. A uid of 0 is the root 2556 * user, which will pass every permission check. 2557 * @param modeFlags The type of access to grant. May be one or both of 2558 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or 2559 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. 2560 * @param message A message to include in the exception if it is thrown. 2561 * 2562 * @see #checkUriPermission(Uri, String, String, int, int, int) 2563 */ 2564 public abstract void enforceUriPermission( 2565 Uri uri, String readPermission, String writePermission, 2566 int pid, int uid, int modeFlags, String message); 2567 2568 /** 2569 * Flag for use with {@link #createPackageContext}: include the application 2570 * code with the context. This means loading code into the caller's 2571 * process, so that {@link #getClassLoader()} can be used to instantiate 2572 * the application's classes. Setting this flags imposes security 2573 * restrictions on what application context you can access; if the 2574 * requested application can not be safely loaded into your process, 2575 * java.lang.SecurityException will be thrown. If this flag is not set, 2576 * there will be no restrictions on the packages that can be loaded, 2577 * but {@link #getClassLoader} will always return the default system 2578 * class loader. 2579 */ 2580 public static final int CONTEXT_INCLUDE_CODE = 0x00000001; 2581 2582 /** 2583 * Flag for use with {@link #createPackageContext}: ignore any security 2584 * restrictions on the Context being requested, allowing it to always 2585 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code 2586 * to be loaded into a process even when it isn't safe to do so. Use 2587 * with extreme care! 2588 */ 2589 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002; 2590 2591 /** 2592 * Flag for use with {@link #createPackageContext}: a restricted context may 2593 * disable specific features. For instance, a View associated with a restricted 2594 * context would ignore particular XML attributes. 2595 */ 2596 public static final int CONTEXT_RESTRICTED = 0x00000004; 2597 2598 /** 2599 * Return a new Context object for the given application name. This 2600 * Context is the same as what the named application gets when it is 2601 * launched, containing the same resources and class loader. Each call to 2602 * this method returns a new instance of a Context object; Context objects 2603 * are not shared, however they share common state (Resources, ClassLoader, 2604 * etc) so the Context instance itself is fairly lightweight. 2605 * 2606 * <p>Throws {@link PackageManager.NameNotFoundException} if there is no 2607 * application with the given package name. 2608 * 2609 * <p>Throws {@link java.lang.SecurityException} if the Context requested 2610 * can not be loaded into the caller's process for security reasons (see 2611 * {@link #CONTEXT_INCLUDE_CODE} for more information}. 2612 * 2613 * @param packageName Name of the application's package. 2614 * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE} 2615 * or {@link #CONTEXT_IGNORE_SECURITY}. 2616 * 2617 * @return A Context for the application. 2618 * 2619 * @throws java.lang.SecurityException 2620 * @throws PackageManager.NameNotFoundException if there is no application with 2621 * the given package name 2622 */ 2623 public abstract Context createPackageContext(String packageName, 2624 int flags) throws PackageManager.NameNotFoundException; 2625 2626 /** 2627 * Similar to {@link #createPackageContext(String, int)}, but with a 2628 * different {@link UserHandle}. For example, {@link #getContentResolver()} 2629 * will open any {@link Uri} as the given user. 2630 * 2631 * @hide 2632 */ 2633 public abstract Context createPackageContextAsUser( 2634 String packageName, int flags, UserHandle user) 2635 throws PackageManager.NameNotFoundException; 2636 2637 /** 2638 * Return a new Context object for the current Context but whose resources 2639 * are adjusted to match the given Configuration. Each call to this method 2640 * returns a new instance of a Context object; Context objects are not 2641 * shared, however common state (ClassLoader, other Resources for the 2642 * same configuration) may be so the Context itself can be fairly lightweight. 2643 * 2644 * @param overrideConfiguration A {@link Configuration} specifying what 2645 * values to modify in the base Configuration of the original Context's 2646 * resources. If the base configuration changes (such as due to an 2647 * orientation change), the resources of this context will also change except 2648 * for those that have been explicitly overridden with a value here. 2649 * 2650 * @return A Context with the given configuration override. 2651 */ 2652 public abstract Context createConfigurationContext(Configuration overrideConfiguration); 2653 2654 /** 2655 * Return a new Context object for the current Context but whose resources 2656 * are adjusted to match the metrics of the given Display. Each call to this method 2657 * returns a new instance of a Context object; Context objects are not 2658 * shared, however common state (ClassLoader, other Resources for the 2659 * same configuration) may be so the Context itself can be fairly lightweight. 2660 * 2661 * The returned display Context provides a {@link WindowManager} 2662 * (see {@link #getSystemService(String)}) that is configured to show windows 2663 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay} 2664 * method can be used to retrieve the Display from the returned Context. 2665 * 2666 * @param display A {@link Display} object specifying the display 2667 * for whose metrics the Context's resources should be tailored and upon which 2668 * new windows should be shown. 2669 * 2670 * @return A Context for the display. 2671 */ 2672 public abstract Context createDisplayContext(Display display); 2673 2674 /** 2675 * Gets the compatibility info holder for this context. This information 2676 * is provided on a per-application basis and is used to simulate lower density 2677 * display metrics for legacy applications. 2678 * 2679 * @param displayId The display id for which to get compatibility info. 2680 * @return The compatibility info holder, or null if not required by the application. 2681 * @hide 2682 */ 2683 public abstract CompatibilityInfoHolder getCompatibilityInfo(int displayId); 2684 2685 /** 2686 * Indicates whether this Context is restricted. 2687 * 2688 * @return True if this Context is restricted, false otherwise. 2689 * 2690 * @see #CONTEXT_RESTRICTED 2691 */ 2692 public boolean isRestricted() { 2693 return false; 2694 } 2695} 2696