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