1 /* 2 * Copyright (C) 2008 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.provider; 18 19 import android.net.Uri; 20 import android.content.ContentUris; 21 import android.content.ContentValues; 22 import android.content.Context; 23 24 import java.io.File; 25 26 /** 27 * The Download Manager 28 * 29 * @pending 30 */ 31 public final class Downloads { 32 /** 33 * @hide 34 */ 35 private Downloads() {} 36 37 /** 38 * The permission to access the download manager 39 * @hide 40 */ 41 public static final String PERMISSION_ACCESS = "android.permission.ACCESS_DOWNLOAD_MANAGER"; 42 43 /** 44 * The permission to access the download manager's advanced functions 45 * @hide 46 */ 47 public static final String PERMISSION_ACCESS_ADVANCED = 48 "android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED"; 49 50 /** 51 * The permission to directly access the download manager's cache directory 52 * @hide 53 */ 54 public static final String PERMISSION_CACHE = "android.permission.ACCESS_CACHE_FILESYSTEM"; 55 56 /** 57 * The permission to send broadcasts on download completion 58 * @hide 59 */ 60 public static final String PERMISSION_SEND_INTENTS = 61 "android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS"; 62 63 /** 64 * The content:// URI for the data table in the provider 65 * @hide 66 */ 67 public static final Uri CONTENT_URI = 68 Uri.parse("content://downloads/download"); 69 70 /** 71 * Broadcast Action: this is sent by the download manager to the app 72 * that had initiated a download when that download completes. The 73 * download's content: uri is specified in the intent's data. 74 * @hide 75 */ 76 public static final String ACTION_DOWNLOAD_COMPLETED = 77 "android.intent.action.DOWNLOAD_COMPLETED"; 78 79 /** 80 * Broadcast Action: this is sent by the download manager to the app 81 * that had initiated a download when the user selects the notification 82 * associated with that download. The download's content: uri is specified 83 * in the intent's data if the click is associated with a single download, 84 * or Downloads.CONTENT_URI if the notification is associated with 85 * multiple downloads. 86 * Note: this is not currently sent for downloads that have completed 87 * successfully. 88 * @hide 89 */ 90 public static final String ACTION_NOTIFICATION_CLICKED = 91 "android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED"; 92 93 /** 94 * The name of the column containing the URI of the data being downloaded. 95 * <P>Type: TEXT</P> 96 * <P>Owner can Init/Read</P> 97 * @hide 98 */ 99 public static final String COLUMN_URI = "uri"; 100 101 /** 102 * The name of the column containing application-specific data. 103 * <P>Type: TEXT</P> 104 * <P>Owner can Init/Read/Write</P> 105 * @hide 106 */ 107 public static final String COLUMN_APP_DATA = "entity"; 108 109 /** 110 * The name of the column containing the flags that indicates whether 111 * the initiating application is capable of verifying the integrity of 112 * the downloaded file. When this flag is set, the download manager 113 * performs downloads and reports success even in some situations where 114 * it can't guarantee that the download has completed (e.g. when doing 115 * a byte-range request without an ETag, or when it can't determine 116 * whether a download fully completed). 117 * <P>Type: BOOLEAN</P> 118 * <P>Owner can Init</P> 119 * @hide 120 */ 121 public static final String COLUMN_NO_INTEGRITY = "no_integrity"; 122 123 /** 124 * The name of the column containing the filename that the initiating 125 * application recommends. When possible, the download manager will attempt 126 * to use this filename, or a variation, as the actual name for the file. 127 * <P>Type: TEXT</P> 128 * <P>Owner can Init</P> 129 * @hide 130 */ 131 public static final String COLUMN_FILE_NAME_HINT = "hint"; 132 133 /** 134 * The name of the column containing the filename where the downloaded data 135 * was actually stored. 136 * <P>Type: TEXT</P> 137 * <P>Owner can Read</P> 138 * @hide 139 */ 140 public static final String _DATA = "_data"; 141 142 /** 143 * The name of the column containing the MIME type of the downloaded data. 144 * <P>Type: TEXT</P> 145 * <P>Owner can Init/Read</P> 146 * @hide 147 */ 148 public static final String COLUMN_MIME_TYPE = "mimetype"; 149 150 /** 151 * The name of the column containing the flag that controls the destination 152 * of the download. See the DESTINATION_* constants for a list of legal values. 153 * <P>Type: INTEGER</P> 154 * <P>Owner can Init</P> 155 * @hide 156 */ 157 public static final String COLUMN_DESTINATION = "destination"; 158 159 /** 160 * The name of the column containing the flags that controls whether the 161 * download is displayed by the UI. See the VISIBILITY_* constants for 162 * a list of legal values. 163 * <P>Type: INTEGER</P> 164 * <P>Owner can Init/Read/Write</P> 165 * @hide 166 */ 167 public static final String COLUMN_VISIBILITY = "visibility"; 168 169 /** 170 * The name of the column containing the current control state of the download. 171 * Applications can write to this to control (pause/resume) the download. 172 * the CONTROL_* constants for a list of legal values. 173 * <P>Type: INTEGER</P> 174 * <P>Owner can Read</P> 175 * @hide 176 */ 177 public static final String COLUMN_CONTROL = "control"; 178 179 /** 180 * The name of the column containing the current status of the download. 181 * Applications can read this to follow the progress of each download. See 182 * the STATUS_* constants for a list of legal values. 183 * <P>Type: INTEGER</P> 184 * <P>Owner can Read</P> 185 * @hide 186 */ 187 public static final String COLUMN_STATUS = "status"; 188 189 /** 190 * The name of the column containing the date at which some interesting 191 * status changed in the download. Stored as a System.currentTimeMillis() 192 * value. 193 * <P>Type: BIGINT</P> 194 * <P>Owner can Read</P> 195 * @hide 196 */ 197 public static final String COLUMN_LAST_MODIFICATION = "lastmod"; 198 199 /** 200 * The name of the column containing the package name of the application 201 * that initiating the download. The download manager will send 202 * notifications to a component in this package when the download completes. 203 * <P>Type: TEXT</P> 204 * <P>Owner can Init/Read</P> 205 * @hide 206 */ 207 public static final String COLUMN_NOTIFICATION_PACKAGE = "notificationpackage"; 208 209 /** 210 * The name of the column containing the component name of the class that 211 * will receive notifications associated with the download. The 212 * package/class combination is passed to 213 * Intent.setClassName(String,String). 214 * <P>Type: TEXT</P> 215 * <P>Owner can Init/Read</P> 216 * @hide 217 */ 218 public static final String COLUMN_NOTIFICATION_CLASS = "notificationclass"; 219 220 /** 221 * If extras are specified when requesting a download they will be provided in the intent that 222 * is sent to the specified class and package when a download has finished. 223 * <P>Type: TEXT</P> 224 * <P>Owner can Init</P> 225 * @hide 226 */ 227 public static final String COLUMN_NOTIFICATION_EXTRAS = "notificationextras"; 228 229 /** 230 * The name of the column contain the values of the cookie to be used for 231 * the download. This is used directly as the value for the Cookie: HTTP 232 * header that gets sent with the request. 233 * <P>Type: TEXT</P> 234 * <P>Owner can Init</P> 235 * @hide 236 */ 237 public static final String COLUMN_COOKIE_DATA = "cookiedata"; 238 239 /** 240 * The name of the column containing the user agent that the initiating 241 * application wants the download manager to use for this download. 242 * <P>Type: TEXT</P> 243 * <P>Owner can Init</P> 244 * @hide 245 */ 246 public static final String COLUMN_USER_AGENT = "useragent"; 247 248 /** 249 * The name of the column containing the referer (sic) that the initiating 250 * application wants the download manager to use for this download. 251 * <P>Type: TEXT</P> 252 * <P>Owner can Init</P> 253 * @hide 254 */ 255 public static final String COLUMN_REFERER = "referer"; 256 257 /** 258 * The name of the column containing the total size of the file being 259 * downloaded. 260 * <P>Type: INTEGER</P> 261 * <P>Owner can Read</P> 262 * @hide 263 */ 264 public static final String COLUMN_TOTAL_BYTES = "total_bytes"; 265 266 /** 267 * The name of the column containing the size of the part of the file that 268 * has been downloaded so far. 269 * <P>Type: INTEGER</P> 270 * <P>Owner can Read</P> 271 * @hide 272 */ 273 public static final String COLUMN_CURRENT_BYTES = "current_bytes"; 274 275 /** 276 * The name of the column where the initiating application can provide the 277 * UID of another application that is allowed to access this download. If 278 * multiple applications share the same UID, all those applications will be 279 * allowed to access this download. This column can be updated after the 280 * download is initiated. This requires the permission 281 * android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED. 282 * <P>Type: INTEGER</P> 283 * <P>Owner can Init</P> 284 * @hide 285 */ 286 public static final String COLUMN_OTHER_UID = "otheruid"; 287 288 /** 289 * The name of the column where the initiating application can provided the 290 * title of this download. The title will be displayed ito the user in the 291 * list of downloads. 292 * <P>Type: TEXT</P> 293 * <P>Owner can Init/Read/Write</P> 294 * @hide 295 */ 296 public static final String COLUMN_TITLE = "title"; 297 298 /** 299 * The name of the column where the initiating application can provide the 300 * description of this download. The description will be displayed to the 301 * user in the list of downloads. 302 * <P>Type: TEXT</P> 303 * <P>Owner can Init/Read/Write</P> 304 * @hide 305 */ 306 public static final String COLUMN_DESCRIPTION = "description"; 307 308 /* 309 * Lists the destinations that an application can specify for a download. 310 */ 311 312 /** 313 * This download will be saved to the external storage. This is the 314 * default behavior, and should be used for any file that the user 315 * can freely access, copy, delete. Even with that destination, 316 * unencrypted DRM files are saved in secure internal storage. 317 * Downloads to the external destination only write files for which 318 * there is a registered handler. The resulting files are accessible 319 * by filename to all applications. 320 * @hide 321 */ 322 public static final int DESTINATION_EXTERNAL = 0; 323 324 /** 325 * This download will be saved to the download manager's private 326 * partition. This is the behavior used by applications that want to 327 * download private files that are used and deleted soon after they 328 * get downloaded. All file types are allowed, and only the initiating 329 * application can access the file (indirectly through a content 330 * provider). This requires the 331 * android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED permission. 332 * @hide 333 */ 334 public static final int DESTINATION_CACHE_PARTITION = 1; 335 336 /** 337 * This download will be saved to the download manager's private 338 * partition and will be purged as necessary to make space. This is 339 * for private files (similar to CACHE_PARTITION) that aren't deleted 340 * immediately after they are used, and are kept around by the download 341 * manager as long as space is available. 342 * @hide 343 */ 344 public static final int DESTINATION_CACHE_PARTITION_PURGEABLE = 2; 345 346 /** 347 * This download will be saved to the download manager's private 348 * partition, as with DESTINATION_CACHE_PARTITION, but the download 349 * will not proceed if the user is on a roaming data connection. 350 * @hide 351 */ 352 public static final int DESTINATION_CACHE_PARTITION_NOROAMING = 3; 353 354 /** 355 * This download is allowed to run. 356 * @hide 357 */ 358 public static final int CONTROL_RUN = 0; 359 360 /** 361 * This download must pause at the first opportunity. 362 * @hide 363 */ 364 public static final int CONTROL_PAUSED = 1; 365 366 /* 367 * Lists the states that the download manager can set on a download 368 * to notify applications of the download progress. 369 * The codes follow the HTTP families:<br> 370 * 1xx: informational<br> 371 * 2xx: success<br> 372 * 3xx: redirects (not used by the download manager)<br> 373 * 4xx: client errors<br> 374 * 5xx: server errors 375 */ 376 377 /** 378 * Returns whether the status is informational (i.e. 1xx). 379 * @hide 380 */ 381 public static boolean isStatusInformational(int status) { 382 return (status >= 100 && status < 200); 383 } 384 385 /** 386 * Returns whether the download is suspended. (i.e. whether the download 387 * won't complete without some action from outside the download 388 * manager). 389 * @hide 390 */ 391 public static boolean isStatusSuspended(int status) { 392 return (status == STATUS_PENDING_PAUSED || status == STATUS_RUNNING_PAUSED); 393 } 394 395 /** 396 * Returns whether the status is a success (i.e. 2xx). 397 * @hide 398 */ 399 public static boolean isStatusSuccess(int status) { 400 return (status >= 200 && status < 300); 401 } 402 403 /** 404 * Returns whether the status is an error (i.e. 4xx or 5xx). 405 * @hide 406 */ 407 public static boolean isStatusError(int status) { 408 return (status >= 400 && status < 600); 409 } 410 411 /** 412 * Returns whether the status is a client error (i.e. 4xx). 413 * @hide 414 */ 415 public static boolean isStatusClientError(int status) { 416 return (status >= 400 && status < 500); 417 } 418 419 /** 420 * Returns whether the status is a server error (i.e. 5xx). 421 * @hide 422 */ 423 public static boolean isStatusServerError(int status) { 424 return (status >= 500 && status < 600); 425 } 426 427 /** 428 * Returns whether the download has completed (either with success or 429 * error). 430 * @hide 431 */ 432 public static boolean isStatusCompleted(int status) { 433 return (status >= 200 && status < 300) || (status >= 400 && status < 600); 434 } 435 436 /** 437 * This download hasn't stated yet 438 * @hide 439 */ 440 public static final int STATUS_PENDING = 190; 441 442 /** 443 * This download hasn't stated yet and is paused 444 * @hide 445 */ 446 public static final int STATUS_PENDING_PAUSED = 191; 447 448 /** 449 * This download has started 450 * @hide 451 */ 452 public static final int STATUS_RUNNING = 192; 453 454 /** 455 * This download has started and is paused 456 * @hide 457 */ 458 public static final int STATUS_RUNNING_PAUSED = 193; 459 460 /** 461 * This download has successfully completed. 462 * Warning: there might be other status values that indicate success 463 * in the future. 464 * Use isSucccess() to capture the entire category. 465 * @hide 466 */ 467 public static final int STATUS_SUCCESS = 200; 468 469 /** 470 * This request couldn't be parsed. This is also used when processing 471 * requests with unknown/unsupported URI schemes. 472 * @hide 473 */ 474 public static final int STATUS_BAD_REQUEST = 400; 475 476 /** 477 * This download can't be performed because the content type cannot be 478 * handled. 479 * @hide 480 */ 481 public static final int STATUS_NOT_ACCEPTABLE = 406; 482 483 /** 484 * This download cannot be performed because the length cannot be 485 * determined accurately. This is the code for the HTTP error "Length 486 * Required", which is typically used when making requests that require 487 * a content length but don't have one, and it is also used in the 488 * client when a response is received whose length cannot be determined 489 * accurately (therefore making it impossible to know when a download 490 * completes). 491 * @hide 492 */ 493 public static final int STATUS_LENGTH_REQUIRED = 411; 494 495 /** 496 * This download was interrupted and cannot be resumed. 497 * This is the code for the HTTP error "Precondition Failed", and it is 498 * also used in situations where the client doesn't have an ETag at all. 499 * @hide 500 */ 501 public static final int STATUS_PRECONDITION_FAILED = 412; 502 503 /** 504 * This download was canceled 505 * @hide 506 */ 507 public static final int STATUS_CANCELED = 490; 508 509 /** 510 * This download has completed with an error. 511 * Warning: there will be other status values that indicate errors in 512 * the future. Use isStatusError() to capture the entire category. 513 * @hide 514 */ 515 public static final int STATUS_UNKNOWN_ERROR = 491; 516 517 /** 518 * This download couldn't be completed because of a storage issue. 519 * Typically, that's because the filesystem is missing or full. 520 * Use the more specific {@link #STATUS_INSUFFICIENT_SPACE_ERROR} 521 * and {@link #STATUS_DEVICE_NOT_FOUND_ERROR} when appropriate. 522 * @hide 523 */ 524 public static final int STATUS_FILE_ERROR = 492; 525 526 /** 527 * This download couldn't be completed because of an HTTP 528 * redirect response that the download manager couldn't 529 * handle. 530 * @hide 531 */ 532 public static final int STATUS_UNHANDLED_REDIRECT = 493; 533 534 /** 535 * This download couldn't be completed because of an 536 * unspecified unhandled HTTP code. 537 * @hide 538 */ 539 public static final int STATUS_UNHANDLED_HTTP_CODE = 494; 540 541 /** 542 * This download couldn't be completed because of an 543 * error receiving or processing data at the HTTP level. 544 * @hide 545 */ 546 public static final int STATUS_HTTP_DATA_ERROR = 495; 547 548 /** 549 * This download couldn't be completed because of an 550 * HttpException while setting up the request. 551 * @hide 552 */ 553 public static final int STATUS_HTTP_EXCEPTION = 496; 554 555 /** 556 * This download couldn't be completed because there were 557 * too many redirects. 558 * @hide 559 */ 560 public static final int STATUS_TOO_MANY_REDIRECTS = 497; 561 562 /** 563 * This download couldn't be completed due to insufficient storage 564 * space. Typically, this is because the SD card is full. 565 * @hide 566 */ 567 public static final int STATUS_INSUFFICIENT_SPACE_ERROR = 498; 568 569 /** 570 * This download couldn't be completed because no external storage 571 * device was found. Typically, this is because the SD card is not 572 * mounted. 573 * @hide 574 */ 575 public static final int STATUS_DEVICE_NOT_FOUND_ERROR = 499; 576 577 /** 578 * This download is visible but only shows in the notifications 579 * while it's in progress. 580 * @hide 581 */ 582 public static final int VISIBILITY_VISIBLE = 0; 583 584 /** 585 * This download is visible and shows in the notifications while 586 * in progress and after completion. 587 * @hide 588 */ 589 public static final int VISIBILITY_VISIBLE_NOTIFY_COMPLETED = 1; 590 591 /** 592 * This download doesn't show in the UI or in the notifications. 593 * @hide 594 */ 595 public static final int VISIBILITY_HIDDEN = 2; 596 597 /** 598 * Implementation details 599 * 600 * Exposes constants used to interact with the download manager's 601 * content provider. 602 * The constants URI ... STATUS are the names of columns in the downloads table. 603 * 604 * @hide 605 */ 606 public static final class Impl implements BaseColumns { 607 private Impl() {} 608 609 /** 610 * The permission to access the download manager 611 */ 612 public static final String PERMISSION_ACCESS = "android.permission.ACCESS_DOWNLOAD_MANAGER"; 613 614 /** 615 * The permission to access the download manager's advanced functions 616 */ 617 public static final String PERMISSION_ACCESS_ADVANCED = 618 "android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED"; 619 620 /** 621 * The permission to directly access the download manager's cache directory 622 */ 623 public static final String PERMISSION_CACHE = "android.permission.ACCESS_CACHE_FILESYSTEM"; 624 625 /** 626 * The permission to send broadcasts on download completion 627 */ 628 public static final String PERMISSION_SEND_INTENTS = 629 "android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS"; 630 631 /** 632 * The permission to access downloads to {@link DESTINATION_EXTERNAL} 633 * which were downloaded by other applications. 634 * @hide 635 */ 636 public static final String PERMISSION_SEE_ALL_EXTERNAL = 637 "android.permission.SEE_ALL_EXTERNAL"; 638 639 /** 640 * The content:// URI for the data table in the provider 641 */ 642 public static final Uri CONTENT_URI = 643 Uri.parse("content://downloads/download"); 644 645 /** 646 * Broadcast Action: this is sent by the download manager to the app 647 * that had initiated a download when that download completes. The 648 * download's content: uri is specified in the intent's data. 649 */ 650 public static final String ACTION_DOWNLOAD_COMPLETED = 651 "android.intent.action.DOWNLOAD_COMPLETED"; 652 653 /** 654 * Broadcast Action: this is sent by the download manager to the app 655 * that had initiated a download when the user selects the notification 656 * associated with that download. The download's content: uri is specified 657 * in the intent's data if the click is associated with a single download, 658 * or Downloads.CONTENT_URI if the notification is associated with 659 * multiple downloads. 660 * Note: this is not currently sent for downloads that have completed 661 * successfully. 662 */ 663 public static final String ACTION_NOTIFICATION_CLICKED = 664 "android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED"; 665 666 /** 667 * The name of the column containing the URI of the data being downloaded. 668 * <P>Type: TEXT</P> 669 * <P>Owner can Init/Read</P> 670 */ 671 public static final String COLUMN_URI = "uri"; 672 673 /** 674 * The name of the column containing application-specific data. 675 * <P>Type: TEXT</P> 676 * <P>Owner can Init/Read/Write</P> 677 */ 678 public static final String COLUMN_APP_DATA = "entity"; 679 680 /** 681 * The name of the column containing the flags that indicates whether 682 * the initiating application is capable of verifying the integrity of 683 * the downloaded file. When this flag is set, the download manager 684 * performs downloads and reports success even in some situations where 685 * it can't guarantee that the download has completed (e.g. when doing 686 * a byte-range request without an ETag, or when it can't determine 687 * whether a download fully completed). 688 * <P>Type: BOOLEAN</P> 689 * <P>Owner can Init</P> 690 */ 691 public static final String COLUMN_NO_INTEGRITY = "no_integrity"; 692 693 /** 694 * The name of the column containing the filename that the initiating 695 * application recommends. When possible, the download manager will attempt 696 * to use this filename, or a variation, as the actual name for the file. 697 * <P>Type: TEXT</P> 698 * <P>Owner can Init</P> 699 */ 700 public static final String COLUMN_FILE_NAME_HINT = "hint"; 701 702 /** 703 * The name of the column containing the filename where the downloaded data 704 * was actually stored. 705 * <P>Type: TEXT</P> 706 * <P>Owner can Read</P> 707 */ 708 public static final String _DATA = "_data"; 709 710 /** 711 * The name of the column containing the MIME type of the downloaded data. 712 * <P>Type: TEXT</P> 713 * <P>Owner can Init/Read</P> 714 */ 715 public static final String COLUMN_MIME_TYPE = "mimetype"; 716 717 /** 718 * The name of the column containing the flag that controls the destination 719 * of the download. See the DESTINATION_* constants for a list of legal values. 720 * <P>Type: INTEGER</P> 721 * <P>Owner can Init</P> 722 */ 723 public static final String COLUMN_DESTINATION = "destination"; 724 725 /** 726 * The name of the column containing the flags that controls whether the 727 * download is displayed by the UI. See the VISIBILITY_* constants for 728 * a list of legal values. 729 * <P>Type: INTEGER</P> 730 * <P>Owner can Init/Read/Write</P> 731 */ 732 public static final String COLUMN_VISIBILITY = "visibility"; 733 734 /** 735 * The name of the column containing the current control state of the download. 736 * Applications can write to this to control (pause/resume) the download. 737 * the CONTROL_* constants for a list of legal values. 738 * <P>Type: INTEGER</P> 739 * <P>Owner can Read</P> 740 */ 741 public static final String COLUMN_CONTROL = "control"; 742 743 /** 744 * The name of the column containing the current status of the download. 745 * Applications can read this to follow the progress of each download. See 746 * the STATUS_* constants for a list of legal values. 747 * <P>Type: INTEGER</P> 748 * <P>Owner can Read</P> 749 */ 750 public static final String COLUMN_STATUS = "status"; 751 752 /** 753 * The name of the column containing the date at which some interesting 754 * status changed in the download. Stored as a System.currentTimeMillis() 755 * value. 756 * <P>Type: BIGINT</P> 757 * <P>Owner can Read</P> 758 */ 759 public static final String COLUMN_LAST_MODIFICATION = "lastmod"; 760 761 /** 762 * The name of the column containing the package name of the application 763 * that initiating the download. The download manager will send 764 * notifications to a component in this package when the download completes. 765 * <P>Type: TEXT</P> 766 * <P>Owner can Init/Read</P> 767 */ 768 public static final String COLUMN_NOTIFICATION_PACKAGE = "notificationpackage"; 769 770 /** 771 * The name of the column containing the component name of the class that 772 * will receive notifications associated with the download. The 773 * package/class combination is passed to 774 * Intent.setClassName(String,String). 775 * <P>Type: TEXT</P> 776 * <P>Owner can Init/Read</P> 777 */ 778 public static final String COLUMN_NOTIFICATION_CLASS = "notificationclass"; 779 780 /** 781 * If extras are specified when requesting a download they will be provided in the intent that 782 * is sent to the specified class and package when a download has finished. 783 * <P>Type: TEXT</P> 784 * <P>Owner can Init</P> 785 */ 786 public static final String COLUMN_NOTIFICATION_EXTRAS = "notificationextras"; 787 788 /** 789 * The name of the column contain the values of the cookie to be used for 790 * the download. This is used directly as the value for the Cookie: HTTP 791 * header that gets sent with the request. 792 * <P>Type: TEXT</P> 793 * <P>Owner can Init</P> 794 */ 795 public static final String COLUMN_COOKIE_DATA = "cookiedata"; 796 797 /** 798 * The name of the column containing the user agent that the initiating 799 * application wants the download manager to use for this download. 800 * <P>Type: TEXT</P> 801 * <P>Owner can Init</P> 802 */ 803 public static final String COLUMN_USER_AGENT = "useragent"; 804 805 /** 806 * The name of the column containing the referer (sic) that the initiating 807 * application wants the download manager to use for this download. 808 * <P>Type: TEXT</P> 809 * <P>Owner can Init</P> 810 */ 811 public static final String COLUMN_REFERER = "referer"; 812 813 /** 814 * The name of the column containing the total size of the file being 815 * downloaded. 816 * <P>Type: INTEGER</P> 817 * <P>Owner can Read</P> 818 */ 819 public static final String COLUMN_TOTAL_BYTES = "total_bytes"; 820 821 /** 822 * The name of the column containing the size of the part of the file that 823 * has been downloaded so far. 824 * <P>Type: INTEGER</P> 825 * <P>Owner can Read</P> 826 */ 827 public static final String COLUMN_CURRENT_BYTES = "current_bytes"; 828 829 /** 830 * The name of the column where the initiating application can provide the 831 * UID of another application that is allowed to access this download. If 832 * multiple applications share the same UID, all those applications will be 833 * allowed to access this download. This column can be updated after the 834 * download is initiated. This requires the permission 835 * android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED. 836 * <P>Type: INTEGER</P> 837 * <P>Owner can Init</P> 838 */ 839 public static final String COLUMN_OTHER_UID = "otheruid"; 840 841 /** 842 * The name of the column where the initiating application can provided the 843 * title of this download. The title will be displayed ito the user in the 844 * list of downloads. 845 * <P>Type: TEXT</P> 846 * <P>Owner can Init/Read/Write</P> 847 */ 848 public static final String COLUMN_TITLE = "title"; 849 850 /** 851 * The name of the column where the initiating application can provide the 852 * description of this download. The description will be displayed to the 853 * user in the list of downloads. 854 * <P>Type: TEXT</P> 855 * <P>Owner can Init/Read/Write</P> 856 */ 857 public static final String COLUMN_DESCRIPTION = "description"; 858 859 /* 860 * Lists the destinations that an application can specify for a download. 861 */ 862 863 /** 864 * This download will be saved to the external storage. This is the 865 * default behavior, and should be used for any file that the user 866 * can freely access, copy, delete. Even with that destination, 867 * unencrypted DRM files are saved in secure internal storage. 868 * Downloads to the external destination only write files for which 869 * there is a registered handler. The resulting files are accessible 870 * by filename to all applications. 871 */ 872 public static final int DESTINATION_EXTERNAL = 0; 873 874 /** 875 * This download will be saved to the download manager's private 876 * partition. This is the behavior used by applications that want to 877 * download private files that are used and deleted soon after they 878 * get downloaded. All file types are allowed, and only the initiating 879 * application can access the file (indirectly through a content 880 * provider). This requires the 881 * android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED permission. 882 */ 883 public static final int DESTINATION_CACHE_PARTITION = 1; 884 885 /** 886 * This download will be saved to the download manager's private 887 * partition and will be purged as necessary to make space. This is 888 * for private files (similar to CACHE_PARTITION) that aren't deleted 889 * immediately after they are used, and are kept around by the download 890 * manager as long as space is available. 891 */ 892 public static final int DESTINATION_CACHE_PARTITION_PURGEABLE = 2; 893 894 /** 895 * This download will be saved to the download manager's private 896 * partition, as with DESTINATION_CACHE_PARTITION, but the download 897 * will not proceed if the user is on a roaming data connection. 898 */ 899 public static final int DESTINATION_CACHE_PARTITION_NOROAMING = 3; 900 901 /** 902 * This download is allowed to run. 903 */ 904 public static final int CONTROL_RUN = 0; 905 906 /** 907 * This download must pause at the first opportunity. 908 */ 909 public static final int CONTROL_PAUSED = 1; 910 911 /* 912 * Lists the states that the download manager can set on a download 913 * to notify applications of the download progress. 914 * The codes follow the HTTP families:<br> 915 * 1xx: informational<br> 916 * 2xx: success<br> 917 * 3xx: redirects (not used by the download manager)<br> 918 * 4xx: client errors<br> 919 * 5xx: server errors 920 */ 921 922 /** 923 * Returns whether the status is informational (i.e. 1xx). 924 */ 925 public static boolean isStatusInformational(int status) { 926 return (status >= 100 && status < 200); 927 } 928 929 /** 930 * Returns whether the download is suspended. (i.e. whether the download 931 * won't complete without some action from outside the download 932 * manager). 933 */ 934 public static boolean isStatusSuspended(int status) { 935 return (status == STATUS_PENDING_PAUSED || status == STATUS_RUNNING_PAUSED); 936 } 937 938 /** 939 * Returns whether the status is a success (i.e. 2xx). 940 */ 941 public static boolean isStatusSuccess(int status) { 942 return (status >= 200 && status < 300); 943 } 944 945 /** 946 * Returns whether the status is an error (i.e. 4xx or 5xx). 947 */ 948 public static boolean isStatusError(int status) { 949 return (status >= 400 && status < 600); 950 } 951 952 /** 953 * Returns whether the status is a client error (i.e. 4xx). 954 */ 955 public static boolean isStatusClientError(int status) { 956 return (status >= 400 && status < 500); 957 } 958 959 /** 960 * Returns whether the status is a server error (i.e. 5xx). 961 */ 962 public static boolean isStatusServerError(int status) { 963 return (status >= 500 && status < 600); 964 } 965 966 /** 967 * Returns whether the download has completed (either with success or 968 * error). 969 */ 970 public static boolean isStatusCompleted(int status) { 971 return (status >= 200 && status < 300) || (status >= 400 && status < 600); 972 } 973 974 /** 975 * This download hasn't stated yet 976 */ 977 public static final int STATUS_PENDING = 190; 978 979 /** 980 * This download hasn't stated yet and is paused 981 */ 982 public static final int STATUS_PENDING_PAUSED = 191; 983 984 /** 985 * This download has started 986 */ 987 public static final int STATUS_RUNNING = 192; 988 989 /** 990 * This download has started and is paused 991 */ 992 public static final int STATUS_RUNNING_PAUSED = 193; 993 994 /** 995 * This download has successfully completed. 996 * Warning: there might be other status values that indicate success 997 * in the future. 998 * Use isSucccess() to capture the entire category. 999 */ 1000 public static final int STATUS_SUCCESS = 200; 1001 1002 /** 1003 * This request couldn't be parsed. This is also used when processing 1004 * requests with unknown/unsupported URI schemes. 1005 */ 1006 public static final int STATUS_BAD_REQUEST = 400; 1007 1008 /** 1009 * This download can't be performed because the content type cannot be 1010 * handled. 1011 */ 1012 public static final int STATUS_NOT_ACCEPTABLE = 406; 1013 1014 /** 1015 * This download cannot be performed because the length cannot be 1016 * determined accurately. This is the code for the HTTP error "Length 1017 * Required", which is typically used when making requests that require 1018 * a content length but don't have one, and it is also used in the 1019 * client when a response is received whose length cannot be determined 1020 * accurately (therefore making it impossible to know when a download 1021 * completes). 1022 */ 1023 public static final int STATUS_LENGTH_REQUIRED = 411; 1024 1025 /** 1026 * This download was interrupted and cannot be resumed. 1027 * This is the code for the HTTP error "Precondition Failed", and it is 1028 * also used in situations where the client doesn't have an ETag at all. 1029 */ 1030 public static final int STATUS_PRECONDITION_FAILED = 412; 1031 1032 /** 1033 * This download was canceled 1034 */ 1035 public static final int STATUS_CANCELED = 490; 1036 1037 /** 1038 * This download has completed with an error. 1039 * Warning: there will be other status values that indicate errors in 1040 * the future. Use isStatusError() to capture the entire category. 1041 */ 1042 public static final int STATUS_UNKNOWN_ERROR = 491; 1043 1044 /** 1045 * This download couldn't be completed because of a storage issue. 1046 * Typically, that's because the filesystem is missing or full. 1047 * Use the more specific {@link #STATUS_INSUFFICIENT_SPACE_ERROR} 1048 * and {@link #STATUS_DEVICE_NOT_FOUND_ERROR} when appropriate. 1049 */ 1050 public static final int STATUS_FILE_ERROR = 492; 1051 1052 /** 1053 * This download couldn't be completed because of an HTTP 1054 * redirect response that the download manager couldn't 1055 * handle. 1056 */ 1057 public static final int STATUS_UNHANDLED_REDIRECT = 493; 1058 1059 /** 1060 * This download couldn't be completed because of an 1061 * unspecified unhandled HTTP code. 1062 */ 1063 public static final int STATUS_UNHANDLED_HTTP_CODE = 494; 1064 1065 /** 1066 * This download couldn't be completed because of an 1067 * error receiving or processing data at the HTTP level. 1068 */ 1069 public static final int STATUS_HTTP_DATA_ERROR = 495; 1070 1071 /** 1072 * This download couldn't be completed because of an 1073 * HttpException while setting up the request. 1074 */ 1075 public static final int STATUS_HTTP_EXCEPTION = 496; 1076 1077 /** 1078 * This download couldn't be completed because there were 1079 * too many redirects. 1080 */ 1081 public static final int STATUS_TOO_MANY_REDIRECTS = 497; 1082 1083 /** 1084 * This download couldn't be completed due to insufficient storage 1085 * space. Typically, this is because the SD card is full. 1086 */ 1087 public static final int STATUS_INSUFFICIENT_SPACE_ERROR = 498; 1088 1089 /** 1090 * This download couldn't be completed because no external storage 1091 * device was found. Typically, this is because the SD card is not 1092 * mounted. 1093 */ 1094 public static final int STATUS_DEVICE_NOT_FOUND_ERROR = 499; 1095 1096 /** 1097 * This download is visible but only shows in the notifications 1098 * while it's in progress. 1099 */ 1100 public static final int VISIBILITY_VISIBLE = 0; 1101 1102 /** 1103 * This download is visible and shows in the notifications while 1104 * in progress and after completion. 1105 */ 1106 public static final int VISIBILITY_VISIBLE_NOTIFY_COMPLETED = 1; 1107 1108 /** 1109 * This download doesn't show in the UI or in the notifications. 1110 */ 1111 public static final int VISIBILITY_HIDDEN = 2; 1112 } 1113 } 1114