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