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