summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/DownloadThread.java
Commit message (Collapse)AuthorAgeFilesLines
* Can not continue to download after powering on the phoneBenson Huang2015-01-151-0/+1
| | | | | | | | | | | | | | | | | | | 1. Launch chrome and open www.baidu.com -> Choose "software" in the site navigation -> Tap "games" option, choose one apk to download -> During downloading, power off the phone -> Power on the phone and check, it can't continue to download apk. The fix is to add one condition for retrying to download when IO exception happens (i.e. Failed to open for writing: java.io.FileNotFoundException). Bug 18834618 Review: https://partner-android-review.git.corp.google.com/#/c/193436 Signed-off-by: Benson Huang <benson.huang@mediatek.com> Change-Id: I2f975ff7ffedfc4136fb250dcb5ef8fdca4a367d
* Connection: close is enough to know length.Jeff Sharkey2014-11-101-5/+9
| | | | | | | | Now that we're defeating connection reuse, we have one additional type of response where the length is known. Bug: 18306491 Change-Id: I19657c565238f07fd89a55a5dbf1e85748f6e7c3
* Defeat connection reuse to really cancel.Jeff Sharkey2014-11-071-0/+4
| | | | | | | | | Otherwise servers may continue streaming large downloads into the kept-alive socket. This changes to always close the socket, sending a clear signal to server. Bug: 16153076 Change-Id: I3e7fefce4f82b5f80abaab58874cc4c4374d2bfb
* Ensure that downloads stop quickly.Jeff Sharkey2014-10-271-8/+25
| | | | | | | | | | In some cases the provider may have marked a download as deleted, but the content change notification may lag several seconds. To stop as soon as possible, assert that we're not deleted when writing our progress updates. Bug: 16405936 Change-Id: I994b746056d0427c626355e0815234ff5b73198c
* fallocate() returning ENOSYS is okay.Jeff Sharkey2014-08-261-2/+2
| | | | | | | Fall back just like ENOTSUP. Bug: 17285472 Change-Id: Ice4954726c14a0e84c39c5469d573644588934ae
* OsConstants is moving.Elliott Hughes2014-04-291-2/+1
| | | | Change-Id: Ie72e18f539cbad593c489bf52b9afea5330f62c1
* Move internal DownloadProvider code off libcore.os.Elliott Hughes2014-04-281-10/+10
| | | | | | (As much as possible. There are no plans to make the mocking API public.) Change-Id: I348877b850d6d34572d5a19e67952254bc4f12ef
* Add idle service to clean orphan downloads.Jeff Sharkey2014-02-061-0/+1
| | | | | | | | | | | | Periodically reconcile database against disk contents. This handles the case where a user/app deletes files directly from disk without updating the database, and the rare case where a database delete didn't make it to deleting the underlying file. Also cleans up any downloads belonging to a UID when removed. Bug: 12924143 Change-Id: I4899d09df7ef71f2625491ac01ceeafa8a2013ce
* Many improvements to download storage management.Jeff Sharkey2014-02-061-480/+406
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change all data transfer to occur through FileDescriptors instead of relying on local files. This paves the way for downloading directly to content:// Uris in the future. Rewrite storage management logic to preflight download when size is known. If enough space is found, immediately reserve the space with fallocate(), advising the kernel block allocator to try giving us a contiguous block regions to reduce fragmentation. When preflighting on internal storage or emulated external storage, ask PackageManager to clear private app caches to free up space. Since we fallocate() the entire file, use the database as the source of truth for resume locations, which requires that we fsync() before each database update. Store in-progress downloads in separate directories to keep the OS from deleting out from under us. Clean up filename generation logic to break ties in this new dual-directory case. Clearer enforcement of successful download preconditions around content lengths and ETags. Move all database field mutations to clearer DownloadInfoDelta object, and write back through single code path. Catch and log uncaught exceptions from DownloadThread. Tests to verify new storage behaviors. Fixed existing test to reflect correct RFC behavior. Bug: 5287571, 3213677, 12663412 Change-Id: I6bb905eca7c7d1a6bc88df3db28b65d70f660221
* Revert "change download provider to use system log"Doug Zongker2014-01-271-18/+18
| | | | | This reverts commit 4f9d2d04003fafb358d7c127054055b3a9732c9b, was only wanted for debugging.
* change download provider to use system logDoug Zongker2014-01-271-18/+18
| | | | | | | | Try to catch the download provider in the act of deleting pending system updates. Bug: 12680933 Change-Id: If58aba5c30fd624217e5d073730645af05e98ac7
* 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