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