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.app.DownloadManager; 20 import android.compat.annotation.UnsupportedAppUsage; 21 import android.content.Context; 22 import android.net.NetworkPolicyManager; 23 import android.net.Uri; 24 import android.os.Build; 25 26 /** 27 * The Download Manager 28 * 29 * @pending 30 */ 31 public final class Downloads { Downloads()32 private Downloads() {} 33 34 /** 35 * Implementation details 36 * 37 * Exposes constants used to interact with the download manager's 38 * content provider. 39 * The constants URI ... STATUS are the names of columns in the downloads table. 40 * 41 * @hide 42 */ 43 public static final class Impl implements BaseColumns { Impl()44 private Impl() {} 45 46 public static final String AUTHORITY = "downloads"; 47 48 /** 49 * The permission to access the download manager 50 */ 51 public static final String PERMISSION_ACCESS = "android.permission.ACCESS_DOWNLOAD_MANAGER"; 52 53 /** 54 * The permission to access the download manager's advanced functions 55 */ 56 public static final String PERMISSION_ACCESS_ADVANCED = 57 "android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED"; 58 59 /** 60 * The permission to access the all the downloads in the manager. 61 */ 62 public static final String PERMISSION_ACCESS_ALL = 63 "android.permission.ACCESS_ALL_DOWNLOADS"; 64 65 /** 66 * The permission to directly access the download manager's cache 67 * directory 68 */ 69 public static final String PERMISSION_CACHE = "android.permission.ACCESS_CACHE_FILESYSTEM"; 70 71 /** 72 * The permission to send broadcasts on download completion 73 */ 74 public static final String PERMISSION_SEND_INTENTS = 75 "android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS"; 76 77 /** 78 * The permission to download files to the cache partition that won't be automatically 79 * purged when space is needed. 80 */ 81 public static final String PERMISSION_CACHE_NON_PURGEABLE = 82 "android.permission.DOWNLOAD_CACHE_NON_PURGEABLE"; 83 84 /** 85 * The permission to download files without any system notification being shown. 86 */ 87 public static final String PERMISSION_NO_NOTIFICATION = 88 "android.permission.DOWNLOAD_WITHOUT_NOTIFICATION"; 89 90 /** 91 * The content:// URI to access downloads owned by the caller's UID. 92 */ 93 @UnsupportedAppUsage 94 public static final Uri CONTENT_URI = 95 Uri.parse("content://downloads/my_downloads"); 96 97 /** 98 * The content URI for accessing all downloads across all UIDs (requires the 99 * ACCESS_ALL_DOWNLOADS permission). 100 */ 101 @UnsupportedAppUsage 102 public static final Uri ALL_DOWNLOADS_CONTENT_URI = 103 Uri.parse("content://downloads/all_downloads"); 104 105 /** URI segment to access a publicly accessible downloaded file */ 106 public static final String PUBLICLY_ACCESSIBLE_DOWNLOADS_URI_SEGMENT = "public_downloads"; 107 108 /** 109 * The content URI for accessing publicly accessible downloads (i.e., it requires no 110 * permissions to access this downloaded file) 111 */ 112 @UnsupportedAppUsage 113 public static final Uri PUBLICLY_ACCESSIBLE_DOWNLOADS_URI = 114 Uri.parse("content://downloads/" + PUBLICLY_ACCESSIBLE_DOWNLOADS_URI_SEGMENT); 115 116 /** 117 * Broadcast Action: this is sent by the download manager to the app 118 * that had initiated a download when that download completes. The 119 * download's content: uri is specified in the intent's data. 120 */ 121 public static final String ACTION_DOWNLOAD_COMPLETED = 122 DownloadManager.ACTION_DOWNLOAD_COMPLETED; 123 124 /** 125 * Broadcast Action: this is sent by the download manager to the app 126 * that had initiated a download when the user selects the notification 127 * associated with that download. The download's content: uri is specified 128 * in the intent's data if the click is associated with a single download, 129 * or Downloads.CONTENT_URI if the notification is associated with 130 * multiple downloads. 131 * Note: this is not currently sent for downloads that have completed 132 * successfully. 133 */ 134 public static final String ACTION_NOTIFICATION_CLICKED = 135 DownloadManager.ACTION_NOTIFICATION_CLICKED; 136 137 /** 138 * The name of the column containing the URI of the data being downloaded. 139 * <P>Type: TEXT</P> 140 * <P>Owner can Init/Read</P> 141 */ 142 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 143 public static final String COLUMN_URI = "uri"; 144 145 /** 146 * The name of the column containing application-specific data. 147 * <P>Type: TEXT</P> 148 * <P>Owner can Init/Read/Write</P> 149 */ 150 public static final String COLUMN_APP_DATA = "entity"; 151 152 /** 153 * The name of the column containing the flags that indicates whether 154 * the initiating application is capable of verifying the integrity of 155 * the downloaded file. When this flag is set, the download manager 156 * performs downloads and reports success even in some situations where 157 * it can't guarantee that the download has completed (e.g. when doing 158 * a byte-range request without an ETag, or when it can't determine 159 * whether a download fully completed). 160 * <P>Type: BOOLEAN</P> 161 * <P>Owner can Init</P> 162 */ 163 public static final String COLUMN_NO_INTEGRITY = "no_integrity"; 164 165 /** 166 * The name of the column containing the filename that the initiating 167 * application recommends. When possible, the download manager will attempt 168 * to use this filename, or a variation, as the actual name for the file. 169 * <P>Type: TEXT</P> 170 * <P>Owner can Init</P> 171 */ 172 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 173 public static final String COLUMN_FILE_NAME_HINT = "hint"; 174 175 /** 176 * The name of the column containing the filename where the downloaded data 177 * was actually stored. 178 * <P>Type: TEXT</P> 179 * <P>Owner can Read</P> 180 */ 181 public static final String _DATA = "_data"; 182 183 /** 184 * The name of the column containing the MIME type of the downloaded data. 185 * <P>Type: TEXT</P> 186 * <P>Owner can Init/Read</P> 187 */ 188 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 189 public static final String COLUMN_MIME_TYPE = "mimetype"; 190 191 /** 192 * The name of the column containing the flag that controls the destination 193 * of the download. See the DESTINATION_* constants for a list of legal values. 194 * <P>Type: INTEGER</P> 195 * <P>Owner can Init</P> 196 */ 197 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 198 public static final String COLUMN_DESTINATION = "destination"; 199 200 /** 201 * The name of the column containing the flags that controls whether the 202 * download is displayed by the UI. See the VISIBILITY_* constants for 203 * a list of legal values. 204 * <P>Type: INTEGER</P> 205 * <P>Owner can Init/Read/Write</P> 206 */ 207 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 208 public static final String COLUMN_VISIBILITY = "visibility"; 209 210 /** 211 * The name of the column containing the current control state of the download. 212 * Applications can write to this to control (pause/resume) the download. 213 * the CONTROL_* constants for a list of legal values. 214 * <P>Type: INTEGER</P> 215 * <P>Owner can Read</P> 216 */ 217 public static final String COLUMN_CONTROL = "control"; 218 219 /** 220 * The name of the column containing the current status of the download. 221 * Applications can read this to follow the progress of each download. See 222 * the STATUS_* constants for a list of legal values. 223 * <P>Type: INTEGER</P> 224 * <P>Owner can Read</P> 225 */ 226 public static final String COLUMN_STATUS = "status"; 227 228 /** 229 * The name of the column containing the date at which some interesting 230 * status changed in the download. Stored as a System.currentTimeMillis() 231 * value. 232 * <P>Type: BIGINT</P> 233 * <P>Owner can Read</P> 234 */ 235 public static final String COLUMN_LAST_MODIFICATION = "lastmod"; 236 237 /** 238 * The name of the column containing the package name of the application 239 * that initiating the download. The download manager will send 240 * notifications to a component in this package when the download completes. 241 * <P>Type: TEXT</P> 242 * <P>Owner can Init/Read</P> 243 */ 244 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 245 public static final String COLUMN_NOTIFICATION_PACKAGE = "notificationpackage"; 246 247 /** 248 * The name of the column containing the component name of the class that 249 * will receive notifications associated with the download. The 250 * package/class combination is passed to 251 * Intent.setClassName(String,String). 252 * <P>Type: TEXT</P> 253 * <P>Owner can Init/Read</P> 254 */ 255 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 256 public static final String COLUMN_NOTIFICATION_CLASS = "notificationclass"; 257 258 /** 259 * If extras are specified when requesting a download they will be provided in the intent that 260 * is sent to the specified class and package when a download has finished. 261 * <P>Type: TEXT</P> 262 * <P>Owner can Init</P> 263 */ 264 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 265 public static final String COLUMN_NOTIFICATION_EXTRAS = "notificationextras"; 266 267 /** 268 * The name of the column contain the values of the cookie to be used for 269 * the download. This is used directly as the value for the Cookie: HTTP 270 * header that gets sent with the request. 271 * <P>Type: TEXT</P> 272 * <P>Owner can Init</P> 273 */ 274 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 275 public static final String COLUMN_COOKIE_DATA = "cookiedata"; 276 277 /** 278 * The name of the column containing the user agent that the initiating 279 * application wants the download manager to use for this download. 280 * <P>Type: TEXT</P> 281 * <P>Owner can Init</P> 282 */ 283 public static final String COLUMN_USER_AGENT = "useragent"; 284 285 /** 286 * The name of the column containing the referer (sic) that the initiating 287 * application wants the download manager to use for this download. 288 * <P>Type: TEXT</P> 289 * <P>Owner can Init</P> 290 */ 291 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 292 public static final String COLUMN_REFERER = "referer"; 293 294 /** 295 * The name of the column containing the total size of the file being 296 * downloaded. 297 * <P>Type: INTEGER</P> 298 * <P>Owner can Read</P> 299 */ 300 public static final String COLUMN_TOTAL_BYTES = "total_bytes"; 301 302 /** 303 * The name of the column containing the size of the part of the file that 304 * has been downloaded so far. 305 * <P>Type: INTEGER</P> 306 * <P>Owner can Read</P> 307 */ 308 public static final String COLUMN_CURRENT_BYTES = "current_bytes"; 309 310 /** 311 * The name of the column where the initiating application can provide the 312 * UID of another application that is allowed to access this download. If 313 * multiple applications share the same UID, all those applications will be 314 * allowed to access this download. This column can be updated after the 315 * download is initiated. This requires the permission 316 * android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED. 317 * <P>Type: INTEGER</P> 318 * <P>Owner can Init</P> 319 */ 320 public static final String COLUMN_OTHER_UID = "otheruid"; 321 322 /** 323 * The name of the column where the initiating application can provided the 324 * title of this download. The title will be displayed ito the user in the 325 * list of downloads. 326 * <P>Type: TEXT</P> 327 * <P>Owner can Init/Read/Write</P> 328 */ 329 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 330 public static final String COLUMN_TITLE = "title"; 331 332 /** 333 * The name of the column where the initiating application can provide the 334 * description of this download. The description will be displayed to the 335 * user in the list of downloads. 336 * <P>Type: TEXT</P> 337 * <P>Owner can Init/Read/Write</P> 338 */ 339 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 340 public static final String COLUMN_DESCRIPTION = "description"; 341 342 /** 343 * The name of the column indicating whether the download was requesting through the public 344 * API. This controls some differences in behavior. 345 * <P>Type: BOOLEAN</P> 346 * <P>Owner can Init/Read</P> 347 */ 348 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 349 public static final String COLUMN_IS_PUBLIC_API = "is_public_api"; 350 351 /** 352 * The name of the column holding a bitmask of allowed network types. This is only used for 353 * public API downloads. 354 * <P>Type: INTEGER</P> 355 * <P>Owner can Init/Read</P> 356 */ 357 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 358 public static final String COLUMN_ALLOWED_NETWORK_TYPES = "allowed_network_types"; 359 360 /** 361 * The name of the column indicating whether roaming connections can be used. This is only 362 * used for public API downloads. 363 * <P>Type: BOOLEAN</P> 364 * <P>Owner can Init/Read</P> 365 */ 366 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 367 public static final String COLUMN_ALLOW_ROAMING = "allow_roaming"; 368 369 /** 370 * The name of the column indicating whether metered connections can be used. This is only 371 * used for public API downloads. 372 * <P>Type: BOOLEAN</P> 373 * <P>Owner can Init/Read</P> 374 */ 375 public static final String COLUMN_ALLOW_METERED = "allow_metered"; 376 377 /** 378 * Whether or not this download should be displayed in the system's Downloads UI. Defaults 379 * to true. 380 * <P>Type: INTEGER</P> 381 * <P>Owner can Init/Read</P> 382 */ 383 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 384 public static final String COLUMN_IS_VISIBLE_IN_DOWNLOADS_UI = "is_visible_in_downloads_ui"; 385 386 /** 387 * If true, the user has confirmed that this download can proceed over the mobile network 388 * even though it exceeds the recommended maximum size. 389 * <P>Type: BOOLEAN</P> 390 */ 391 public static final String COLUMN_BYPASS_RECOMMENDED_SIZE_LIMIT = 392 "bypass_recommended_size_limit"; 393 394 /** 395 * Set to true if this download is deleted. It is completely removed from the database 396 * when MediaProvider database also deletes the metadata asociated with this downloaded file. 397 * <P>Type: BOOLEAN</P> 398 * <P>Owner can Read</P> 399 */ 400 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 401 public static final String COLUMN_DELETED = "deleted"; 402 403 /** 404 * The URI to the corresponding entry in MediaProvider for this downloaded entry. It is 405 * used to delete the entries from MediaProvider database when it is deleted from the 406 * downloaded list. 407 * <P>Type: TEXT</P> 408 * <P>Owner can Read</P> 409 */ 410 public static final String COLUMN_MEDIAPROVIDER_URI = "mediaprovider_uri"; 411 412 /** 413 * Similar to {@link #COLUMN_MEDIAPROVIDER_URI}, except this cannot be updated/queried 414 * by apps and will be the source of truth when updating/deleting download entries in 415 * MediaProvider database. 416 * 417 * <P>Type: TEXT</P> 418 */ 419 public static final String COLUMN_MEDIASTORE_URI = "mediastore_uri"; 420 421 /** 422 * The column that is used to remember whether the media scanner was invoked. 423 * It can take the values: {@link #MEDIA_NOT_SCANNED}, {@link #MEDIA_SCANNED} or 424 * {@link #MEDIA_NOT_SCANNABLE} or {@code null}. If it's value is {@code null}, it will be 425 * treated as {@link #MEDIA_NOT_SCANNED}. 426 * 427 * <P>Type: TEXT</P> 428 */ 429 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 430 public static final String COLUMN_MEDIA_SCANNED = "scanned"; 431 432 /** Possible values for column {@link #COLUMN_MEDIA_SCANNED} */ 433 public static final int MEDIA_NOT_SCANNED = 0; 434 public static final int MEDIA_SCANNED = 1; 435 public static final int MEDIA_NOT_SCANNABLE = 2; 436 437 /** 438 * The column with errorMsg for a failed downloaded. 439 * Used only for debugging purposes. 440 * <P>Type: TEXT</P> 441 */ 442 public static final String COLUMN_ERROR_MSG = "errorMsg"; 443 444 /** 445 * This column stores the source of the last update to this row. 446 * This column is only for internal use. 447 * Valid values are indicated by LAST_UPDATESRC_* constants. 448 * <P>Type: INT</P> 449 */ 450 public static final String COLUMN_LAST_UPDATESRC = "lastUpdateSrc"; 451 452 /** The column that is used to count retries */ 453 public static final String COLUMN_FAILED_CONNECTIONS = "numfailed"; 454 455 public static final String COLUMN_ALLOW_WRITE = "allow_write"; 456 457 public static final int FLAG_REQUIRES_CHARGING = 1 << 0; 458 public static final int FLAG_REQUIRES_DEVICE_IDLE = 1 << 1; 459 460 public static final String COLUMN_FLAGS = "flags"; 461 462 /** 463 * default value for {@link #COLUMN_LAST_UPDATESRC}. 464 * This value is used when this column's value is not relevant. 465 */ 466 public static final int LAST_UPDATESRC_NOT_RELEVANT = 0; 467 468 /** 469 * One of the values taken by {@link #COLUMN_LAST_UPDATESRC}. 470 * This value is used when the update is NOT to be relayed to the DownloadService 471 * (and thus spare DownloadService from scanning the database when this change occurs) 472 */ 473 public static final int LAST_UPDATESRC_DONT_NOTIFY_DOWNLOADSVC = 1; 474 475 /* 476 * Lists the destinations that an application can specify for a download. 477 */ 478 479 /** 480 * This download will be saved to the external storage. This is the 481 * default behavior, and should be used for any file that the user 482 * can freely access, copy, delete. Even with that destination, 483 * unencrypted DRM files are saved in secure internal storage. 484 * Downloads to the external destination only write files for which 485 * there is a registered handler. The resulting files are accessible 486 * by filename to all applications. 487 */ 488 public static final int DESTINATION_EXTERNAL = 0; 489 490 /** 491 * This download will be saved to the download manager's private 492 * partition. This is the behavior used by applications that want to 493 * download private files that are used and deleted soon after they 494 * get downloaded. All file types are allowed, and only the initiating 495 * application can access the file (indirectly through a content 496 * provider). This requires the 497 * android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED permission. 498 */ 499 public static final int DESTINATION_CACHE_PARTITION = 1; 500 501 /** 502 * This download will be saved to the download manager's private 503 * partition and will be purged as necessary to make space. This is 504 * for private files (similar to CACHE_PARTITION) that aren't deleted 505 * immediately after they are used, and are kept around by the download 506 * manager as long as space is available. 507 */ 508 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 509 public static final int DESTINATION_CACHE_PARTITION_PURGEABLE = 2; 510 511 /** 512 * This download will be saved to the download manager's private 513 * partition, as with DESTINATION_CACHE_PARTITION, but the download 514 * will not proceed if the user is on a roaming data connection. 515 */ 516 public static final int DESTINATION_CACHE_PARTITION_NOROAMING = 3; 517 518 /** 519 * This download will be saved to the location given by the file URI in 520 * {@link #COLUMN_FILE_NAME_HINT}. 521 */ 522 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 523 public static final int DESTINATION_FILE_URI = 4; 524 525 /** 526 * This download will be saved to the system cache ("/cache") 527 * partition. This option is only used by system apps and so it requires 528 * android.permission.ACCESS_CACHE_FILESYSTEM permission. 529 */ 530 @Deprecated 531 public static final int DESTINATION_SYSTEMCACHE_PARTITION = 5; 532 533 /** 534 * This download was completed by the caller (i.e., NOT downloadmanager) 535 * and caller wants to have this download displayed in Downloads App. 536 */ 537 public static final int DESTINATION_NON_DOWNLOADMANAGER_DOWNLOAD = 6; 538 539 /** 540 * This download is allowed to run. 541 */ 542 public static final int CONTROL_RUN = 0; 543 544 /** 545 * This download must pause at the first opportunity. 546 */ 547 public static final int CONTROL_PAUSED = 1; 548 549 /* 550 * Lists the states that the download manager can set on a download 551 * to notify applications of the download progress. 552 * The codes follow the HTTP families:<br> 553 * 1xx: informational<br> 554 * 2xx: success<br> 555 * 3xx: redirects (not used by the download manager)<br> 556 * 4xx: client errors<br> 557 * 5xx: server errors 558 */ 559 560 /** 561 * Returns whether the status is informational (i.e. 1xx). 562 */ isStatusInformational(int status)563 public static boolean isStatusInformational(int status) { 564 return (status >= 100 && status < 200); 565 } 566 567 /** 568 * Returns whether the status is a success (i.e. 2xx). 569 */ 570 @UnsupportedAppUsage isStatusSuccess(int status)571 public static boolean isStatusSuccess(int status) { 572 return (status >= 200 && status < 300); 573 } 574 575 /** 576 * Returns whether the status is an error (i.e. 4xx or 5xx). 577 */ 578 @UnsupportedAppUsage isStatusError(int status)579 public static boolean isStatusError(int status) { 580 return (status >= 400 && status < 600); 581 } 582 583 /** 584 * Returns whether the status is a client error (i.e. 4xx). 585 */ isStatusClientError(int status)586 public static boolean isStatusClientError(int status) { 587 return (status >= 400 && status < 500); 588 } 589 590 /** 591 * Returns whether the status is a server error (i.e. 5xx). 592 */ isStatusServerError(int status)593 public static boolean isStatusServerError(int status) { 594 return (status >= 500 && status < 600); 595 } 596 597 /** 598 * this method determines if a notification should be displayed for a 599 * given {@link #COLUMN_VISIBILITY} value 600 * @param visibility the value of {@link #COLUMN_VISIBILITY}. 601 * @return true if the notification should be displayed. false otherwise. 602 */ 603 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) isNotificationToBeDisplayed(int visibility)604 public static boolean isNotificationToBeDisplayed(int visibility) { 605 return visibility == DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED || 606 visibility == DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION; 607 } 608 609 /** 610 * Returns whether the download has completed (either with success or 611 * error). 612 */ 613 @UnsupportedAppUsage isStatusCompleted(int status)614 public static boolean isStatusCompleted(int status) { 615 return (status >= 200 && status < 300) || (status >= 400 && status < 600); 616 } 617 618 /** 619 * This download hasn't stated yet 620 */ 621 public static final int STATUS_PENDING = 190; 622 623 /** 624 * This download has started 625 */ 626 public static final int STATUS_RUNNING = 192; 627 628 /** 629 * This download has been paused by the owning app. 630 */ 631 public static final int STATUS_PAUSED_BY_APP = 193; 632 633 /** 634 * This download encountered some network error and is waiting before retrying the request. 635 */ 636 public static final int STATUS_WAITING_TO_RETRY = 194; 637 638 /** 639 * This download is waiting for network connectivity to proceed. 640 */ 641 public static final int STATUS_WAITING_FOR_NETWORK = 195; 642 643 /** 644 * This download exceeded a size limit for mobile networks and is waiting for a Wi-Fi 645 * connection to proceed. 646 */ 647 public static final int STATUS_QUEUED_FOR_WIFI = 196; 648 649 /** 650 * This download couldn't be completed due to insufficient storage 651 * space. Typically, this is because the SD card is full. 652 */ 653 public static final int STATUS_INSUFFICIENT_SPACE_ERROR = 198; 654 655 /** 656 * This download couldn't be completed because no external storage 657 * device was found. Typically, this is because the SD card is not 658 * mounted. 659 */ 660 public static final int STATUS_DEVICE_NOT_FOUND_ERROR = 199; 661 662 /** 663 * This download has successfully completed. 664 * Warning: there might be other status values that indicate success 665 * in the future. 666 * Use isStatusSuccess() to capture the entire category. 667 */ 668 public static final int STATUS_SUCCESS = 200; 669 670 /** 671 * This request couldn't be parsed. This is also used when processing 672 * requests with unknown/unsupported URI schemes. 673 */ 674 public static final int STATUS_BAD_REQUEST = 400; 675 676 /** 677 * This download can't be performed because the content type cannot be 678 * handled. 679 */ 680 public static final int STATUS_NOT_ACCEPTABLE = 406; 681 682 /** 683 * This download cannot be performed because the length cannot be 684 * determined accurately. This is the code for the HTTP error "Length 685 * Required", which is typically used when making requests that require 686 * a content length but don't have one, and it is also used in the 687 * client when a response is received whose length cannot be determined 688 * accurately (therefore making it impossible to know when a download 689 * completes). 690 */ 691 public static final int STATUS_LENGTH_REQUIRED = 411; 692 693 /** 694 * This download was interrupted and cannot be resumed. 695 * This is the code for the HTTP error "Precondition Failed", and it is 696 * also used in situations where the client doesn't have an ETag at all. 697 */ 698 public static final int STATUS_PRECONDITION_FAILED = 412; 699 700 /** 701 * The lowest-valued error status that is not an actual HTTP status code. 702 */ 703 public static final int MIN_ARTIFICIAL_ERROR_STATUS = 488; 704 705 /** 706 * The requested destination file already exists. 707 */ 708 public static final int STATUS_FILE_ALREADY_EXISTS_ERROR = 488; 709 710 /** 711 * Some possibly transient error occurred, but we can't resume the download. 712 */ 713 public static final int STATUS_CANNOT_RESUME = 489; 714 715 /** 716 * This download was canceled 717 */ 718 public static final int STATUS_CANCELED = 490; 719 720 /** 721 * This download has completed with an error. 722 * Warning: there will be other status values that indicate errors in 723 * the future. Use isStatusError() to capture the entire category. 724 */ 725 public static final int STATUS_UNKNOWN_ERROR = 491; 726 727 /** 728 * This download couldn't be completed because of a storage issue. 729 * Typically, that's because the filesystem is missing or full. 730 * Use the more specific {@link #STATUS_INSUFFICIENT_SPACE_ERROR} 731 * and {@link #STATUS_DEVICE_NOT_FOUND_ERROR} when appropriate. 732 */ 733 public static final int STATUS_FILE_ERROR = 492; 734 735 /** 736 * This download couldn't be completed because of an HTTP 737 * redirect response that the download manager couldn't 738 * handle. 739 */ 740 public static final int STATUS_UNHANDLED_REDIRECT = 493; 741 742 /** 743 * This download couldn't be completed because of an 744 * unspecified unhandled HTTP code. 745 */ 746 public static final int STATUS_UNHANDLED_HTTP_CODE = 494; 747 748 /** 749 * This download couldn't be completed because of an 750 * error receiving or processing data at the HTTP level. 751 */ 752 public static final int STATUS_HTTP_DATA_ERROR = 495; 753 754 /** 755 * This download couldn't be completed because of an 756 * HttpException while setting up the request. 757 */ 758 public static final int STATUS_HTTP_EXCEPTION = 496; 759 760 /** 761 * This download couldn't be completed because there were 762 * too many redirects. 763 */ 764 public static final int STATUS_TOO_MANY_REDIRECTS = 497; 765 766 /** 767 * This download has failed because requesting application has been 768 * blocked by {@link NetworkPolicyManager}. 769 * 770 * @hide 771 * @deprecated since behavior now uses 772 * {@link #STATUS_WAITING_FOR_NETWORK} 773 */ 774 @Deprecated 775 public static final int STATUS_BLOCKED = 498; 776 777 /** {@hide} */ statusToString(int status)778 public static String statusToString(int status) { 779 switch (status) { 780 case STATUS_PENDING: return "PENDING"; 781 case STATUS_RUNNING: return "RUNNING"; 782 case STATUS_PAUSED_BY_APP: return "PAUSED_BY_APP"; 783 case STATUS_WAITING_TO_RETRY: return "WAITING_TO_RETRY"; 784 case STATUS_WAITING_FOR_NETWORK: return "WAITING_FOR_NETWORK"; 785 case STATUS_QUEUED_FOR_WIFI: return "QUEUED_FOR_WIFI"; 786 case STATUS_INSUFFICIENT_SPACE_ERROR: return "INSUFFICIENT_SPACE_ERROR"; 787 case STATUS_DEVICE_NOT_FOUND_ERROR: return "DEVICE_NOT_FOUND_ERROR"; 788 case STATUS_SUCCESS: return "SUCCESS"; 789 case STATUS_BAD_REQUEST: return "BAD_REQUEST"; 790 case STATUS_NOT_ACCEPTABLE: return "NOT_ACCEPTABLE"; 791 case STATUS_LENGTH_REQUIRED: return "LENGTH_REQUIRED"; 792 case STATUS_PRECONDITION_FAILED: return "PRECONDITION_FAILED"; 793 case STATUS_FILE_ALREADY_EXISTS_ERROR: return "FILE_ALREADY_EXISTS_ERROR"; 794 case STATUS_CANNOT_RESUME: return "CANNOT_RESUME"; 795 case STATUS_CANCELED: return "CANCELED"; 796 case STATUS_UNKNOWN_ERROR: return "UNKNOWN_ERROR"; 797 case STATUS_FILE_ERROR: return "FILE_ERROR"; 798 case STATUS_UNHANDLED_REDIRECT: return "UNHANDLED_REDIRECT"; 799 case STATUS_UNHANDLED_HTTP_CODE: return "UNHANDLED_HTTP_CODE"; 800 case STATUS_HTTP_DATA_ERROR: return "HTTP_DATA_ERROR"; 801 case STATUS_HTTP_EXCEPTION: return "HTTP_EXCEPTION"; 802 case STATUS_TOO_MANY_REDIRECTS: return "TOO_MANY_REDIRECTS"; 803 case STATUS_BLOCKED: return "BLOCKED"; 804 default: return Integer.toString(status); 805 } 806 } 807 808 /** 809 * This download is visible but only shows in the notifications 810 * while it's in progress. 811 */ 812 public static final int VISIBILITY_VISIBLE = DownloadManager.Request.VISIBILITY_VISIBLE; 813 814 /** 815 * This download is visible and shows in the notifications while 816 * in progress and after completion. 817 */ 818 public static final int VISIBILITY_VISIBLE_NOTIFY_COMPLETED = 819 DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED; 820 821 /** 822 * This download doesn't show in the UI or in the notifications. 823 */ 824 public static final int VISIBILITY_HIDDEN = DownloadManager.Request.VISIBILITY_HIDDEN; 825 826 /** 827 * Constants related to HTTP request headers associated with each download. 828 */ 829 public static class RequestHeaders { 830 public static final String HEADERS_DB_TABLE = "request_headers"; 831 public static final String COLUMN_DOWNLOAD_ID = "download_id"; 832 public static final String COLUMN_HEADER = "header"; 833 public static final String COLUMN_VALUE = "value"; 834 835 /** 836 * Path segment to add to a download URI to retrieve request headers 837 */ 838 public static final String URI_SEGMENT = "headers"; 839 840 /** 841 * Prefix for ContentValues keys that contain HTTP header lines, to be passed to 842 * DownloadProvider.insert(). 843 */ 844 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 845 public static final String INSERT_KEY_PREFIX = "http_header_"; 846 } 847 } 848 849 /** @hide */ 850 public static final String CALL_MEDIASTORE_DOWNLOADS_DELETED = "mediastore_downloads_deleted"; 851 /** @hide */ 852 public static final String CALL_CREATE_EXTERNAL_PUBLIC_DIR = "create_external_public_dir"; 853 /** @hide */ 854 public static final String CALL_REVOKE_MEDIASTORE_URI_PERMS = "revoke_mediastore_uri_perms"; 855 856 /** @hide */ 857 public static final String EXTRA_IDS = "ids"; 858 /** @hide */ 859 public static final String EXTRA_MIME_TYPES = "mime_types"; 860 /** @hide */ 861 public static final String DIR_TYPE = "dir_type"; 862 863 /** 864 * Query where clause for general querying. 865 */ 866 private static final String QUERY_WHERE_CLAUSE = Impl.COLUMN_NOTIFICATION_PACKAGE + "=? AND " 867 + Impl.COLUMN_NOTIFICATION_CLASS + "=?"; 868 869 /** 870 * Delete all the downloads for a package/class pair. 871 */ removeAllDownloadsByPackage( Context context, String notification_package, String notification_class)872 public static final void removeAllDownloadsByPackage( 873 Context context, String notification_package, String notification_class) { 874 context.getContentResolver().delete(Impl.CONTENT_URI, QUERY_WHERE_CLAUSE, 875 new String[] { notification_package, notification_class }); 876 } 877 } 878