/core/java/android/provider/Downloads.java

https://github.com/phunkycow/android_frameworks_base · Java · 1215 lines · 197 code · 153 blank · 865 comment · 16 complexity · ec086234d31bcd4ee2f82fdf5fa271ec MD5 · raw file

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