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