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