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