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 21 /** 22 * Exposes constants used to interact with the download manager's 23 * content provider. 24 * The constants URI ... STATUS are the names of columns in the downloads table. 25 * 26 * @hide 27 */ 28 // For 1.0 the download manager can't deal with abuse from untrusted apps, so 29 // this API is hidden. 30 public final class Downloads implements BaseColumns { Downloads()31 private Downloads() {} 32 33 /** 34 * The permission to access the download manager 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 */ 41 public static final String PERMISSION_ACCESS_ADVANCED = 42 "android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED"; 43 44 /** 45 * The permission to directly access the download manager's cache directory 46 */ 47 public static final String PERMISSION_CACHE = "android.permission.ACCESS_CACHE_FILESYSTEM"; 48 49 /** 50 * The permission to send broadcasts on download completion 51 */ 52 public static final String PERMISSION_SEND_INTENTS = 53 "android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS"; 54 55 /** 56 * The content:// URI for the data table in the provider 57 */ 58 public static final Uri CONTENT_URI = 59 Uri.parse("content://downloads/download"); 60 61 /** 62 * Broadcast Action: this is sent by the download manager to the app 63 * that had initiated a download when that download completes. The 64 * download's content: uri is specified in the intent's data. 65 */ 66 public static final String ACTION_DOWNLOAD_COMPLETED = 67 "android.intent.action.DOWNLOAD_COMPLETED"; 68 69 /** 70 * Broadcast Action: this is sent by the download manager to the app 71 * that had initiated a download when the user selects the notification 72 * associated with that download. The download's content: uri is specified 73 * in the intent's data if the click is associated with a single download, 74 * or Downloads.CONTENT_URI if the notification is associated with 75 * multiple downloads. 76 * Note: this is not currently sent for downloads that have completed 77 * successfully. 78 */ 79 public static final String ACTION_NOTIFICATION_CLICKED = 80 "android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED"; 81 82 /** 83 * The name of the column containing the URI of the data being downloaded. 84 * <P>Type: TEXT</P> 85 * <P>Owner can Init/Read</P> 86 */ 87 public static final String COLUMN_URI = "uri"; 88 89 /** 90 * The name of the column containing application-specific data. 91 * <P>Type: TEXT</P> 92 * <P>Owner can Init/Read/Write</P> 93 */ 94 public static final String COLUMN_APP_DATA = "entity"; 95 96 /** 97 * The name of the column containing the flags that indicates whether 98 * the initiating application is capable of verifying the integrity of 99 * the downloaded file. When this flag is set, the download manager 100 * performs downloads and reports success even in some situations where 101 * it can't guarantee that the download has completed (e.g. when doing 102 * a byte-range request without an ETag, or when it can't determine 103 * whether a download fully completed). 104 * <P>Type: BOOLEAN</P> 105 * <P>Owner can Init</P> 106 */ 107 public static final String COLUMN_NO_INTEGRITY = "no_integrity"; 108 109 /** 110 * The name of the column containing the filename that the initiating 111 * application recommends. When possible, the download manager will attempt 112 * to use this filename, or a variation, as the actual name for the file. 113 * <P>Type: TEXT</P> 114 * <P>Owner can Init</P> 115 */ 116 public static final String COLUMN_FILE_NAME_HINT = "hint"; 117 118 /** 119 * The name of the column containing the filename where the downloaded data 120 * was actually stored. 121 * <P>Type: TEXT</P> 122 * <P>Owner can Read</P> 123 */ 124 public static final String _DATA = "_data"; 125 126 /** 127 * The name of the column containing the MIME type of the downloaded data. 128 * <P>Type: TEXT</P> 129 * <P>Owner can Init/Read</P> 130 */ 131 public static final String COLUMN_MIME_TYPE = "mimetype"; 132 133 /** 134 * The name of the column containing the flag that controls the destination 135 * of the download. See the DESTINATION_* constants for a list of legal values. 136 * <P>Type: INTEGER</P> 137 * <P>Owner can Init</P> 138 */ 139 public static final String COLUMN_DESTINATION = "destination"; 140 141 /** 142 * The name of the column containing the flags that controls whether the 143 * download is displayed by the UI. See the VISIBILITY_* constants for 144 * a list of legal values. 145 * <P>Type: INTEGER</P> 146 * <P>Owner can Init/Read/Write</P> 147 */ 148 public static final String COLUMN_VISIBILITY = "visibility"; 149 150 /** 151 * The name of the column containing the current control state of the download. 152 * Applications can write to this to control (pause/resume) the download. 153 * the CONTROL_* constants for a list of legal values. 154 * <P>Type: INTEGER</P> 155 * <P>Owner can Read</P> 156 */ 157 public static final String COLUMN_CONTROL = "control"; 158 159 /** 160 * The name of the column containing the current status of the download. 161 * Applications can read this to follow the progress of each download. See 162 * the STATUS_* constants for a list of legal values. 163 * <P>Type: INTEGER</P> 164 * <P>Owner can Read</P> 165 */ 166 public static final String COLUMN_STATUS = "status"; 167 168 /** 169 * The name of the column containing the date at which some interesting 170 * status changed in the download. Stored as a System.currentTimeMillis() 171 * value. 172 * <P>Type: BIGINT</P> 173 * <P>Owner can Read</P> 174 */ 175 public static final String COLUMN_LAST_MODIFICATION = "lastmod"; 176 177 /** 178 * The name of the column containing the package name of the application 179 * that initiating the download. The download manager will send 180 * notifications to a component in this package when the download completes. 181 * <P>Type: TEXT</P> 182 * <P>Owner can Init/Read</P> 183 */ 184 public static final String COLUMN_NOTIFICATION_PACKAGE = "notificationpackage"; 185 186 /** 187 * The name of the column containing the component name of the class that 188 * will receive notifications associated with the download. The 189 * package/class combination is passed to 190 * Intent.setClassName(String,String). 191 * <P>Type: TEXT</P> 192 * <P>Owner can Init/Read</P> 193 */ 194 public static final String COLUMN_NOTIFICATION_CLASS = "notificationclass"; 195 196 /** 197 * If extras are specified when requesting a download they will be provided in the intent that 198 * is sent to the specified class and package when a download has finished. 199 * <P>Type: TEXT</P> 200 * <P>Owner can Init</P> 201 */ 202 public static final String COLUMN_NOTIFICATION_EXTRAS = "notificationextras"; 203 204 /** 205 * The name of the column contain the values of the cookie to be used for 206 * the download. This is used directly as the value for the Cookie: HTTP 207 * header that gets sent with the request. 208 * <P>Type: TEXT</P> 209 * <P>Owner can Init</P> 210 */ 211 public static final String COLUMN_COOKIE_DATA = "cookiedata"; 212 213 /** 214 * The name of the column containing the user agent that the initiating 215 * application wants the download manager to use for this download. 216 * <P>Type: TEXT</P> 217 * <P>Owner can Init</P> 218 */ 219 public static final String COLUMN_USER_AGENT = "useragent"; 220 221 /** 222 * The name of the column containing the referer (sic) that the initiating 223 * application wants the download manager to use for this download. 224 * <P>Type: TEXT</P> 225 * <P>Owner can Init</P> 226 */ 227 public static final String COLUMN_REFERER = "referer"; 228 229 /** 230 * The name of the column containing the total size of the file being 231 * downloaded. 232 * <P>Type: INTEGER</P> 233 * <P>Owner can Read</P> 234 */ 235 public static final String COLUMN_TOTAL_BYTES = "total_bytes"; 236 237 /** 238 * The name of the column containing the size of the part of the file that 239 * has been downloaded so far. 240 * <P>Type: INTEGER</P> 241 * <P>Owner can Read</P> 242 */ 243 public static final String COLUMN_CURRENT_BYTES = "current_bytes"; 244 245 /** 246 * The name of the column where the initiating application can provide the 247 * UID of another application that is allowed to access this download. If 248 * multiple applications share the same UID, all those applications will be 249 * allowed to access this download. This column can be updated after the 250 * download is initiated. This requires the permission 251 * android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED. 252 * <P>Type: INTEGER</P> 253 * <P>Owner can Init</P> 254 */ 255 public static final String COLUMN_OTHER_UID = "otheruid"; 256 257 /** 258 * The name of the column where the initiating application can provided the 259 * title of this download. The title will be displayed ito the user in the 260 * list of downloads. 261 * <P>Type: TEXT</P> 262 * <P>Owner can Init/Read/Write</P> 263 */ 264 public static final String COLUMN_TITLE = "title"; 265 266 /** 267 * The name of the column where the initiating application can provide the 268 * description of this download. The description will be displayed to the 269 * user in the list of downloads. 270 * <P>Type: TEXT</P> 271 * <P>Owner can Init/Read/Write</P> 272 */ 273 public static final String COLUMN_DESCRIPTION = "description"; 274 275 /* 276 * Lists the destinations that an application can specify for a download. 277 */ 278 279 /** 280 * This download will be saved to the external storage. This is the 281 * default behavior, and should be used for any file that the user 282 * can freely access, copy, delete. Even with that destination, 283 * unencrypted DRM files are saved in secure internal storage. 284 * Downloads to the external destination only write files for which 285 * there is a registered handler. The resulting files are accessible 286 * by filename to all applications. 287 */ 288 public static final int DESTINATION_EXTERNAL = 0; 289 290 /** 291 * This download will be saved to the download manager's private 292 * partition. This is the behavior used by applications that want to 293 * download private files that are used and deleted soon after they 294 * get downloaded. All file types are allowed, and only the initiating 295 * application can access the file (indirectly through a content 296 * provider). This requires the 297 * android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED permission. 298 */ 299 public static final int DESTINATION_CACHE_PARTITION = 1; 300 301 /** 302 * This download will be saved to the download manager's private 303 * partition and will be purged as necessary to make space. This is 304 * for private files (similar to CACHE_PARTITION) that aren't deleted 305 * immediately after they are used, and are kept around by the download 306 * manager as long as space is available. 307 */ 308 public static final int DESTINATION_CACHE_PARTITION_PURGEABLE = 2; 309 310 /** 311 * This download will be saved to the download manager's private 312 * partition, as with DESTINATION_CACHE_PARTITION, but the download 313 * will not proceed if the user is on a roaming data connection. 314 */ 315 public static final int DESTINATION_CACHE_PARTITION_NOROAMING = 3; 316 317 /** 318 * This download is allowed to run. 319 */ 320 public static final int CONTROL_RUN = 0; 321 322 /** 323 * This download must pause at the first opportunity. 324 */ 325 public static final int CONTROL_PAUSED = 1; 326 327 /* 328 * Lists the states that the download manager can set on a download 329 * to notify applications of the download progress. 330 * The codes follow the HTTP families:<br> 331 * 1xx: informational<br> 332 * 2xx: success<br> 333 * 3xx: redirects (not used by the download manager)<br> 334 * 4xx: client errors<br> 335 * 5xx: server errors 336 */ 337 338 /** 339 * Returns whether the status is informational (i.e. 1xx). 340 */ isStatusInformational(int status)341 public static boolean isStatusInformational(int status) { 342 return (status >= 100 && status < 200); 343 } 344 345 /** 346 * Returns whether the download is suspended. (i.e. whether the download 347 * won't complete without some action from outside the download 348 * manager). 349 */ isStatusSuspended(int status)350 public static boolean isStatusSuspended(int status) { 351 return (status == STATUS_PENDING_PAUSED || status == STATUS_RUNNING_PAUSED); 352 } 353 354 /** 355 * Returns whether the status is a success (i.e. 2xx). 356 */ isStatusSuccess(int status)357 public static boolean isStatusSuccess(int status) { 358 return (status >= 200 && status < 300); 359 } 360 361 /** 362 * Returns whether the status is an error (i.e. 4xx or 5xx). 363 */ isStatusError(int status)364 public static boolean isStatusError(int status) { 365 return (status >= 400 && status < 600); 366 } 367 368 /** 369 * Returns whether the status is a client error (i.e. 4xx). 370 */ isStatusClientError(int status)371 public static boolean isStatusClientError(int status) { 372 return (status >= 400 && status < 500); 373 } 374 375 /** 376 * Returns whether the status is a server error (i.e. 5xx). 377 */ isStatusServerError(int status)378 public static boolean isStatusServerError(int status) { 379 return (status >= 500 && status < 600); 380 } 381 382 /** 383 * Returns whether the download has completed (either with success or 384 * error). 385 */ isStatusCompleted(int status)386 public static boolean isStatusCompleted(int status) { 387 return (status >= 200 && status < 300) || (status >= 400 && status < 600); 388 } 389 390 /** 391 * This download hasn't stated yet 392 */ 393 public static final int STATUS_PENDING = 190; 394 395 /** 396 * This download hasn't stated yet and is paused 397 */ 398 public static final int STATUS_PENDING_PAUSED = 191; 399 400 /** 401 * This download has started 402 */ 403 public static final int STATUS_RUNNING = 192; 404 405 /** 406 * This download has started and is paused 407 */ 408 public static final int STATUS_RUNNING_PAUSED = 193; 409 410 /** 411 * This download has successfully completed. 412 * Warning: there might be other status values that indicate success 413 * in the future. 414 * Use isSucccess() to capture the entire category. 415 */ 416 public static final int STATUS_SUCCESS = 200; 417 418 /** 419 * This request couldn't be parsed. This is also used when processing 420 * requests with unknown/unsupported URI schemes. 421 */ 422 public static final int STATUS_BAD_REQUEST = 400; 423 424 /** 425 * This download can't be performed because the content type cannot be 426 * handled. 427 */ 428 public static final int STATUS_NOT_ACCEPTABLE = 406; 429 430 /** 431 * This download cannot be performed because the length cannot be 432 * determined accurately. This is the code for the HTTP error "Length 433 * Required", which is typically used when making requests that require 434 * a content length but don't have one, and it is also used in the 435 * client when a response is received whose length cannot be determined 436 * accurately (therefore making it impossible to know when a download 437 * completes). 438 */ 439 public static final int STATUS_LENGTH_REQUIRED = 411; 440 441 /** 442 * This download was interrupted and cannot be resumed. 443 * This is the code for the HTTP error "Precondition Failed", and it is 444 * also used in situations where the client doesn't have an ETag at all. 445 */ 446 public static final int STATUS_PRECONDITION_FAILED = 412; 447 448 /** 449 * This download was canceled 450 */ 451 public static final int STATUS_CANCELED = 490; 452 453 /** 454 * This download has completed with an error. 455 * Warning: there will be other status values that indicate errors in 456 * the future. Use isStatusError() to capture the entire category. 457 */ 458 public static final int STATUS_UNKNOWN_ERROR = 491; 459 460 /** 461 * This download couldn't be completed because of a storage issue. 462 * Typically, that's because the filesystem is missing or full. 463 */ 464 public static final int STATUS_FILE_ERROR = 492; 465 466 /** 467 * This download couldn't be completed because of an HTTP 468 * redirect response that the download manager couldn't 469 * handle. 470 */ 471 public static final int STATUS_UNHANDLED_REDIRECT = 493; 472 473 /** 474 * This download couldn't be completed because of an 475 * unspecified unhandled HTTP code. 476 */ 477 public static final int STATUS_UNHANDLED_HTTP_CODE = 494; 478 479 /** 480 * This download couldn't be completed because of an 481 * error receiving or processing data at the HTTP level. 482 */ 483 public static final int STATUS_HTTP_DATA_ERROR = 495; 484 485 /** 486 * This download couldn't be completed because of an 487 * HttpException while setting up the request. 488 */ 489 public static final int STATUS_HTTP_EXCEPTION = 496; 490 491 /** 492 * This download couldn't be completed because there were 493 * too many redirects. 494 */ 495 public static final int STATUS_TOO_MANY_REDIRECTS = 497; 496 497 /** 498 * This download is visible but only shows in the notifications 499 * while it's in progress. 500 */ 501 public static final int VISIBILITY_VISIBLE = 0; 502 503 /** 504 * This download is visible and shows in the notifications while 505 * in progress and after completion. 506 */ 507 public static final int VISIBILITY_VISIBLE_NOTIFY_COMPLETED = 1; 508 509 /** 510 * This download doesn't show in the UI or in the notifications. 511 */ 512 public static final int VISIBILITY_HIDDEN = 2; 513 } 514