The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
| 17 | package android.content; |
| 18 | |
| 19 | import android.content.pm.PackageManager; |
| 20 | import android.content.res.AssetManager; |
| 21 | import android.content.res.Resources; |
| 22 | import android.content.res.TypedArray; |
| 23 | import android.database.sqlite.SQLiteDatabase; |
| 24 | import android.database.sqlite.SQLiteDatabase.CursorFactory; |
| 25 | import android.graphics.Bitmap; |
| 26 | import android.graphics.drawable.Drawable; |
| 27 | import android.net.Uri; |
| 28 | import android.os.Bundle; |
| 29 | import android.os.Handler; |
| 30 | import android.os.Looper; |
| 31 | import android.util.AttributeSet; |
| 32 | |
| 33 | import java.io.File; |
| 34 | import java.io.FileInputStream; |
| 35 | import java.io.FileNotFoundException; |
| 36 | import java.io.FileOutputStream; |
| 37 | import java.io.IOException; |
| 38 | import java.io.InputStream; |
| 39 | |
| 40 | /** |
| 41 | * Interface to global information about an application environment. This is |
| 42 | * an abstract class whose implementation is provided by |
| 43 | * the Android system. It |
| 44 | * allows access to application-specific resources and classes, as well as |
| 45 | * up-calls for application-level operations such as launching activities, |
| 46 | * broadcasting and receiving intents, etc. |
| 47 | */ |
| 48 | public abstract class Context { |
| 49 | /** |
| 50 | * File creation mode: the default mode, where the created file can only |
| 51 | * be accessed by the calling application (or all applications sharing the |
| 52 | * same user ID). |
| 53 | * @see #MODE_WORLD_READABLE |
| 54 | * @see #MODE_WORLD_WRITEABLE |
| 55 | */ |
| 56 | public static final int MODE_PRIVATE = 0x0000; |
| 57 | /** |
| 58 | * File creation mode: allow all other applications to have read access |
| 59 | * to the created file. |
| 60 | * @see #MODE_PRIVATE |
| 61 | * @see #MODE_WORLD_WRITEABLE |
| 62 | */ |
| 63 | public static final int MODE_WORLD_READABLE = 0x0001; |
| 64 | /** |
| 65 | * File creation mode: allow all other applications to have write access |
| 66 | * to the created file. |
| 67 | * @see #MODE_PRIVATE |
| 68 | * @see #MODE_WORLD_READABLE |
| 69 | */ |
| 70 | public static final int MODE_WORLD_WRITEABLE = 0x0002; |
| 71 | /** |
| 72 | * File creation mode: for use with {@link #openFileOutput}, if the file |
| 73 | * already exists then write data to the end of the existing file |
| 74 | * instead of erasing it. |
| 75 | * @see #openFileOutput |
| 76 | */ |
| 77 | public static final int MODE_APPEND = 0x8000; |
| 78 | |
| 79 | /** |
| 80 | * Flag for {@link #bindService}: automatically create the service as long |
| 81 | * as the binding exists. Note that while this will create the service, |
| 82 | * its {@link android.app.Service#onStart} method will still only be called due to an |
| 83 | * explicit call to {@link #startService}. Even without that, though, |
| 84 | * this still provides you with access to the service object while the |
| 85 | * service is created. |
| 86 | * |
| 87 | * <p>Specifying this flag also tells the system to treat the service |
| 88 | * as being as important as your own process -- that is, when deciding |
| 89 | * which process should be killed to free memory, the service will only |
| 90 | * be considered a candidate as long as the processes of any such bindings |
| 91 | * is also a candidate to be killed. This is to avoid situations where |
| 92 | * the service is being continually created and killed due to low memory. |
| 93 | */ |
| 94 | public static final int BIND_AUTO_CREATE = 0x0001; |
| 95 | |
| 96 | /** |
| 97 | * Flag for {@link #bindService}: include debugging help for mismatched |
| 98 | * calls to unbind. When this flag is set, the callstack of the following |
| 99 | * {@link #unbindService} call is retained, to be printed if a later |
| 100 | * incorrect unbind call is made. Note that doing this requires retaining |
| 101 | * information about the binding that was made for the lifetime of the app, |
| 102 | * resulting in a leak -- this should only be used for debugging. |
| 103 | */ |
| 104 | public static final int BIND_DEBUG_UNBIND = 0x0002; |
| 105 | |
| 106 | /** Return an AssetManager instance for your application's package. */ |
| 107 | public abstract AssetManager getAssets(); |
| 108 | |
| 109 | /** Return a Resources instance for your application's package. */ |
| 110 | public abstract Resources getResources(); |
| 111 | |
| 112 | /** Return PackageManager instance to find global package information. */ |
| 113 | public abstract PackageManager getPackageManager(); |
| 114 | |
| 115 | /** Return a ContentResolver instance for your application's package. */ |
| 116 | public abstract ContentResolver getContentResolver(); |
| 117 | |
| 118 | /** |
| 119 | * Return the Looper for the main thread of the current process. This is |
| 120 | * the thread used to dispatch calls to application components (activities, |
| 121 | * services, etc). |
| 122 | */ |
| 123 | public abstract Looper getMainLooper(); |
| 124 | |
| 125 | /** |
| 126 | * Return the context of the single, global Application object of the |
| 127 | * current process. |
| 128 | */ |
| 129 | public abstract Context getApplicationContext(); |
| 130 | |
| 131 | /** |
| 132 | * Return a localized, styled CharSequence from the application's package's |
| 133 | * default string table. |
| 134 | * |
| 135 | * @param resId Resource id for the CharSequence text |
| 136 | */ |
| 137 | public final CharSequence getText(int resId) { |
| 138 | return getResources().getText(resId); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Return a localized string from the application's package's |
| 143 | * default string table. |
| 144 | * |
| 145 | * @param resId Resource id for the string |
| 146 | */ |
| 147 | public final String getString(int resId) { |
| 148 | return getResources().getString(resId); |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Return a localized formatted string from the application's package's |
| 153 | * default string table, substituting the format arguments as defined in |
| 154 | * {@link java.util.Formatter} and {@link java.lang.String#format}. |
| 155 | * |
| 156 | * @param resId Resource id for the format string |
| 157 | * @param formatArgs The format arguments that will be used for substitution. |
| 158 | */ |
| 159 | |
| 160 | public final String getString(int resId, Object... formatArgs) { |
| 161 | return getResources().getString(resId, formatArgs); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Set the base theme for this context. Note that this should be called |
| 166 | * before any views are instantiated in the Context (for example before |
| 167 | * calling {@link android.app.Activity#setContentView} or |
| 168 | * {@link android.view.LayoutInflater#inflate}). |
| 169 | * |
| 170 | * @param resid The style resource describing the theme. |
| 171 | */ |
| 172 | public abstract void setTheme(int resid); |
| 173 | |
| 174 | /** |
| 175 | * Return the Theme object associated with this Context. |
| 176 | */ |
| 177 | public abstract Resources.Theme getTheme(); |
| 178 | |
| 179 | /** |
| 180 | * Retrieve styled attribute information in this Context's theme. See |
| 181 | * {@link Resources.Theme#obtainStyledAttributes(int[])} |
| 182 | * for more information. |
| 183 | * |
| 184 | * @see Resources.Theme#obtainStyledAttributes(int[]) |
| 185 | */ |
| 186 | public final TypedArray obtainStyledAttributes( |
| 187 | int[] attrs) { |
| 188 | return getTheme().obtainStyledAttributes(attrs); |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Retrieve styled attribute information in this Context's theme. See |
| 193 | * {@link Resources.Theme#obtainStyledAttributes(int, int[])} |
| 194 | * for more information. |
| 195 | * |
| 196 | * @see Resources.Theme#obtainStyledAttributes(int, int[]) |
| 197 | */ |
| 198 | public final TypedArray obtainStyledAttributes( |
| 199 | int resid, int[] attrs) throws Resources.NotFoundException { |
| 200 | return getTheme().obtainStyledAttributes(resid, attrs); |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Retrieve styled attribute information in this Context's theme. See |
| 205 | * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)} |
| 206 | * for more information. |
| 207 | * |
| 208 | * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int) |
| 209 | */ |
| 210 | public final TypedArray obtainStyledAttributes( |
| 211 | AttributeSet set, int[] attrs) { |
| 212 | return getTheme().obtainStyledAttributes(set, attrs, 0, 0); |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Retrieve styled attribute information in this Context's theme. See |
| 217 | * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)} |
| 218 | * for more information. |
| 219 | * |
| 220 | * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int) |
| 221 | */ |
| 222 | public final TypedArray obtainStyledAttributes( |
| 223 | AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) { |
| 224 | return getTheme().obtainStyledAttributes( |
| 225 | set, attrs, defStyleAttr, defStyleRes); |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Return a class loader you can use to retrieve classes in this package. |
| 230 | */ |
| 231 | public abstract ClassLoader getClassLoader(); |
| 232 | |
| 233 | /** Return the name of this application's package. */ |
| 234 | public abstract String getPackageName(); |
| 235 | |
| 236 | /** |
| 237 | * {@hide} |
| 238 | * Return the full path to this context's resource files. This is the ZIP files |
| 239 | * containing the application's resources. |
| 240 | * |
| 241 | * <p>Note: this is not generally useful for applications, since they should |
| 242 | * not be directly accessing the file system. |
| 243 | * |
| 244 | * |
| 245 | * @return String Path to the resources. |
| 246 | */ |
| 247 | public abstract String getPackageResourcePath(); |
| 248 | |
| 249 | /** |
| 250 | * {@hide} |
| 251 | * Return the full path to this context's code and asset files. This is the ZIP files |
| 252 | * containing the application's code and assets. |
| 253 | * |
| 254 | * <p>Note: this is not generally useful for applications, since they should |
| 255 | * not be directly accessing the file system. |
| 256 | * |
| 257 | * |
| 258 | * @return String Path to the code and assets. |
| 259 | */ |
| 260 | public abstract String getPackageCodePath(); |
| 261 | |
| 262 | /** |
| 263 | * Retrieve and hold the contents of the preferences file 'name', returning |
| 264 | * a SharedPreferences through which you can retrieve and modify its |
| 265 | * values. Only one instance of the SharedPreferences object is returned |
| 266 | * to any callers for the same name, meaning they will see each other's |
| 267 | * edits as soon as they are made. |
| 268 | * |
| 269 | * @param name Desired preferences file. If a preferences file by this name |
| 270 | * does not exist, it will be created when you retrieve an |
| 271 | * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()). |
| 272 | * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the |
| 273 | * default operation, {@link #MODE_WORLD_READABLE} |
| 274 | * and {@link #MODE_WORLD_WRITEABLE} to control permissions. |
| 275 | * |
| 276 | * @return Returns the single SharedPreferences instance that can be used |
| 277 | * to retrieve and modify the preference values. |
| 278 | * |
| 279 | * @see #MODE_PRIVATE |
| 280 | * @see #MODE_WORLD_READABLE |
| 281 | * @see #MODE_WORLD_WRITEABLE |
| 282 | */ |
| 283 | public abstract SharedPreferences getSharedPreferences(String name, |
| 284 | int mode); |
| 285 | |
| 286 | /** |
| 287 | * Open a private file associated with this Context's application package |
| 288 | * for reading. |
| 289 | * |
| 290 | * @param name The name of the file to open; can not contain path |
| 291 | * separators. |
| 292 | * |
| 293 | * @return FileInputStream Resulting input stream. |
| 294 | * |
| 295 | * @see #openFileOutput |
| 296 | * @see #fileList |
| 297 | * @see #deleteFile |
| 298 | * @see java.io.FileInputStream#FileInputStream(String) |
| 299 | */ |
| 300 | public abstract FileInputStream openFileInput(String name) |
| 301 | throws FileNotFoundException; |
| 302 | |
| 303 | /** |
| 304 | * Open a private file associated with this Context's application package |
| 305 | * for writing. Creates the file if it doesn't already exist. |
| 306 | * |
| 307 | * @param name The name of the file to open; can not contain path |
| 308 | * separators. |
| 309 | * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the |
| 310 | * default operation, {@link #MODE_APPEND} to append to an existing file, |
| 311 | * {@link #MODE_WORLD_READABLE} and {@link #MODE_WORLD_WRITEABLE} to control |
| 312 | * permissions. |
| 313 | * |
| 314 | * @return FileOutputStream Resulting output stream. |
| 315 | * |
| 316 | * @see #MODE_APPEND |
| 317 | * @see #MODE_PRIVATE |
| 318 | * @see #MODE_WORLD_READABLE |
| 319 | * @see #MODE_WORLD_WRITEABLE |
| 320 | * @see #openFileInput |
| 321 | * @see #fileList |
| 322 | * @see #deleteFile |
| 323 | * @see java.io.FileOutputStream#FileOutputStream(String) |
| 324 | */ |
| 325 | public abstract FileOutputStream openFileOutput(String name, int mode) |
| 326 | throws FileNotFoundException; |
| 327 | |
| 328 | /** |
| 329 | * Delete the given private file associated with this Context's |
| 330 | * application package. |
| 331 | * |
| 332 | * @param name The name of the file to delete; can not contain path |
| 333 | * separators. |
| 334 | * |
| 335 | * @return True if the file was successfully deleted; else |
| 336 | * false. |
| 337 | * |
| 338 | * @see #openFileInput |
| 339 | * @see #openFileOutput |
| 340 | * @see #fileList |
| 341 | * @see java.io.File#delete() |
| 342 | */ |
| 343 | public abstract boolean deleteFile(String name); |
| 344 | |
| 345 | /** |
| 346 | * Returns the absolute path on the filesystem where a file created with |
| 347 | * {@link #openFileOutput} is stored. |
| 348 | * |
| 349 | * @param name The name of the file for which you would like to get |
| 350 | * its path. |
| 351 | * |
| 352 | * @return Returns an absolute path to the given file. |
| 353 | * |
| 354 | * @see #openFileOutput |
| 355 | * @see #getFilesDir |
| 356 | * @see #getDir |
| 357 | */ |
| 358 | public abstract File getFileStreamPath(String name); |
| 359 | |
| 360 | /** |
| 361 | * Returns the absolute path to the directory on the filesystem where |
| 362 | * files created with {@link #openFileOutput} are stored. |
| 363 | * |
| 364 | * @return Returns the path of the directory holding application files. |
| 365 | * |
| 366 | * @see #openFileOutput |
| 367 | * @see #getFileStreamPath |
| 368 | * @see #getDir |
| 369 | */ |
| 370 | public abstract File getFilesDir(); |
| 371 | |
| 372 | /** |
| 373 | * Returns the absolute path to the application specific cache directory |
| 374 | * on the filesystem. These files will be ones that get deleted first when the |
| 375 | * device runs low on storage |
| 376 | * There is no guarantee when these files will be deleted. |
| 377 | * |
| 378 | * @return Returns the path of the directory holding application cache files. |
| 379 | * |
| 380 | * @see #openFileOutput |
| 381 | * @see #getFileStreamPath |
| 382 | * @see #getDir |
| 383 | */ |
| 384 | public abstract File getCacheDir(); |
| 385 | |
| 386 | /** |
| 387 | * Returns an array of strings naming the private files associated with |
| 388 | * this Context's application package. |
| 389 | * |
| 390 | * @return Array of strings naming the private files. |
| 391 | * |
| 392 | * @see #openFileInput |
| 393 | * @see #openFileOutput |
| 394 | * @see #deleteFile |
| 395 | */ |
| 396 | public abstract String[] fileList(); |
| 397 | |
| 398 | /** |
| 399 | * Retrieve, creating if needed, a new directory in which the application |
| 400 | * can place its own custom data files. You can use the returned File |
| 401 | * object to create and access files in this directory. Note that files |
| 402 | * created through a File object will only be accessible by your own |
| 403 | * application; you can only set the mode of the entire directory, not |
| 404 | * of individual files. |
| 405 | * |
| 406 | * @param name Name of the directory to retrieve. This is a directory |
| 407 | * that is created as part of your application data. |
| 408 | * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the |
| 409 | * default operation, {@link #MODE_WORLD_READABLE} and |
| 410 | * {@link #MODE_WORLD_WRITEABLE} to control permissions. |
| 411 | * |
| 412 | * @return Returns a File object for the requested directory. The directory |
| 413 | * will have been created if it does not already exist. |
| 414 | * |
| 415 | * @see #openFileOutput(String, int) |
| 416 | */ |
| 417 | public abstract File getDir(String name, int mode); |
| 418 | |
| 419 | /** |
| 420 | * Open a new private SQLiteDatabase associated with this Context's |
| 421 | * application package. Create the database file if it doesn't exist. |
| 422 | * |
| 423 | * @param name The name (unique in the application package) of the database. |
| 424 | * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the |
| 425 | * default operation, {@link #MODE_WORLD_READABLE} |
| 426 | * and {@link #MODE_WORLD_WRITEABLE} to control permissions. |
| 427 | * @param factory An optional factory class that is called to instantiate a |
| 428 | * cursor when query is called. |
| 429 | * |
| 430 | * @return The contents of a newly created database with the given name. |
| 431 | * @throws android.database.sqlite.SQLiteException if the database file could not be opened. |
| 432 | * |
| 433 | * @see #MODE_PRIVATE |
| 434 | * @see #MODE_WORLD_READABLE |
| 435 | * @see #MODE_WORLD_WRITEABLE |
| 436 | * @see #deleteDatabase |
| 437 | */ |
| 438 | public abstract SQLiteDatabase openOrCreateDatabase(String name, |
| 439 | int mode, CursorFactory factory); |
| 440 | |
| 441 | /** |
| 442 | * Delete an existing private SQLiteDatabase associated with this Context's |
| 443 | * application package. |
| 444 | * |
| 445 | * @param name The name (unique in the application package) of the |
| 446 | * database. |
| 447 | * |
| 448 | * @return True if the database was successfully deleted; else false. |
| 449 | * |
| 450 | * @see #openOrCreateDatabase |
| 451 | */ |
| 452 | public abstract boolean deleteDatabase(String name); |
| 453 | |
| 454 | /** |
| 455 | * Returns the absolute path on the filesystem where a database created with |
| 456 | * {@link #openOrCreateDatabase} is stored. |
| 457 | * |
| 458 | * @param name The name of the database for which you would like to get |
| 459 | * its path. |
| 460 | * |
| 461 | * @return Returns an absolute path to the given database. |
| 462 | * |
| 463 | * @see #openOrCreateDatabase |
| 464 | */ |
| 465 | public abstract File getDatabasePath(String name); |
| 466 | |
| 467 | /** |
| 468 | * Returns an array of strings naming the private databases associated with |
| 469 | * this Context's application package. |
| 470 | * |
| 471 | * @return Array of strings naming the private databases. |
| 472 | * |
| 473 | * @see #openOrCreateDatabase |
| 474 | * @see #deleteDatabase |
| 475 | */ |
| 476 | public abstract String[] databaseList(); |
| 477 | |
| 478 | /** |
| 479 | * Like {@link #peekWallpaper}, but always returns a valid Drawable. If |
| 480 | * no wallpaper is set, the system default wallpaper is returned. |
| 481 | * |
| 482 | * @return Returns a Drawable object that will draw the wallpaper. |
| 483 | */ |
| 484 | public abstract Drawable getWallpaper(); |
| 485 | |
| 486 | /** |
| 487 | * Retrieve the current system wallpaper. This is returned as an |
| 488 | * abstract Drawable that you can install in a View to display whatever |
| 489 | * wallpaper the user has currently set. If there is no wallpaper set, |
| 490 | * a null pointer is returned. |
| 491 | * |
| 492 | * @return Returns a Drawable object that will draw the wallpaper or a |
| 493 | * null pointer if these is none. |
| 494 | */ |
| 495 | public abstract Drawable peekWallpaper(); |
| 496 | |
| 497 | /** |
| 498 | * Returns the desired minimum width for the wallpaper. Callers of |
| 499 | * {@link #setWallpaper(android.graphics.Bitmap)} or |
| 500 | * {@link #setWallpaper(java.io.InputStream)} should check this value |
| 501 | * beforehand to make sure the supplied wallpaper respects the desired |
| 502 | * minimum width. |
| 503 | * |
| 504 | * If the returned value is <= 0, the caller should use the width of |
| 505 | * the default display instead. |
| 506 | * |
| 507 | * @return The desired minimum width for the wallpaper. This value should |
| 508 | * be honored by applications that set the wallpaper but it is not |
| 509 | * mandatory. |
| 510 | */ |
| 511 | public abstract int getWallpaperDesiredMinimumWidth(); |
| 512 | |
| 513 | /** |
| 514 | * Returns the desired minimum height for the wallpaper. Callers of |
| 515 | * {@link #setWallpaper(android.graphics.Bitmap)} or |
| 516 | * {@link #setWallpaper(java.io.InputStream)} should check this value |
| 517 | * beforehand to make sure the supplied wallpaper respects the desired |
| 518 | * minimum height. |
| 519 | * |
| 520 | * If the returned value is <= 0, the caller should use the height of |
| 521 | * the default display instead. |
| 522 | * |
| 523 | * @return The desired minimum height for the wallpaper. This value should |
| 524 | * be honored by applications that set the wallpaper but it is not |
| 525 | * mandatory. |
| 526 | */ |
| 527 | public abstract int getWallpaperDesiredMinimumHeight(); |
| 528 | |
| 529 | /** |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 530 | * Returns the scale in which the application will be drawn on the |
| 531 | * screen. This is usually 1.0f if the application supports the device's |
| 532 | * resolution/density. This will be 1.5f, for example, if the application |
| 533 | * that supports only 160 density runs on 240 density screen. |
| 534 | * |
| 535 | * @hide |
| 536 | */ |
| 537 | public abstract float getApplicationScale(); |
| 538 | |
| 539 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 540 | * Change the current system wallpaper to a bitmap. The given bitmap is |
| 541 | * converted to a PNG and stored as the wallpaper. On success, the intent |
| 542 | * {@link Intent#ACTION_WALLPAPER_CHANGED} is broadcast. |
| 543 | * |
| 544 | * @param bitmap The bitmap to save. |
| 545 | * |
| 546 | * @throws IOException If an error occurs reverting to the default |
| 547 | * wallpaper. |
| 548 | */ |
| 549 | public abstract void setWallpaper(Bitmap bitmap) throws IOException; |
| 550 | |
| 551 | /** |
| 552 | * Change the current system wallpaper to a specific byte stream. The |
| 553 | * give InputStream is copied into persistent storage and will now be |
| 554 | * used as the wallpaper. Currently it must be either a JPEG or PNG |
| 555 | * image. On success, the intent {@link Intent#ACTION_WALLPAPER_CHANGED} |
| 556 | * is broadcast. |
| 557 | * |
| 558 | * @param data A stream containing the raw data to install as a wallpaper. |
| 559 | * |
| 560 | * @throws IOException If an error occurs reverting to the default |
| 561 | * wallpaper. |
| 562 | */ |
| 563 | public abstract void setWallpaper(InputStream data) throws IOException; |
| 564 | |
| 565 | /** |
| 566 | * Remove any currently set wallpaper, reverting to the system's default |
| 567 | * wallpaper. On success, the intent {@link Intent#ACTION_WALLPAPER_CHANGED} |
| 568 | * is broadcast. |
| 569 | * |
| 570 | * @throws IOException If an error occurs reverting to the default |
| 571 | * wallpaper. |
| 572 | */ |
| 573 | public abstract void clearWallpaper() throws IOException; |
| 574 | |
| 575 | /** |
| 576 | * Launch a new activity. You will not receive any information about when |
| 577 | * the activity exits. |
| 578 | * |
| 579 | * <p>Note that if this method is being called from outside of an |
| 580 | * {@link android.app.Activity} Context, then the Intent must include |
| 581 | * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because, |
| 582 | * without being started from an existing Activity, there is no existing |
| 583 | * task in which to place the new activity and thus it needs to be placed |
| 584 | * in its own separate task. |
| 585 | * |
| 586 | * <p>This method throws {@link ActivityNotFoundException} |
| 587 | * if there was no Activity found to run the given Intent. |
| 588 | * |
| 589 | * @param intent The description of the activity to start. |
| 590 | * |
| 591 | * @throws ActivityNotFoundException |
| 592 | * |
| 593 | * @see PackageManager#resolveActivity |
| 594 | */ |
| 595 | public abstract void startActivity(Intent intent); |
| 596 | |
| 597 | /** |
| 598 | * Broadcast the given intent to all interested BroadcastReceivers. This |
| 599 | * call is asynchronous; it returns immediately, and you will continue |
| 600 | * executing while the receivers are run. No results are propagated from |
| 601 | * receivers and receivers can not abort the broadcast. If you want |
| 602 | * to allow receivers to propagate results or abort the broadcast, you must |
| 603 | * send an ordered broadcast using |
| 604 | * {@link #sendOrderedBroadcast(Intent, String)}. |
| 605 | * |
| 606 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 607 | * |
| 608 | * @param intent The Intent to broadcast; all receivers matching this |
| 609 | * Intent will receive the broadcast. |
| 610 | * |
| 611 | * @see android.content.BroadcastReceiver |
| 612 | * @see #registerReceiver |
| 613 | * @see #sendBroadcast(Intent, String) |
| 614 | * @see #sendOrderedBroadcast(Intent, String) |
| 615 | * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) |
| 616 | */ |
| 617 | public abstract void sendBroadcast(Intent intent); |
| 618 | |
| 619 | /** |
| 620 | * Broadcast the given intent to all interested BroadcastReceivers, allowing |
| 621 | * an optional required permission to be enforced. This |
| 622 | * call is asynchronous; it returns immediately, and you will continue |
| 623 | * executing while the receivers are run. No results are propagated from |
| 624 | * receivers and receivers can not abort the broadcast. If you want |
| 625 | * to allow receivers to propagate results or abort the broadcast, you must |
| 626 | * send an ordered broadcast using |
| 627 | * {@link #sendOrderedBroadcast(Intent, String)}. |
| 628 | * |
| 629 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 630 | * |
| 631 | * @param intent The Intent to broadcast; all receivers matching this |
| 632 | * Intent will receive the broadcast. |
| 633 | * @param receiverPermission (optional) String naming a permissions that |
| 634 | * a receiver must hold in order to receive your broadcast. |
| 635 | * If null, no permission is required. |
| 636 | * |
| 637 | * @see android.content.BroadcastReceiver |
| 638 | * @see #registerReceiver |
| 639 | * @see #sendBroadcast(Intent) |
| 640 | * @see #sendOrderedBroadcast(Intent, String) |
| 641 | * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) |
| 642 | */ |
| 643 | public abstract void sendBroadcast(Intent intent, |
| 644 | String receiverPermission); |
| 645 | |
| 646 | /** |
| 647 | * Broadcast the given intent to all interested BroadcastReceivers, delivering |
| 648 | * them one at a time to allow more preferred receivers to consume the |
| 649 | * broadcast before it is delivered to less preferred receivers. This |
| 650 | * call is asynchronous; it returns immediately, and you will continue |
| 651 | * executing while the receivers are run. |
| 652 | * |
| 653 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 654 | * |
| 655 | * @param intent The Intent to broadcast; all receivers matching this |
| 656 | * Intent will receive the broadcast. |
| 657 | * @param receiverPermission (optional) String naming a permissions that |
| 658 | * a receiver must hold in order to receive your broadcast. |
| 659 | * If null, no permission is required. |
| 660 | * |
| 661 | * @see android.content.BroadcastReceiver |
| 662 | * @see #registerReceiver |
| 663 | * @see #sendBroadcast(Intent) |
| 664 | * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) |
| 665 | */ |
| 666 | public abstract void sendOrderedBroadcast(Intent intent, |
| 667 | String receiverPermission); |
| 668 | |
| 669 | /** |
| 670 | * Version of {@link #sendBroadcast(Intent)} that allows you to |
| 671 | * receive data back from the broadcast. This is accomplished by |
| 672 | * supplying your own BroadcastReceiver when calling, which will be |
| 673 | * treated as a final receiver at the end of the broadcast -- its |
| 674 | * {@link BroadcastReceiver#onReceive} method will be called with |
| 675 | * the result values collected from the other receivers. If you use |
| 676 | * an <var>resultReceiver</var> with this method, then the broadcast will |
| 677 | * be serialized in the same way as calling |
| 678 | * {@link #sendOrderedBroadcast(Intent, String)}. |
| 679 | * |
| 680 | * <p>Like {@link #sendBroadcast(Intent)}, this method is |
| 681 | * asynchronous; it will return before |
| 682 | * resultReceiver.onReceive() is called. |
| 683 | * |
| 684 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 685 | * |
| 686 | * @param intent The Intent to broadcast; all receivers matching this |
| 687 | * Intent will receive the broadcast. |
| 688 | * @param receiverPermission String naming a permissions that |
| 689 | * a receiver must hold in order to receive your broadcast. |
| 690 | * If null, no permission is required. |
| 691 | * @param resultReceiver Your own BroadcastReceiver to treat as the final |
| 692 | * receiver of the broadcast. |
| 693 | * @param scheduler A custom Handler with which to schedule the |
| 694 | * resultReceiver callback; if null it will be |
| 695 | * scheduled in the Context's main thread. |
| 696 | * @param initialCode An initial value for the result code. Often |
| 697 | * Activity.RESULT_OK. |
| 698 | * @param initialData An initial value for the result data. Often |
| 699 | * null. |
| 700 | * @param initialExtras An initial value for the result extras. Often |
| 701 | * null. |
| 702 | * |
| 703 | * @see #sendBroadcast(Intent) |
| 704 | * @see #sendBroadcast(Intent, String) |
| 705 | * @see #sendOrderedBroadcast(Intent, String) |
| 706 | * @see #sendStickyBroadcast(Intent) |
| 707 | * @see android.content.BroadcastReceiver |
| 708 | * @see #registerReceiver |
| 709 | * @see android.app.Activity#RESULT_OK |
| 710 | */ |
| 711 | public abstract void sendOrderedBroadcast(Intent intent, |
| 712 | String receiverPermission, BroadcastReceiver resultReceiver, |
| 713 | Handler scheduler, int initialCode, String initialData, |
| 714 | Bundle initialExtras); |
| 715 | |
| 716 | /** |
| 717 | * Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the |
| 718 | * Intent you are sending stays around after the broadcast is complete, |
| 719 | * so that others can quickly retrieve that data through the return |
| 720 | * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In |
| 721 | * all other ways, this behaves the same as |
| 722 | * {@link #sendBroadcast(Intent)}. |
| 723 | * |
| 724 | * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY} |
| 725 | * permission in order to use this API. If you do not hold that |
| 726 | * permission, {@link SecurityException} will be thrown. |
| 727 | * |
| 728 | * @param intent The Intent to broadcast; all receivers matching this |
| 729 | * Intent will receive the broadcast, and the Intent will be held to |
| 730 | * be re-broadcast to future receivers. |
| 731 | * |
| 732 | * @see #sendBroadcast(Intent) |
| 733 | */ |
| 734 | public abstract void sendStickyBroadcast(Intent intent); |
| 735 | |
| 736 | /** |
| 737 | * Remove the data previously sent with {@link #sendStickyBroadcast}, |
| 738 | * so that it is as if the sticky broadcast had never happened. |
| 739 | * |
| 740 | * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY} |
| 741 | * permission in order to use this API. If you do not hold that |
| 742 | * permission, {@link SecurityException} will be thrown. |
| 743 | * |
| 744 | * @param intent The Intent that was previously broadcast. |
| 745 | * |
| 746 | * @see #sendStickyBroadcast |
| 747 | */ |
| 748 | public abstract void removeStickyBroadcast(Intent intent); |
| 749 | |
| 750 | /** |
Chris Tate | a34df8a2 | 2009-04-02 23:15:58 -0700 | [diff] [blame] | 751 | * Register a BroadcastReceiver to be run in the main activity thread. The |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 752 | * <var>receiver</var> will be called with any broadcast Intent that |
| 753 | * matches <var>filter</var>, in the main application thread. |
| 754 | * |
| 755 | * <p>The system may broadcast Intents that are "sticky" -- these stay |
| 756 | * around after the broadcast as finished, to be sent to any later |
| 757 | * registrations. If your IntentFilter matches one of these sticky |
| 758 | * Intents, that Intent will be returned by this function |
| 759 | * <strong>and</strong> sent to your <var>receiver</var> as if it had just |
| 760 | * been broadcast. |
| 761 | * |
| 762 | * <p>There may be multiple sticky Intents that match <var>filter</var>, |
| 763 | * in which case each of these will be sent to <var>receiver</var>. In |
| 764 | * this case, only one of these can be returned directly by the function; |
| 765 | * which of these that is returned is arbitrarily decided by the system. |
| 766 | * |
| 767 | * <p>If you know the Intent your are registering for is sticky, you can |
| 768 | * supply null for your <var>receiver</var>. In this case, no receiver is |
| 769 | * registered -- the function simply returns the sticky Intent that |
| 770 | * matches <var>filter</var>. In the case of multiple matches, the same |
| 771 | * rules as described above apply. |
| 772 | * |
| 773 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 774 | * |
Chris Tate | a34df8a2 | 2009-04-02 23:15:58 -0700 | [diff] [blame] | 775 | * <p class="note">Note: this method <em>cannot be called from a |
| 776 | * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver |
| 777 | * that is declared in an application's manifest. It is okay, however, to call |
| 778 | * this method from another BroadcastReceiver that has itself been registered |
| 779 | * at run time with {@link #registerReceiver}, since the lifetime of such a |
| 780 | * registered BroadcastReceiver is tied to the object that registered it.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 781 | * |
| 782 | * @param receiver The BroadcastReceiver to handle the broadcast. |
| 783 | * @param filter Selects the Intent broadcasts to be received. |
| 784 | * |
| 785 | * @return The first sticky intent found that matches <var>filter</var>, |
| 786 | * or null if there are none. |
| 787 | * |
| 788 | * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler) |
| 789 | * @see #sendBroadcast |
| 790 | * @see #unregisterReceiver |
| 791 | */ |
| 792 | public abstract Intent registerReceiver(BroadcastReceiver receiver, |
| 793 | IntentFilter filter); |
| 794 | |
| 795 | /** |
| 796 | * Register to receive intent broadcasts, to run in the context of |
| 797 | * <var>scheduler</var>. See |
| 798 | * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more |
| 799 | * information. This allows you to enforce permissions on who can |
| 800 | * broadcast intents to your receiver, or have the receiver run in |
| 801 | * a different thread than the main application thread. |
| 802 | * |
| 803 | * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts. |
| 804 | * |
| 805 | * @param receiver The BroadcastReceiver to handle the broadcast. |
| 806 | * @param filter Selects the Intent broadcasts to be received. |
| 807 | * @param broadcastPermission String naming a permissions that a |
| 808 | * broadcaster must hold in order to send an Intent to you. If null, |
| 809 | * no permission is required. |
| 810 | * @param scheduler Handler identifying the thread that will receive |
| 811 | * the Intent. If null, the main thread of the process will be used. |
| 812 | * |
| 813 | * @return The first sticky intent found that matches <var>filter</var>, |
| 814 | * or null if there are none. |
| 815 | * |
| 816 | * @see #registerReceiver(BroadcastReceiver, IntentFilter) |
| 817 | * @see #sendBroadcast |
| 818 | * @see #unregisterReceiver |
| 819 | */ |
| 820 | public abstract Intent registerReceiver(BroadcastReceiver receiver, |
| 821 | IntentFilter filter, |
| 822 | String broadcastPermission, |
| 823 | Handler scheduler); |
| 824 | |
| 825 | /** |
| 826 | * Unregister a previously registered BroadcastReceiver. <em>All</em> |
| 827 | * filters that have been registered for this BroadcastReceiver will be |
| 828 | * removed. |
| 829 | * |
| 830 | * @param receiver The BroadcastReceiver to unregister. |
| 831 | * |
| 832 | * @see #registerReceiver |
| 833 | */ |
| 834 | public abstract void unregisterReceiver(BroadcastReceiver receiver); |
| 835 | |
| 836 | /** |
| 837 | * Request that a given application service be started. The Intent |
| 838 | * can either contain the complete class name of a specific service |
| 839 | * implementation to start, or an abstract definition through the |
| 840 | * action and other fields of the kind of service to start. If this service |
| 841 | * is not already running, it will be instantiated and started (creating a |
| 842 | * process for it if needed); if it is running then it remains running. |
| 843 | * |
| 844 | * <p>Every call to this method will result in a corresponding call to |
| 845 | * the target service's {@link android.app.Service#onStart} method, |
| 846 | * with the <var>intent</var> given here. This provides a convenient way |
| 847 | * to submit jobs to a service without having to bind and call on to its |
| 848 | * interface. |
| 849 | * |
| 850 | * <p>Using startService() overrides the default service lifetime that is |
| 851 | * managed by {@link #bindService}: it requires the service to remain |
| 852 | * running until {@link #stopService} is called, regardless of whether |
| 853 | * any clients are connected to it. Note that calls to startService() |
| 854 | * are not nesting: no matter how many times you call startService(), |
| 855 | * a single call to {@link #stopService} will stop it. |
| 856 | * |
| 857 | * <p>The system attempts to keep running services around as much as |
| 858 | * possible. The only time they should be stopped is if the current |
| 859 | * foreground application is using so many resources that the service needs |
| 860 | * to be killed. If any errors happen in the service's process, it will |
| 861 | * automatically be restarted. |
| 862 | * |
| 863 | * <p>This function will throw {@link SecurityException} if you do not |
| 864 | * have permission to start the given service. |
| 865 | * |
| 866 | * @param service Identifies the service to be started. The Intent may |
| 867 | * specify either an explicit component name to start, or a logical |
| 868 | * description (action, category, etc) to match an |
| 869 | * {@link IntentFilter} published by a service. Additional values |
| 870 | * may be included in the Intent extras to supply arguments along with |
| 871 | * this specific start call. |
| 872 | * |
| 873 | * @return If the service is being started or is already running, the |
| 874 | * {@link ComponentName} of the actual service that was started is |
| 875 | * returned; else if the service does not exist null is returned. |
| 876 | * |
| 877 | * @throws SecurityException |
| 878 | * |
| 879 | * @see #stopService |
| 880 | * @see #bindService |
| 881 | */ |
| 882 | public abstract ComponentName startService(Intent service); |
| 883 | |
| 884 | /** |
| 885 | * Request that a given application service be stopped. If the service is |
| 886 | * not running, nothing happens. Otherwise it is stopped. Note that calls |
| 887 | * to startService() are not counted -- this stops the service no matter |
| 888 | * how many times it was started. |
| 889 | * |
| 890 | * <p>Note that if a stopped service still has {@link ServiceConnection} |
| 891 | * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will |
| 892 | * not be destroyed until all of these bindings are removed. See |
| 893 | * the {@link android.app.Service} documentation for more details on a |
| 894 | * service's lifecycle. |
| 895 | * |
| 896 | * <p>This function will throw {@link SecurityException} if you do not |
| 897 | * have permission to stop the given service. |
| 898 | * |
| 899 | * @param service Description of the service to be stopped. The Intent may |
| 900 | * specify either an explicit component name to start, or a logical |
| 901 | * description (action, category, etc) to match an |
| 902 | * {@link IntentFilter} published by a service. |
| 903 | * |
| 904 | * @return If there is a service matching the given Intent that is already |
| 905 | * running, then it is stopped and true is returned; else false is returned. |
| 906 | * |
| 907 | * @throws SecurityException |
| 908 | * |
| 909 | * @see #startService |
| 910 | */ |
| 911 | public abstract boolean stopService(Intent service); |
| 912 | |
| 913 | /** |
| 914 | * Connect to an application service, creating it if needed. This defines |
| 915 | * a dependency between your application and the service. The given |
| 916 | * <var>conn</var> will receive the service object when its created and be |
| 917 | * told if it dies and restarts. The service will be considered required |
| 918 | * by the system only for as long as the calling context exists. For |
| 919 | * example, if this Context is an Activity that is stopped, the service will |
| 920 | * not be required to continue running until the Activity is resumed. |
| 921 | * |
| 922 | * <p>This function will throw {@link SecurityException} if you do not |
| 923 | * have permission to bind to the given service. |
| 924 | * |
| 925 | * <p class="note">Note: this method <em>can not be called from an |
| 926 | * {@link BroadcastReceiver} component</em>. A pattern you can use to |
| 927 | * communicate from an BroadcastReceiver to a Service is to call |
| 928 | * {@link #startService} with the arguments containing the command to be |
| 929 | * sent, with the service calling its |
| 930 | * {@link android.app.Service#stopSelf(int)} method when done executing |
| 931 | * that command. See the API demo App/Service/Service Start Arguments |
| 932 | * Controller for an illustration of this. It is okay, however, to use |
| 933 | * this method from an BroadcastReceiver that has been registered with |
| 934 | * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver |
| 935 | * is tied to another object (the one that registered it).</p> |
| 936 | * |
| 937 | * @param service Identifies the service to connect to. The Intent may |
| 938 | * specify either an explicit component name, or a logical |
| 939 | * description (action, category, etc) to match an |
| 940 | * {@link IntentFilter} published by a service. |
| 941 | * @param conn Receives information as the service is started and stopped. |
| 942 | * @param flags Operation options for the binding. May be 0 or |
| 943 | * {@link #BIND_AUTO_CREATE}. |
| 944 | * @return If you have successfully bound to the service, true is returned; |
| 945 | * false is returned if the connection is not made so you will not |
| 946 | * receive the service object. |
| 947 | * |
| 948 | * @throws SecurityException |
| 949 | * |
| 950 | * @see #unbindService |
| 951 | * @see #startService |
| 952 | * @see #BIND_AUTO_CREATE |
| 953 | */ |
| 954 | public abstract boolean bindService(Intent service, ServiceConnection conn, |
| 955 | int flags); |
| 956 | |
| 957 | /** |
| 958 | * Disconnect from an application service. You will no longer receive |
| 959 | * calls as the service is restarted, and the service is now allowed to |
| 960 | * stop at any time. |
| 961 | * |
| 962 | * @param conn The connection interface previously supplied to |
| 963 | * bindService(). |
| 964 | * |
| 965 | * @see #bindService |
| 966 | */ |
| 967 | public abstract void unbindService(ServiceConnection conn); |
| 968 | |
| 969 | /** |
| 970 | * Start executing an {@link android.app.Instrumentation} class. The given |
| 971 | * Instrumentation component will be run by killing its target application |
| 972 | * (if currently running), starting the target process, instantiating the |
| 973 | * instrumentation component, and then letting it drive the application. |
| 974 | * |
| 975 | * <p>This function is not synchronous -- it returns as soon as the |
| 976 | * instrumentation has started and while it is running. |
| 977 | * |
| 978 | * <p>Instrumentation is normally only allowed to run against a package |
| 979 | * that is either unsigned or signed with a signature that the |
| 980 | * the instrumentation package is also signed with (ensuring the target |
| 981 | * trusts the instrumentation). |
| 982 | * |
| 983 | * @param className Name of the Instrumentation component to be run. |
| 984 | * @param profileFile Optional path to write profiling data as the |
| 985 | * instrumentation runs, or null for no profiling. |
| 986 | * @param arguments Additional optional arguments to pass to the |
| 987 | * instrumentation, or null. |
| 988 | * |
| 989 | * @return Returns true if the instrumentation was successfully started, |
| 990 | * else false if it could not be found. |
| 991 | */ |
| 992 | public abstract boolean startInstrumentation(ComponentName className, |
| 993 | String profileFile, Bundle arguments); |
| 994 | |
| 995 | /** |
| 996 | * Return the handle to a system-level service by name. The class of the |
| 997 | * returned object varies by the requested name. Currently available names |
| 998 | * are: |
| 999 | * |
| 1000 | * <dl> |
| 1001 | * <dt> {@link #WINDOW_SERVICE} ("window") |
| 1002 | * <dd> The top-level window manager in which you can place custom |
| 1003 | * windows. The returned object is a {@link android.view.WindowManager}. |
| 1004 | * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater") |
| 1005 | * <dd> A {@link android.view.LayoutInflater} for inflating layout resources |
| 1006 | * in this context. |
| 1007 | * <dt> {@link #ACTIVITY_SERVICE} ("activity") |
| 1008 | * <dd> A {@link android.app.ActivityManager} for interacting with the |
| 1009 | * global activity state of the system. |
| 1010 | * <dt> {@link #POWER_SERVICE} ("power") |
| 1011 | * <dd> A {@link android.os.PowerManager} for controlling power |
| 1012 | * management. |
| 1013 | * <dt> {@link #ALARM_SERVICE} ("alarm") |
| 1014 | * <dd> A {@link android.app.AlarmManager} for receiving intents at the |
| 1015 | * time of your choosing. |
| 1016 | * <dt> {@link #NOTIFICATION_SERVICE} ("notification") |
| 1017 | * <dd> A {@link android.app.NotificationManager} for informing the user |
| 1018 | * of background events. |
| 1019 | * <dt> {@link #KEYGUARD_SERVICE} ("keyguard") |
| 1020 | * <dd> A {@link android.app.KeyguardManager} for controlling keyguard. |
| 1021 | * <dt> {@link #LOCATION_SERVICE} ("location") |
| 1022 | * <dd> A {@link android.location.LocationManager} for controlling location |
| 1023 | * (e.g., GPS) updates. |
| 1024 | * <dt> {@link #SEARCH_SERVICE} ("search") |
| 1025 | * <dd> A {@link android.app.SearchManager} for handling search. |
| 1026 | * <dt> {@link #VIBRATOR_SERVICE} ("vibrator") |
| 1027 | * <dd> A {@link android.os.Vibrator} for interacting with the vibrator |
| 1028 | * hardware. |
| 1029 | * <dt> {@link #CONNECTIVITY_SERVICE} ("connection") |
| 1030 | * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for |
| 1031 | * handling management of network connections. |
| 1032 | * <dt> {@link #WIFI_SERVICE} ("wifi") |
| 1033 | * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of |
| 1034 | * Wi-Fi connectivity. |
| 1035 | * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method") |
| 1036 | * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager} |
| 1037 | * for management of input methods. |
| 1038 | * </dl> |
| 1039 | * |
| 1040 | * <p>Note: System services obtained via this API may be closely associated with |
| 1041 | * the Context in which they are obtained from. In general, do not share the |
| 1042 | * service objects between various different contexts (Activities, Applications, |
| 1043 | * Services, Providers, etc.) |
| 1044 | * |
| 1045 | * @param name The name of the desired service. |
| 1046 | * |
| 1047 | * @return The service or null if the name does not exist. |
| 1048 | * |
| 1049 | * @see #WINDOW_SERVICE |
| 1050 | * @see android.view.WindowManager |
| 1051 | * @see #LAYOUT_INFLATER_SERVICE |
| 1052 | * @see android.view.LayoutInflater |
| 1053 | * @see #ACTIVITY_SERVICE |
| 1054 | * @see android.app.ActivityManager |
| 1055 | * @see #POWER_SERVICE |
| 1056 | * @see android.os.PowerManager |
| 1057 | * @see #ALARM_SERVICE |
| 1058 | * @see android.app.AlarmManager |
| 1059 | * @see #NOTIFICATION_SERVICE |
| 1060 | * @see android.app.NotificationManager |
| 1061 | * @see #KEYGUARD_SERVICE |
| 1062 | * @see android.app.KeyguardManager |
| 1063 | * @see #LOCATION_SERVICE |
| 1064 | * @see android.location.LocationManager |
| 1065 | * @see #SEARCH_SERVICE |
| 1066 | * @see android.app.SearchManager |
| 1067 | * @see #SENSOR_SERVICE |
| 1068 | * @see android.hardware.SensorManager |
| 1069 | * @see #VIBRATOR_SERVICE |
| 1070 | * @see android.os.Vibrator |
| 1071 | * @see #CONNECTIVITY_SERVICE |
| 1072 | * @see android.net.ConnectivityManager |
| 1073 | * @see #WIFI_SERVICE |
| 1074 | * @see android.net.wifi.WifiManager |
| 1075 | * @see #AUDIO_SERVICE |
| 1076 | * @see android.media.AudioManager |
| 1077 | * @see #TELEPHONY_SERVICE |
| 1078 | * @see android.telephony.TelephonyManager |
| 1079 | * @see #INPUT_METHOD_SERVICE |
| 1080 | * @see android.view.inputmethod.InputMethodManager |
| 1081 | */ |
| 1082 | public abstract Object getSystemService(String name); |
| 1083 | |
| 1084 | /** |
| 1085 | * Use with {@link #getSystemService} to retrieve a |
| 1086 | * {@link android.os.PowerManager} for controlling power management, |
| 1087 | * including "wake locks," which let you keep the device on while |
| 1088 | * you're running long tasks. |
| 1089 | */ |
| 1090 | public static final String POWER_SERVICE = "power"; |
| 1091 | /** |
| 1092 | * Use with {@link #getSystemService} to retrieve a |
| 1093 | * {@link android.view.WindowManager} for accessing the system's window |
| 1094 | * manager. |
| 1095 | * |
| 1096 | * @see #getSystemService |
| 1097 | * @see android.view.WindowManager |
| 1098 | */ |
| 1099 | public static final String WINDOW_SERVICE = "window"; |
| 1100 | /** |
| 1101 | * Use with {@link #getSystemService} to retrieve a |
| 1102 | * {@link android.view.LayoutInflater} for inflating layout resources in this |
| 1103 | * context. |
| 1104 | * |
| 1105 | * @see #getSystemService |
| 1106 | * @see android.view.LayoutInflater |
| 1107 | */ |
| 1108 | public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater"; |
| 1109 | /** |
| 1110 | * Use with {@link #getSystemService} to retrieve a |
Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 1111 | * {@link android.accounts.AccountManager} for receiving intents at a |
| 1112 | * time of your choosing. |
| 1113 | * TODO STOPSHIP perform a final review of the the account apis before shipping |
| 1114 | * |
| 1115 | * @see #getSystemService |
| 1116 | * @see android.accounts.AccountManager |
| 1117 | */ |
| 1118 | public static final String ACCOUNT_SERVICE = "account"; |
| 1119 | /** |
| 1120 | * Use with {@link #getSystemService} to retrieve a |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | * {@link android.app.ActivityManager} for interacting with the global |
| 1122 | * system state. |
| 1123 | * |
| 1124 | * @see #getSystemService |
| 1125 | * @see android.app.ActivityManager |
| 1126 | */ |
| 1127 | public static final String ACTIVITY_SERVICE = "activity"; |
| 1128 | /** |
| 1129 | * Use with {@link #getSystemService} to retrieve a |
| 1130 | * {@link android.app.AlarmManager} for receiving intents at a |
| 1131 | * time of your choosing. |
| 1132 | * |
| 1133 | * @see #getSystemService |
| 1134 | * @see android.app.AlarmManager |
| 1135 | */ |
| 1136 | public static final String ALARM_SERVICE = "alarm"; |
| 1137 | /** |
| 1138 | * Use with {@link #getSystemService} to retrieve a |
| 1139 | * {@link android.app.NotificationManager} for informing the user of |
| 1140 | * background events. |
| 1141 | * |
| 1142 | * @see #getSystemService |
| 1143 | * @see android.app.NotificationManager |
| 1144 | */ |
| 1145 | public static final String NOTIFICATION_SERVICE = "notification"; |
| 1146 | /** |
| 1147 | * Use with {@link #getSystemService} to retrieve a |
| 1148 | * {@link android.app.NotificationManager} for controlling keyguard. |
| 1149 | * |
| 1150 | * @see #getSystemService |
| 1151 | * @see android.app.KeyguardManager |
| 1152 | */ |
| 1153 | public static final String KEYGUARD_SERVICE = "keyguard"; |
| 1154 | /** |
| 1155 | * Use with {@link #getSystemService} to retrieve a {@link |
| 1156 | * android.location.LocationManager} for controlling location |
| 1157 | * updates. |
| 1158 | * |
| 1159 | * @see #getSystemService |
| 1160 | * @see android.location.LocationManager |
| 1161 | */ |
| 1162 | public static final String LOCATION_SERVICE = "location"; |
| 1163 | /** |
| 1164 | * Use with {@link #getSystemService} to retrieve a {@link |
| 1165 | * android.app.SearchManager} for handling searches. |
| 1166 | * |
| 1167 | * @see #getSystemService |
| 1168 | * @see android.app.SearchManager |
| 1169 | */ |
| 1170 | public static final String SEARCH_SERVICE = "search"; |
| 1171 | /** |
| 1172 | * Use with {@link #getSystemService} to retrieve a {@link |
| 1173 | * android.hardware.SensorManager} for accessing sensors. |
| 1174 | * |
| 1175 | * @see #getSystemService |
| 1176 | * @see android.hardware.SensorManager |
| 1177 | */ |
| 1178 | public static final String SENSOR_SERVICE = "sensor"; |
| 1179 | /** |
| 1180 | * Use with {@link #getSystemService} to retrieve a {@link |
| 1181 | * android.bluetooth.BluetoothDevice} for interacting with Bluetooth. |
| 1182 | * |
| 1183 | * @see #getSystemService |
| 1184 | * @see android.bluetooth.BluetoothDevice |
| 1185 | * @hide |
| 1186 | */ |
| 1187 | public static final String BLUETOOTH_SERVICE = "bluetooth"; |
| 1188 | /** |
| 1189 | * Use with {@link #getSystemService} to retrieve a |
| 1190 | * com.android.server.WallpaperService for accessing wallpapers. |
| 1191 | * |
| 1192 | * @see #getSystemService |
| 1193 | */ |
| 1194 | public static final String WALLPAPER_SERVICE = "wallpaper"; |
| 1195 | /** |
| 1196 | * Use with {@link #getSystemService} to retrieve a {@link |
| 1197 | * android.os.Vibrator} for interacting with the vibration hardware. |
| 1198 | * |
| 1199 | * @see #getSystemService |
| 1200 | * @see android.os.Vibrator |
| 1201 | */ |
| 1202 | public static final String VIBRATOR_SERVICE = "vibrator"; |
| 1203 | /** |
| 1204 | * Use with {@link #getSystemService} to retrieve a {@link |
| 1205 | * android.app.StatusBarManager} for interacting with the status bar. |
| 1206 | * |
| 1207 | * @see #getSystemService |
| 1208 | * @see android.app.StatusBarManager |
| 1209 | * @hide |
| 1210 | */ |
| 1211 | public static final String STATUS_BAR_SERVICE = "statusbar"; |
| 1212 | |
| 1213 | /** |
| 1214 | * Use with {@link #getSystemService} to retrieve a {@link |
| 1215 | * android.net.ConnectivityManager} for handling management of |
| 1216 | * network connections. |
| 1217 | * |
| 1218 | * @see #getSystemService |
| 1219 | * @see android.net.ConnectivityManager |
| 1220 | */ |
| 1221 | public static final String CONNECTIVITY_SERVICE = "connectivity"; |
| 1222 | |
| 1223 | /** |
| 1224 | * Use with {@link #getSystemService} to retrieve a {@link |
| 1225 | * android.net.wifi.WifiManager} for handling management of |
| 1226 | * Wi-Fi access. |
| 1227 | * |
| 1228 | * @see #getSystemService |
| 1229 | * @see android.net.wifi.WifiManager |
| 1230 | */ |
| 1231 | public static final String WIFI_SERVICE = "wifi"; |
| 1232 | |
| 1233 | /** |
| 1234 | * Use with {@link #getSystemService} to retrieve a |
| 1235 | * {@link android.media.AudioManager} for handling management of volume, |
| 1236 | * ringer modes and audio routing. |
| 1237 | * |
| 1238 | * @see #getSystemService |
| 1239 | * @see android.media.AudioManager |
| 1240 | */ |
| 1241 | public static final String AUDIO_SERVICE = "audio"; |
| 1242 | |
| 1243 | /** |
| 1244 | * Use with {@link #getSystemService} to retrieve a |
| 1245 | * {@link android.telephony.TelephonyManager} for handling management the |
| 1246 | * telephony features of the device. |
| 1247 | * |
| 1248 | * @see #getSystemService |
| 1249 | * @see android.telephony.TelephonyManager |
| 1250 | */ |
| 1251 | public static final String TELEPHONY_SERVICE = "phone"; |
| 1252 | |
| 1253 | /** |
| 1254 | * Use with {@link #getSystemService} to retrieve a |
| 1255 | * {@link android.text.ClipboardManager} for accessing and modifying |
| 1256 | * the contents of the global clipboard. |
| 1257 | * |
| 1258 | * @see #getSystemService |
| 1259 | * @see android.text.ClipboardManager |
| 1260 | */ |
| 1261 | public static final String CLIPBOARD_SERVICE = "clipboard"; |
| 1262 | |
| 1263 | /** |
| 1264 | * Use with {@link #getSystemService} to retrieve a |
| 1265 | * {@link android.view.inputmethod.InputMethodManager} for accessing input |
| 1266 | * methods. |
| 1267 | * |
| 1268 | * @see #getSystemService |
| 1269 | */ |
| 1270 | public static final String INPUT_METHOD_SERVICE = "input_method"; |
| 1271 | |
| 1272 | /** |
| 1273 | * Use with {@link #getSystemService} to retrieve a |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1274 | * {@blink android.appwidget.AppWidgetManager} for accessing AppWidgets. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1275 | * |
| 1276 | * @hide |
| 1277 | * @see #getSystemService |
| 1278 | */ |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1279 | public static final String APPWIDGET_SERVICE = "appwidget"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1280 | |
| 1281 | /** |
| 1282 | * Determine whether the given permission is allowed for a particular |
| 1283 | * process and user ID running in the system. |
| 1284 | * |
| 1285 | * @param permission The name of the permission being checked. |
| 1286 | * @param pid The process ID being checked against. Must be > 0. |
| 1287 | * @param uid The user ID being checked against. A uid of 0 is the root |
| 1288 | * user, which will pass every permission check. |
| 1289 | * |
| 1290 | * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the given |
| 1291 | * pid/uid is allowed that permission, or |
| 1292 | * {@link PackageManager#PERMISSION_DENIED} if it is not. |
| 1293 | * |
| 1294 | * @see PackageManager#checkPermission(String, String) |
| 1295 | * @see #checkCallingPermission |
| 1296 | */ |
| 1297 | public abstract int checkPermission(String permission, int pid, int uid); |
| 1298 | |
| 1299 | /** |
| 1300 | * Determine whether the calling process of an IPC you are handling has been |
| 1301 | * granted a particular permission. This is basically the same as calling |
| 1302 | * {@link #checkPermission(String, int, int)} with the pid and uid returned |
| 1303 | * by {@link android.os.Binder#getCallingPid} and |
| 1304 | * {@link android.os.Binder#getCallingUid}. One important difference |
| 1305 | * is that if you are not currently processing an IPC, this function |
| 1306 | * will always fail. This is done to protect against accidentally |
| 1307 | * leaking permissions; you can use {@link #checkCallingOrSelfPermission} |
| 1308 | * to avoid this protection. |
| 1309 | * |
| 1310 | * @param permission The name of the permission being checked. |
| 1311 | * |
| 1312 | * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the calling |
| 1313 | * pid/uid is allowed that permission, or |
| 1314 | * {@link PackageManager#PERMISSION_DENIED} if it is not. |
| 1315 | * |
| 1316 | * @see PackageManager#checkPermission(String, String) |
| 1317 | * @see #checkPermission |
| 1318 | * @see #checkCallingOrSelfPermission |
| 1319 | */ |
| 1320 | public abstract int checkCallingPermission(String permission); |
| 1321 | |
| 1322 | /** |
| 1323 | * Determine whether the calling process of an IPC <em>or you</em> have been |
| 1324 | * granted a particular permission. This is the same as |
| 1325 | * {@link #checkCallingPermission}, except it grants your own permissions |
| 1326 | * if you are not currently processing an IPC. Use with care! |
| 1327 | * |
| 1328 | * @param permission The name of the permission being checked. |
| 1329 | * |
| 1330 | * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the calling |
| 1331 | * pid/uid is allowed that permission, or |
| 1332 | * {@link PackageManager#PERMISSION_DENIED} if it is not. |
| 1333 | * |
| 1334 | * @see PackageManager#checkPermission(String, String) |
| 1335 | * @see #checkPermission |
| 1336 | * @see #checkCallingPermission |
| 1337 | */ |
| 1338 | public abstract int checkCallingOrSelfPermission(String permission); |
| 1339 | |
| 1340 | /** |
| 1341 | * If the given permission is not allowed for a particular process |
| 1342 | * and user ID running in the system, throw a {@link SecurityException}. |
| 1343 | * |
| 1344 | * @param permission The name of the permission being checked. |
| 1345 | * @param pid The process ID being checked against. Must be > 0. |
| 1346 | * @param uid The user ID being checked against. A uid of 0 is the root |
| 1347 | * user, which will pass every permission check. |
| 1348 | * @param message A message to include in the exception if it is thrown. |
| 1349 | * |
| 1350 | * @see #checkPermission(String, int, int) |
| 1351 | */ |
| 1352 | public abstract void enforcePermission( |
| 1353 | String permission, int pid, int uid, String message); |
| 1354 | |
| 1355 | /** |
| 1356 | * If the calling process of an IPC you are handling has not been |
| 1357 | * granted a particular permission, throw a {@link |
| 1358 | * SecurityException}. This is basically the same as calling |
| 1359 | * {@link #enforcePermission(String, int, int, String)} with the |
| 1360 | * pid and uid returned by {@link android.os.Binder#getCallingPid} |
| 1361 | * and {@link android.os.Binder#getCallingUid}. One important |
| 1362 | * difference is that if you are not currently processing an IPC, |
| 1363 | * this function will always throw the SecurityException. This is |
| 1364 | * done to protect against accidentally leaking permissions; you |
| 1365 | * can use {@link #enforceCallingOrSelfPermission} to avoid this |
| 1366 | * protection. |
| 1367 | * |
| 1368 | * @param permission The name of the permission being checked. |
| 1369 | * @param message A message to include in the exception if it is thrown. |
| 1370 | * |
| 1371 | * @see #checkCallingPermission(String) |
| 1372 | */ |
| 1373 | public abstract void enforceCallingPermission( |
| 1374 | String permission, String message); |
| 1375 | |
| 1376 | /** |
| 1377 | * If neither you nor the calling process of an IPC you are |
| 1378 | * handling has been granted a particular permission, throw a |
| 1379 | * {@link SecurityException}. This is the same as {@link |
| 1380 | * #enforceCallingPermission}, except it grants your own |
| 1381 | * permissions if you are not currently processing an IPC. Use |
| 1382 | * with care! |
| 1383 | * |
| 1384 | * @param permission The name of the permission being checked. |
| 1385 | * @param message A message to include in the exception if it is thrown. |
| 1386 | * |
| 1387 | * @see #checkCallingOrSelfPermission(String) |
| 1388 | */ |
| 1389 | public abstract void enforceCallingOrSelfPermission( |
| 1390 | String permission, String message); |
| 1391 | |
| 1392 | /** |
| 1393 | * Grant permission to access a specific Uri to another package, regardless |
| 1394 | * of whether that package has general permission to access the Uri's |
| 1395 | * content provider. This can be used to grant specific, temporary |
| 1396 | * permissions, typically in response to user interaction (such as the |
| 1397 | * user opening an attachment that you would like someone else to |
| 1398 | * display). |
| 1399 | * |
| 1400 | * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION |
| 1401 | * Intent.FLAG_GRANT_READ_URI_PERMISSION} or |
| 1402 | * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION |
| 1403 | * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to |
| 1404 | * start an activity instead of this function directly. If you use this |
| 1405 | * function directly, you should be sure to call |
| 1406 | * {@link #revokeUriPermission} when the target should no longer be allowed |
| 1407 | * to access it. |
| 1408 | * |
| 1409 | * <p>To succeed, the content provider owning the Uri must have set the |
| 1410 | * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions |
| 1411 | * grantUriPermissions} attribute in its manifest or included the |
| 1412 | * {@link android.R.styleable#AndroidManifestGrantUriPermission |
| 1413 | * <grant-uri-permissions>} tag. |
| 1414 | * |
| 1415 | * @param toPackage The package you would like to allow to access the Uri. |
| 1416 | * @param uri The Uri you would like to grant access to. |
| 1417 | * @param modeFlags The desired access modes. Any combination of |
| 1418 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION |
| 1419 | * Intent.FLAG_GRANT_READ_URI_PERMISSION} or |
| 1420 | * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION |
| 1421 | * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. |
| 1422 | * |
| 1423 | * @see #revokeUriPermission |
| 1424 | */ |
| 1425 | public abstract void grantUriPermission(String toPackage, Uri uri, |
| 1426 | int modeFlags); |
| 1427 | |
| 1428 | /** |
| 1429 | * Remove all permissions to access a particular content provider Uri |
| 1430 | * that were previously added with {@link #grantUriPermission}. The given |
| 1431 | * Uri will match all previously granted Uris that are the same or a |
| 1432 | * sub-path of the given Uri. That is, revoking "content://foo/one" will |
| 1433 | * revoke both "content://foo/target" and "content://foo/target/sub", but not |
| 1434 | * "content://foo". |
| 1435 | * |
| 1436 | * @param uri The Uri you would like to revoke access to. |
| 1437 | * @param modeFlags The desired access modes. Any combination of |
| 1438 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION |
| 1439 | * Intent.FLAG_GRANT_READ_URI_PERMISSION} or |
| 1440 | * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION |
| 1441 | * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. |
| 1442 | * |
| 1443 | * @see #grantUriPermission |
| 1444 | */ |
| 1445 | public abstract void revokeUriPermission(Uri uri, int modeFlags); |
| 1446 | |
| 1447 | /** |
| 1448 | * Determine whether a particular process and user ID has been granted |
| 1449 | * permission to access a specific URI. This only checks for permissions |
| 1450 | * that have been explicitly granted -- if the given process/uid has |
| 1451 | * more general access to the URI's content provider then this check will |
| 1452 | * always fail. |
| 1453 | * |
| 1454 | * @param uri The uri that is being checked. |
| 1455 | * @param pid The process ID being checked against. Must be > 0. |
| 1456 | * @param uid The user ID being checked against. A uid of 0 is the root |
| 1457 | * user, which will pass every permission check. |
| 1458 | * @param modeFlags The type of access to grant. May be one or both of |
| 1459 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or |
| 1460 | * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. |
| 1461 | * |
| 1462 | * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the given |
| 1463 | * pid/uid is allowed to access that uri, or |
| 1464 | * {@link PackageManager#PERMISSION_DENIED} if it is not. |
| 1465 | * |
| 1466 | * @see #checkCallingUriPermission |
| 1467 | */ |
| 1468 | public abstract int checkUriPermission(Uri uri, int pid, int uid, int modeFlags); |
| 1469 | |
| 1470 | /** |
| 1471 | * Determine whether the calling process and user ID has been |
| 1472 | * granted permission to access a specific URI. This is basically |
| 1473 | * the same as calling {@link #checkUriPermission(Uri, int, int, |
| 1474 | * int)} with the pid and uid returned by {@link |
| 1475 | * android.os.Binder#getCallingPid} and {@link |
| 1476 | * android.os.Binder#getCallingUid}. One important difference is |
| 1477 | * that if you are not currently processing an IPC, this function |
| 1478 | * will always fail. |
| 1479 | * |
| 1480 | * @param uri The uri that is being checked. |
| 1481 | * @param modeFlags The type of access to grant. May be one or both of |
| 1482 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or |
| 1483 | * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. |
| 1484 | * |
| 1485 | * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller |
| 1486 | * is allowed to access that uri, or |
| 1487 | * {@link PackageManager#PERMISSION_DENIED} if it is not. |
| 1488 | * |
| 1489 | * @see #checkUriPermission(Uri, int, int, int) |
| 1490 | */ |
| 1491 | public abstract int checkCallingUriPermission(Uri uri, int modeFlags); |
| 1492 | |
| 1493 | /** |
| 1494 | * Determine whether the calling process of an IPC <em>or you</em> has been granted |
| 1495 | * permission to access a specific URI. This is the same as |
| 1496 | * {@link #checkCallingUriPermission}, except it grants your own permissions |
| 1497 | * if you are not currently processing an IPC. Use with care! |
| 1498 | * |
| 1499 | * @param uri The uri that is being checked. |
| 1500 | * @param modeFlags The type of access to grant. May be one or both of |
| 1501 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or |
| 1502 | * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. |
| 1503 | * |
| 1504 | * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller |
| 1505 | * is allowed to access that uri, or |
| 1506 | * {@link PackageManager#PERMISSION_DENIED} if it is not. |
| 1507 | * |
| 1508 | * @see #checkCallingUriPermission |
| 1509 | */ |
| 1510 | public abstract int checkCallingOrSelfUriPermission(Uri uri, int modeFlags); |
| 1511 | |
| 1512 | /** |
| 1513 | * Check both a Uri and normal permission. This allows you to perform |
| 1514 | * both {@link #checkPermission} and {@link #checkUriPermission} in one |
| 1515 | * call. |
| 1516 | * |
| 1517 | * @param uri The Uri whose permission is to be checked, or null to not |
| 1518 | * do this check. |
| 1519 | * @param readPermission The permission that provides overall read access, |
| 1520 | * or null to not do this check. |
| 1521 | * @param writePermission The permission that provides overall write |
| 1522 | * acess, or null to not do this check. |
| 1523 | * @param pid The process ID being checked against. Must be > 0. |
| 1524 | * @param uid The user ID being checked against. A uid of 0 is the root |
| 1525 | * user, which will pass every permission check. |
| 1526 | * @param modeFlags The type of access to grant. May be one or both of |
| 1527 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or |
| 1528 | * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. |
| 1529 | * |
| 1530 | * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller |
| 1531 | * is allowed to access that uri or holds one of the given permissions, or |
| 1532 | * {@link PackageManager#PERMISSION_DENIED} if it is not. |
| 1533 | */ |
| 1534 | public abstract int checkUriPermission(Uri uri, String readPermission, |
| 1535 | String writePermission, int pid, int uid, int modeFlags); |
| 1536 | |
| 1537 | /** |
| 1538 | * If a particular process and user ID has not been granted |
| 1539 | * permission to access a specific URI, throw {@link |
| 1540 | * SecurityException}. This only checks for permissions that have |
| 1541 | * been explicitly granted -- if the given process/uid has more |
| 1542 | * general access to the URI's content provider then this check |
| 1543 | * will always fail. |
| 1544 | * |
| 1545 | * @param uri The uri that is being checked. |
| 1546 | * @param pid The process ID being checked against. Must be > 0. |
| 1547 | * @param uid The user ID being checked against. A uid of 0 is the root |
| 1548 | * user, which will pass every permission check. |
| 1549 | * @param modeFlags The type of access to grant. May be one or both of |
| 1550 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or |
| 1551 | * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. |
| 1552 | * @param message A message to include in the exception if it is thrown. |
| 1553 | * |
| 1554 | * @see #checkUriPermission(Uri, int, int, int) |
| 1555 | */ |
| 1556 | public abstract void enforceUriPermission( |
| 1557 | Uri uri, int pid, int uid, int modeFlags, String message); |
| 1558 | |
| 1559 | /** |
| 1560 | * If the calling process and user ID has not been granted |
| 1561 | * permission to access a specific URI, throw {@link |
| 1562 | * SecurityException}. This is basically the same as calling |
| 1563 | * {@link #enforceUriPermission(Uri, int, int, int, String)} with |
| 1564 | * the pid and uid returned by {@link |
| 1565 | * android.os.Binder#getCallingPid} and {@link |
| 1566 | * android.os.Binder#getCallingUid}. One important difference is |
| 1567 | * that if you are not currently processing an IPC, this function |
| 1568 | * will always throw a SecurityException. |
| 1569 | * |
| 1570 | * @param uri The uri that is being checked. |
| 1571 | * @param modeFlags The type of access to grant. May be one or both of |
| 1572 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or |
| 1573 | * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. |
| 1574 | * @param message A message to include in the exception if it is thrown. |
| 1575 | * |
| 1576 | * @see #checkCallingUriPermission(Uri, int) |
| 1577 | */ |
| 1578 | public abstract void enforceCallingUriPermission( |
| 1579 | Uri uri, int modeFlags, String message); |
| 1580 | |
| 1581 | /** |
| 1582 | * If the calling process of an IPC <em>or you</em> has not been |
| 1583 | * granted permission to access a specific URI, throw {@link |
| 1584 | * SecurityException}. This is the same as {@link |
| 1585 | * #enforceCallingUriPermission}, except it grants your own |
| 1586 | * permissions if you are not currently processing an IPC. Use |
| 1587 | * with care! |
| 1588 | * |
| 1589 | * @param uri The uri that is being checked. |
| 1590 | * @param modeFlags The type of access to grant. May be one or both of |
| 1591 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or |
| 1592 | * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. |
| 1593 | * @param message A message to include in the exception if it is thrown. |
| 1594 | * |
| 1595 | * @see #checkCallingOrSelfUriPermission(Uri, int) |
| 1596 | */ |
| 1597 | public abstract void enforceCallingOrSelfUriPermission( |
| 1598 | Uri uri, int modeFlags, String message); |
| 1599 | |
| 1600 | /** |
| 1601 | * Enforce both a Uri and normal permission. This allows you to perform |
| 1602 | * both {@link #enforcePermission} and {@link #enforceUriPermission} in one |
| 1603 | * call. |
| 1604 | * |
| 1605 | * @param uri The Uri whose permission is to be checked, or null to not |
| 1606 | * do this check. |
| 1607 | * @param readPermission The permission that provides overall read access, |
| 1608 | * or null to not do this check. |
| 1609 | * @param writePermission The permission that provides overall write |
| 1610 | * acess, or null to not do this check. |
| 1611 | * @param pid The process ID being checked against. Must be > 0. |
| 1612 | * @param uid The user ID being checked against. A uid of 0 is the root |
| 1613 | * user, which will pass every permission check. |
| 1614 | * @param modeFlags The type of access to grant. May be one or both of |
| 1615 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or |
| 1616 | * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}. |
| 1617 | * @param message A message to include in the exception if it is thrown. |
| 1618 | * |
| 1619 | * @see #checkUriPermission(Uri, String, String, int, int, int) |
| 1620 | */ |
| 1621 | public abstract void enforceUriPermission( |
| 1622 | Uri uri, String readPermission, String writePermission, |
| 1623 | int pid, int uid, int modeFlags, String message); |
| 1624 | |
| 1625 | /** |
| 1626 | * Flag for use with {@link #createPackageContext}: include the application |
| 1627 | * code with the context. This means loading code into the caller's |
| 1628 | * process, so that {@link #getClassLoader()} can be used to instantiate |
| 1629 | * the application's classes. Setting this flags imposes security |
| 1630 | * restrictions on what application context you can access; if the |
| 1631 | * requested application can not be safely loaded into your process, |
| 1632 | * java.lang.SecurityException will be thrown. If this flag is not set, |
| 1633 | * there will be no restrictions on the packages that can be loaded, |
| 1634 | * but {@link #getClassLoader} will always return the default system |
| 1635 | * class loader. |
| 1636 | */ |
| 1637 | public static final int CONTEXT_INCLUDE_CODE = 0x00000001; |
| 1638 | |
| 1639 | /** |
| 1640 | * Flag for use with {@link #createPackageContext}: ignore any security |
| 1641 | * restrictions on the Context being requested, allowing it to always |
| 1642 | * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code |
| 1643 | * to be loaded into a process even when it isn't safe to do so. Use |
| 1644 | * with extreme care! |
| 1645 | */ |
| 1646 | public static final int CONTEXT_IGNORE_SECURITY = 0x00000002; |
| 1647 | |
| 1648 | /** |
| 1649 | * Return a new Context object for the given application name. This |
| 1650 | * Context is the same as what the named application gets when it is |
| 1651 | * launched, containing the same resources and class loader. Each call to |
| 1652 | * this method returns a new instance of a Context object; Context objects |
| 1653 | * are not shared, however they share common state (Resources, ClassLoader, |
| 1654 | * etc) so the Context instance itself is fairly lightweight. |
| 1655 | * |
| 1656 | * <p>Throws {@link PackageManager.NameNotFoundException} if there is no |
| 1657 | * application with the given package name. |
| 1658 | * |
| 1659 | * <p>Throws {@link java.lang.SecurityException} if the Context requested |
| 1660 | * can not be loaded into the caller's process for security reasons (see |
| 1661 | * {@link #CONTEXT_INCLUDE_CODE} for more information}. |
| 1662 | * |
| 1663 | * @param packageName Name of the application's package. |
| 1664 | * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE} |
| 1665 | * or {@link #CONTEXT_IGNORE_SECURITY}. |
| 1666 | * |
| 1667 | * @return A Context for the application. |
| 1668 | * |
| 1669 | * @throws java.lang.SecurityException |
| 1670 | * @throws PackageManager.NameNotFoundException if there is no application with |
| 1671 | * the given package name |
| 1672 | */ |
| 1673 | public abstract Context createPackageContext(String packageName, |
| 1674 | int flags) throws PackageManager.NameNotFoundException; |
| 1675 | } |