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