summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/DownloadThread.java
Commit message (Collapse)AuthorAgeFilesLines
* Treat deleted in-progress downloads as canceled.Jeff Sharkey2013-10-041-1/+1
| | | | | | | Otherwise the download thread would keep going! Bug: 11081405 Change-Id: Ib8f1b624b29cabc782b8a0047d7b5db7e39a17de
* Count download WakeLocks against requesting app.Jeff Sharkey2013-06-061-0/+2
| | | | | | | This matches how network usage is already counted against the app making the request. Change-Id: I6a862e096f2f99441925a101268235615000355a
* Increment operation counts to track downloads.Jeff Sharkey2013-05-101-2/+7
| | | | | Bug: 8850035 Change-Id: If506ea21f0c823f9da4b7ae14d611fdbfbac8042
* Unregister observer when tearing down service.Jeff Sharkey2013-03-261-4/+4
| | | | | | | Also reduce and adjust some logging. Bug: 8470658 Change-Id: Ia1f1cbd315ded04edd2113506e5c5a1db5ec85b4
* Defeat transparent Accept-Encoding: gzip.Jeff Sharkey2013-03-181-0/+4
| | | | | | | | Transparent gzip encoding doesn't allow us to easily resume partial requests, so defeat it for now. Bug: 8409417 Change-Id: I1172709c09d1153fff1ba8df072a9bef896e244d
* Adjust timeouts to reduce false-positive bugs.Jeff Sharkey2013-02-261-2/+2
| | | | | | | | | Otherwise we end up triggering MSG_FINAL_UPDATE while still waiting for socket timeouts. Using 20 seconds for timeout is more sane, and matches Volley. Bug: 8233041 Change-Id: Ia7220033a5942c46ca1d79a88e2b3f530cb3edac
* Only report speeds from full samples windows.Jeff Sharkey2013-02-191-2/+5
| | | | | | | | | | | Wait until we've passed a full sample window (500ms) before reporting an estimated speed. This avoid showing skewed times like "900 hours remaining." Also remember to clean up the UpdateThread. Bug: 8176417 Change-Id: I851e0abcbb443114abe9c22f4650fee7a9bc3aaa
* Retries shouldn't backoff when network changes.Jeff Sharkey2013-02-191-17/+22
| | | | | | | When a download fails due to a network change, treat it as waiting for network, instead of subjecting it to full retry backoff. Change-Id: Ifdae62fd7c2baad7422f68e09da94740b5f513d0
* Update database before sending broadcast.Jeff Sharkey2013-02-141-1/+1
| | | | | | | | This was moved to to solve a race condition around service shutdown, but ended up causing another race with remote apps. Bug: 8200919 Change-Id: Ief470e9454e9be8ec43ca3ec11e3b3440fa5852d
* Redesign of DownloadManager update loop.Jeff Sharkey2013-02-121-4/+22
| | | | | | | | | | | | | | | | | | Previously, the service lifecycle was managed through a large for() loop which was extremely tricky to reason about. This resulted in several race conditions that could leave the service running indefinitely, or terminate it early before tasks had finished. This change redesigns the update loop to be event driven based on database updates, and to collapse mutiple pending update passes. It is much easier to reason about service termination conditions, and it correctly uses startId to handle races during command delivery. Also moves scanner into isolated class, and switches to using public API instead of binding to private interface. Bug: 7638470, 7455406, 7162341 Change-Id: I380e77f5432223b2acb4e819e37f29f98ee4782b
* Tests for max retries/redirects, ETag switches.Jeff Sharkey2013-01-291-11/+10
| | | | | | | | | | Verify that servers responding with many retries or redirects result in failed download, instead of spinning out of control. Test to verify that changed ETag results in download failing. Also fix handling of HTTP 301 to update Uri in database. Change-Id: Iff2948d79961a245b7900117d107edaa356618c9
* Cleaner thread management, less global state.Jeff Sharkey2013-01-281-8/+7
| | | | | | | | | | | | Switch to using a ThreadPoolExecutor for handling downloads, which gives us parallelism logic that is easier to reason about. Also open the door to eventually waiting until the executor is drained to stopSelf(). Removes DownloadHandler singleton, and gives explicit path for publishing active download speeds to notifications. Change-Id: I1836e7742bb8a84861d1ca6bd1e59b2040bd12f8
* Better handling of retryable errors.Jeff Sharkey2013-01-171-53/+57
| | | | | | | | Now the final errors are always thrown, and the outer code decides how to handle them as retries. Also clean up method signatures. Bug: 8022478 Change-Id: I4e7e43be793294ab837370df521e7c381e0bb6c3
* Move network state to enums for type safety.Jeff Sharkey2013-01-121-10/+11
| | | | Change-Id: Ib8ea24fc58a866f8a5626cdd20e5891eb0a2bbeb
* Only add one User-Agent header.Jeff Sharkey2013-01-101-4/+9
| | | | | | | Also include more details when reporting HTTP error codes. Bug: 7966393 Change-Id: I251b1ec7c827693817391b6e9fb8b0cab995395e
* Simplify download flow control, handle redirects.Jeff Sharkey2013-01-091-98/+121
| | | | | | | | | | Move redirection handling into a single loop, and handle each HTTP response code inline to make flow control easier to reason about. Fix race condition in tests by waiting for first status update. Bug: 7887226 Change-Id: Id4bfd182941baad4cd0bb702376c4beeb7275bb2
* Clean up DownloadManager threading tests.Jeff Sharkey2013-01-081-2/+1
| | | | | | | | | | | Change runUntilStatus() methods to polling with timeout instead of requiring internal knowledge about threading. Fix notification tests, and move opening of InputStream until after handling headers to avoid FNFE. Always reset facade to defaults before each test. Change-Id: I6b2d6cfc4e685d2090c1133b1b2e89ae12760f8b
* Fold InnerState into State.Jeff Sharkey2012-12-201-47/+46
| | | | | | | It was cluttering up method signatures, and can easily be reset before starting each download pass. Change-Id: I7dee9d2160c3b5f737e7db86baa826d5d0b04b2d
* Always append to files, handle end of stream.Jeff Sharkey2012-12-171-30/+34
| | | | | | | | | | | | Fix bug where resumed downloads wouldn't open in append mode. Handle end of stream exceptions from URLConnection as special-case for now to keep tests passing. Move stream creation outside of DrmOutputStream, and always fsync() before closing files. Treat HTTP header errors as retryable. Add explicit state checks to redirection tests. Change-Id: I19d007284f6bfbffaac93859fe47cd98b79a59c4
* Cleaner I/O.Jeff Sharkey2012-12-131-91/+65
| | | | | | | | | | | | This cleans up writing of downloaded data by always writing through OutputStream interface, which applies DRM if needed. Hands I/O streams along with method calls to give clearer chain of ownership. Only retry writes once after verifying free space. Remove checkCanHandleDownload() check, since most downloads are now using public API. Release DrmManagerClient sessions when finished. Change-Id: I49e479089a8218690b556d31ec65a030930ad368
* Move DownloadManager to HttpURLConnection.Jeff Sharkey2012-12-121-265/+113
| | | | | | | | | | Apache HttpClient is in maintenance mode, and doesn't have support for features like Server Name Indication (SNI). This change moves DownloadManager to use HttpURLConnection internally. It also moves redirection handling into HttpURLConnection. Bug: 7070597 Change-Id: Ie80093eeeecd14f94e1c8b7597ff3f8f5d220691
* Improve download remaining time calculation.Jeff Sharkey2012-11-281-11/+2
| | | | | | | | | | | Calculate remaining time in DownloadNotifier so we always use the most recent progress data, which avoids showing stale times. Weight speed calculation to prefer historical data so remaining time is smoother on bumpy network connections. Bug: 7631948 Change-Id: I497be0899e65086356745340b19d3987c6185bdd
* Show remaining time in download notifications.Jeff Sharkey2012-11-141-1/+36
| | | | | | | | | | Calculate speed of in-progress downloads and estimate time remaining until completion. Uses a moving average that is weighted 1:1 with the most recent 500ms sample. Funnels timing data to notifications through DownloadHandler. Bug: 6777872 Change-Id: I9155f2979aa330bd1172f63bbfca1d053815cee5
* Better sanity checking for finished downloads.Jeff Sharkey2012-10-241-1/+15
| | | | | | | | | | | | | | | Downloads in the RUNNING state are considered ready to start so that downloads are correctly resumed when the process crashes. However, this causes a race condition while UpdateThread is processing a Cursor when a DownloadThread finishes. With this change, DownloadThread now skips requests for downloads already marked as finished. Apps listening for the DOWNLOAD_COMPLETE broadcast will no longer see data mutated by the second thread, and will not see the broadcast duplicated. Bug: 6948938, 6970458, 6818900 Change-Id: I35deac3cedbfe7f50091fab5818d85594dba558c
* Reduce deletion logging.Jeff Sharkey2012-07-201-6/+11
| | | | | Bug: 6544953 Change-Id: I4157c67b9b9cddab4ade795c328a202f6a230f95
* More slogging around download deletion.Jeff Sharkey2012-04-191-0/+8
| | | | | Bug: 6362988 Change-Id: Iab4b86cfcaa6aeed6466f88ff49eb935f96db495
* Add and enforce ALLOW_METERED column.Jeff Sharkey2012-04-171-4/+0
| | | | | | | | | | | | Include flag with each download to indicate if its allowed to proceed over metered networks. Downloads are left in WAITING_FOR_NETWORK state, similar to how ALLOWED_NETWORK_TYPES is handled. Also keep blocked downloads in WAITING_FOR_NETWORK state instead of marking them as failed. Bug: 3001465, 5734560 Change-Id: I80bb9aa9bd25ddf6f7a2472db344b6ba6878bd74
* Give DownloadManager a useful user agent.Jeff Sharkey2012-04-091-2/+0
| | | | | | | | Include platform version, model, and build, when available. Matches current logic used by Browser. Bug: 6257336 Change-Id: I0addfd944aff13bd4ce4226bb8d6328da6b0f5d5
* Move to new NetworkPolicyManager accessor.Jeff Sharkey2012-04-051-1/+1
| | | | Change-Id: I21e5f6280748529bad881942f8f5534aa374ba55
* Migrate to shared MockWebServer.Jeff Sharkey2012-03-291-1/+0
| | | | | Bug: 4726601 Change-Id: Ibe537bd5c2a092dbf974360cd454751881f7f4ea
* Match INetworkPolicyListener changes.Jeff Sharkey2012-02-071-8/+7
| | | | Change-Id: I78b6b0380a42b28f42334f93e0538ba7f32bc66d
* Update DownloadProvider for new Intent.normalizeMimeType() API.Nick Pelly2012-01-191-23/+3
| | | | Change-Id: Ideeb8cbeaa4b4d82d7c9fc8197a35bf3541a22d7
* Sanity check only after updating from file size.Jeff Sharkey2011-10-241-7/+7
| | | | | | | | Database values can be stale, so delay sanity check until after updating from file size on disk. Bug: 5484249 Change-Id: Ia648a575d4a3a391a1f06a866c8282f2d569f15e
* NPE check before finalizeDestinationFile().Jeff Sharkey2011-10-141-3/+5
| | | | | Bug: 5461417 Change-Id: I16f1e8594162b006b80bf7f2cdc6630d0dedfa38
* fix DownloadThread's use of ETag, range headersDoug Zongker2011-08-291-46/+54
| | | | | | | | | | | | | | | | | | DownloadThread was only maintaining ETag and the file size for the duration of one HTTP request, rather than over all the requests needed to fetch a file, which kind of defeats the point of having them. Fix this by moving several state variables from InnerState to State, and initializing the total bytes and current bytes values from the download database. Skip actually making the HTTP request if we've already downloaded all the bytes of the file. This works around bug 5217390 by making the second DownloadThread do nothing instead of trying to fetch past the end of the file. (A real fix would eliminate the race condition that causes the second thread to get created in the first place.) Bug: 5217390 Change-Id: Ib5b8f87398b4ed2cb3d7f09569e245b55a89da5a
* Migrate setThreadStatsTag() from String to int.Jeff Sharkey2011-06-251-1/+1
| | | | | Bug: 4948913 Change-Id: I831b9149208f0cc007cf3ebede3ef433b2636600
* Teach DownloadManager about network policy.Jeff Sharkey2011-06-171-19/+67
| | | | | | | | | | | Now network access is determined by using getActiveNetworkInfoForUid() which uses BLOCKED to indicate that network should be rejected for the requesting UID. While download in progress, watch for any policy changes that should trigger pause. Also check NetworkInfo.isConnected() for correctness. Change-Id: I1efa79823f15ecc3fa088a6719da1b770c64b255
* Merge "Download provider change for DRM Forward Lock plugin: to convert .dm ↵Gloria Wang2011-06-031-39/+30
|\ | | | | | | files to .fl files during downloading For bug 3188041"
| * Download provider change for DRM Forward Lock plugin:Gloria Wang2011-04-191-39/+30
| | | | | | | | | | | | | | to convert .dm files to .fl files during downloading For bug 3188041 Change-Id: I882b851664432fba3e57dc25a6be827b48006e69
* | Add Socket tagging for granular data accounting.Jeff Sharkey2011-05-131-5/+14
|/ | | | | | | | Tag active downloads, and account data usage towards UID that made the original request. Also release WakeLock only after we've cleaned up the download. Change-Id: I72d58c6a51beaeb357e59aae4d7c0f5ac9abaa8d
* am 32d9917c: am 7666801a: Merge "bug:4121206 handle STOPSHIP comments/code" ↵Vasu Nori2011-03-171-2/+0
|\ | | | | | | | | | | | | into honeycomb-mr1 * commit '32d9917cd4f56cabcbafa645c8cd89cd832ac523': bug:4121206 handle STOPSHIP comments/code
| * bug:4121206 handle STOPSHIP comments/codeVasu Nori2011-03-171-2/+0
| | | | | | | | Change-Id: I3c9f8e3b11dd301a0921d89e0333883489f37e55
* | (master) bug:3204324 allow no more than certain number of concurrent downloadsVasu Nori2011-03-101-6/+8
|/ | | | Change-Id: Ibbce0782fcf7649209d6f56be240209cebd9045b
* bug:3422868 collect additional info to debug this problemVasu Nori2011-02-101-1/+10
| | | | | | | this bug is not so easy to reproduce. so, this CL will produce some additional logging info for better insight Change-Id: I0d53c647f1b98a49eb93b937c8e7203723c33dbe
* bug:3435895 listen to media_mounted broadcast intentVasu Nori2011-02-081-0/+5
| | | | | | and retry downloads that failed due to the error "sdcard media not mounted" Change-Id: Id181b8167d331214f72679c85f18cc8b9b969e40
* am d47f3711: am 3ea897d9: Merge "bug:3396889 (HC branch) fix STOPSHIP code" ↵Vasu Nori2011-01-261-2/+1
|\ | | | | | | | | | | | | into honeycomb * commit 'd47f37112d4d0a95cd78e6ec3e14cbbb362b1595': bug:3396889 (HC branch) fix STOPSHIP code
| * bug:3396889 (HC branch) fix STOPSHIP codeVasu Nori2011-01-261-2/+1
| | | | | | | | Change-Id: I1eeb8c5a9936db08bc5997980dc6c7307691034e
* | bug:3062216 (master) store correct status about network when pausedVasu Nori2011-01-241-5/+9
|/ | | | | bug:3062216 Change-Id: I4d510a9fc2095ec86991ae657e90d5f39bc55415
* manual merge of GB change Change-Id: I1acf2fb9491d24f5e109206a91dda3eea429e447Vasu Nori2011-01-161-6/+5
| | | | Change-Id: Ibaf889d78fc99a32038a77671036fc6a5068580f
* bug:3338089 NPE in downloadthreadVasu Nori2011-01-111-2/+8
| | | | Change-Id: I95b4c52598092e9f6ffa1713b36ac11d44e26279