summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/DownloadThread.java
Commit message (Collapse)AuthorAgeFilesLines
* 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
* bug:3338089 print better error msg in DownloadThread when exception occursVasu Nori2011-01-101-4/+1
| | | | | | | when download thread gets an exception and aborts a download, print the stacktrace of the exception - so one can debug the problem. Change-Id: Iab1bae3b6180d8601e84020453ff35815ae3e69f
* Revert "Merge "downloadmanager should use "files" dir - not "cache" dir to ↵Vasu Nori2011-01-071-2/+2
| | | | | | | store its files" into honeycomb" This reverts commit 7d96bafa59111d9ca735e5ef86dc0598f946b2be, reversing changes made to 2ce876d2d7000b0c3a1430c5f4932568090f5170.
* downloadmanager should use "files" dir - not "cache" dir to store its filesVasu Nori2011-01-071-2/+2
| | | | | | | | | | | | | data/data/com.android.providers.downlaods/cache is being used to store the downloaded files, when the user doesn't specify the destination path. but system seems to remove files from this dir EVEN when space is running low. bug:3324673 instead, let DownloadManager use data/data/com.android.providers.downlaods/files dir Downlaodmanager manages its space anyway. Change-Id: I2eb15570395a214477891f50f635fada0b466544
* bug:3286430 set quota on downloads data dirVasu Nori2010-12-231-103/+99
| | | | | | | | | | make sure the doanloads data dir size is limited by some quote - 100MB default and 200MB for SR. bug:3286430 tests are in Change-Id: I688f7e058511089bec7fa21e972e23780604d98a Change-Id: Iba7fab9fa91ea018f35e1c3ef5ec0e6b03cba650
* Download dir: /data/data/com.android.providers.downloads/cache NOT /cacheVasu Nori2010-12-141-3/+5
| | | | | | | | | | bug:3264401 still to do: make sure only N bytes are taken up by downloads dir N = a value specific to each device. default = 100MB. Change-Id: I2a49f4b3831d3a8d7be13b5fd46d85d56e831e38
* manually merging Change-Id: If7dc0f86ea7a3c4394603416ca0fc33847f10fa7Vasu Nori2010-12-031-1/+1
| | | | | | need this CL from GB. without it, downloads are badly broken in master. Change-Id: I82ebc467f877bed50e373c437481ad19e14635bf
* am 084c3dc3: am 26f86843: Merge "(GB MR) bug:3144642 temporary small fix in ↵Vasu Nori2010-12-021-1/+1
|\ | | | | | | | | | | | | GB MR and real fix in HC" into gingerbread * commit '084c3dc34ed9e6ae9ddc471819de0d6d55021dfd': (GB MR) bug:3144642 temporary small fix in GB MR and real fix in HC
| * am 26f86843: Merge "(GB MR) bug:3144642 temporary small fix in GB MR and ↵Vasu Nori2010-12-021-1/+2
| |\ | | | | | | | | | | | | | | | | | | real fix in HC" into gingerbread * commit '26f86843f48b3d7878837a1a9f93865b3eba0aee': (GB MR) bug:3144642 temporary small fix in GB MR and real fix in HC
| | * (GB MR) bug:3144642 temporary small fix in GB MR and real fix in HCVasu Nori2010-12-021-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Real fix is in Change-Id: Ifea1544737023008eff44aef9acd976902a0c143 In the database, sometimes _data column in downloads is set to null and sometimes to empty string. this is inconsistent and causes bugs such as bug:3144642. This bug is caused by line# 793 in DownloadThread. state.mFileName is null sometimes and empty string sometimes - because the correspodning field is set inconsistentlt in downloads.db _data column. in GB MR, apply a bandaid because real fix could be too risky for GB. Change-Id: I115b3ba6cfe0262269dbbc4c336b9e1d63c618e4
* | | when a download fails, store the error msg in dbVasu Nori2010-11-111-8/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | useful for debugging for bugs like bug:3187299 without this error message, one doesn't know WHY downloads fail. to prevent PII info in database, there is a STOPSHIP comment around storage of this error message in database. Change-Id: I612e383aef8483b68b772f70dff722a5daea2ef5
* | | remove usage of hidden public constants.Vasu Nori2010-10-201-1/+0
|/ / | | | | | | Change-Id: I2edf1bef5e741de8193cb293807e3ace42003b0c
* | am d4dc8501: Merge "Seriously improve error reporting in DownloadThread." ↵Steve Howard2010-10-011-111/+84
|\| | | | | | | | | | | | | | | | | into gingerbread Merge commit 'd4dc8501ecb89b91f865510207297dd960afe031' into gingerbread-plus-aosp * commit 'd4dc8501ecb89b91f865510207297dd960afe031': Seriously improve error reporting in DownloadThread.
| * Seriously improve error reporting in DownloadThread.Steve Howard2010-09-301-111/+84
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | My old error reporting strategy for DownloadThread was to log the stack trace for the exception, so we'd know exactly what conditions caused the StopRequest. hackbod suggested that we shouldn't log tracebacks as they clutter the log. Instead, we should just always include a little string tag explaining why the request is being stopped -- this is more concise and more useful to developers. There are three main changes here to acheive this goal: * make StopRequest require a short, log-friendly error message upon construction, and add such a message to all construction sites * make a similar change to GenerateSaveFileError, so that the variety of errors that originate with Helpers.generateSaveFile() get similarly fine-grained and concise error reporting * make network usable checking code return a distinct error code for each distinct negative condition, and add a utility to return a log-friendly error message for each such code. Finally, I cleaned up some of the ways errors/exceptions are handled in the process. Change-Id: Ie70cbf3f2960e260e97f8449258e25218d0f900f