summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/Helpers.java
Commit message (Collapse)AuthorAgeFilesLines
* Fix race conditions around filename claiming.Jeff Sharkey2013-03-011-10/+20
| | | | | | | | | | | | | When multiple downloads are running in parallel, they can end up claiming the same filename and clobber over each other. This change introduces locking around filename generation, and touches the claimed filename so other threads fail the File.exists() check and keep looking. Tests to verify. Bug: 8255596 Change-Id: Ie75ed047c199cf679832c75159056ca036eac18d
* Retries shouldn't backoff when network changes.Jeff Sharkey2013-02-191-8/+0
| | | | | | | 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
* Tests for max retries/redirects, ETag switches.Jeff Sharkey2013-01-291-1/+1
| | | | | | | | | | 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
* Simplify download flow control, handle redirects.Jeff Sharkey2013-01-091-0/+3
| | | | | | | | | | 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
* Cleaner I/O.Jeff Sharkey2012-12-131-42/+0
| | | | | | | | | | | | 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-0/+3
| | | | | | | | | | 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
* Don't change extensions for explicitly set download locations.Jeff Davidson2011-08-301-8/+18
| | | | | | | | | | | | | | This regression from GB was introduced by 38f1711910715538d6b64e505fe8fb9a0cd40475, which was intended to allow duplicate downloads of the same file, adding -<n> to the end of file names. As a side effect, this also activated extension validation logic, which adds/changes an extension to match the Mimetype. This change keeps the unique filename logic but prevents extension changes when an explicit filename is set. Thus, it is still possible for the actual download location to differ from the requested one, but only if the file already exists. Bug: 5196436 Change-Id: I198dc2a819c5d839a05b72c25e0830d889a9c5a3
* Teach DownloadManager about network policy.Jeff Sharkey2011-06-171-2/+4
| | | | | | | | | | | 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-3/+6
|\ | | | | | | files to .fl files during downloading For bug 3188041"
| * Download provider change for DRM Forward Lock plugin:Gloria Wang2011-04-191-3/+6
| | | | | | | | | | | | | | to convert .dm files to .fl files during downloading For bug 3188041 Change-Id: I882b851664432fba3e57dc25a6be827b48006e69
* | Remove the deprecated things from Config.java. These havent been working ↵Joe Onorato2011-04-071-2/+1
|/ | | | | | since before 1.0. Change-Id: Iba18a18547a161c1aa432a434b6c8f64693fb194
* Adding HelpersTest.java for testing the download provider's helpers class. ↵olly2011-01-041-2/+2
| | | | | | Note - only a small fraction of input cases are currently tested. Change-Id: I830fff43cc283367a3534b7a3ffcc2a6d296e7c3
* bug:3286430 set quota on downloads data dirVasu Nori2010-12-231-207/+17
| | | | | | | | | | 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
* Fixing Helpers to correctly parse file names / extensions in the case where ↵olly2010-12-211-4/+4
| | | | | | | | the filename does not have a file extension but there are one or more dots in the parent directory names. e.g. /mnt/sdcard/Android/data/com.google.android.youtube/files/file Change-Id: I5aad1625a9f36135e947c0f929ee740fc66eb0d3
* fix a bug in one of the downloadmanager queriesVasu Nori2010-12-161-1/+1
| | | | Change-Id: Ie8148af67507bdc1d12307ce0d957343d2a28af0
* Download dir: /data/data/com.android.providers.downloads/cache NOT /cacheVasu Nori2010-12-141-15/+31
| | | | | | | | | | 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
* make sure filename is non-null before delting it.Vasu Nori2010-10-291-16/+0
| | | | | | | if a download fails for some reason, then filename could be null. move Helpers.deleteFile() code into private method in DownloadService Change-Id: Ifb12a84b6185e19c70d62392e102950c07f56a01
* when using DM public API, allow duplicate downloads of same fileVasu Nori2010-10-281-10/+12
| | | | | | | bug:3132790 this mimics the behavior that exists today (in non-public API) Change-Id: I722b3bc23fe8c9b0bf66a088c5f6a3130be2129f
* Merge 216736d2 from gingerbreadJean-Baptiste Queru2010-10-151-0/+16
|\ | | | | | | Change-Id: I404d1a66d337b1dade181ade92dc21fc0e819aa7
| * bug:3099994 NPE in DownloadManager when deleting non-media fileVasu Nori2010-10-151-0/+16
| | | | | | | | | | | | | | | | | | | | DownloadService always scans files and assumes MediaProvider returns a valid Uri. But MediaProvider returns null for return param 'uri' if the file is not audio/video/image etc media type file (for example, pdf) Change-Id: If32bd1895b00b5406973a5e240ad3558d46f9f4a
* | am d4dc8501: Merge "Seriously improve error reporting in DownloadThread." ↵Steve Howard2010-10-011-48/+39
|\| | | | | | | | | | | | | | | | | 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-48/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | am dc738781: Merge "Improve file error reporting + new detailed error ↵Steve Howard2010-09-201-62/+85
|\| | | | | | | | | | | | | | | | | messages in UI" into gingerbread Merge commit 'dc738781156d0f5ac1db62838d42c876d740810d' into gingerbread-plus-aosp * commit 'dc738781156d0f5ac1db62838d42c876d740810d': Improve file error reporting + new detailed error messages in UI
| * Improve file error reporting + new detailed error messages in UISteve Howard2010-09-201-62/+85
| | | | | | | | | | | | | | | | | | | | | | * support new error code for "destination file already exists" * improve error handling for various file error cases to return a more specific error code when appropriate * make UI support more detailed error messages for some cases * use Uri.getPath() instead of Uri.getSchemeSpecificPart() for file URIs Change-Id: Icb01d4d3b47c7776be3ddcd8347212e950cd023e
* | resolved conflicts for merge of 3d55d829 to gingerbread-plus-aospSteve Howard2010-09-161-2/+3
|\| | | | | | | Change-Id: I18ede2f2d5ad8aa40cd61bdb7213659d356fdf57
| * New URI structure with "my_downloads" and "all_downloads"Steve Howard2010-09-141-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change introduces a second view into the download manager database via a set of URIs starting with /all_downloads, renaming the original /download URIs to /my_downloads. In addition to making things more clear, this change allows the downloads UI to grant permissions on individual downloads to viewer apps. The old semantics were: * for ordinary callers, /download included only downloads initiated by the calling UID * for intraprocess calls or calls by root, /download included all downloads The new semantics are * /my_downloads always includes only downloads initiated by the calling UID, and requires only INTERNET permission. It could just as well require no permission, but that's not possible in the framework, since path-permissions can only broaden access, not tighten it. It doesn't matter, because these URIs are useless without INTERNET permission -- if a user can't initiate downloads, there's no reason to read this. * /all_downloads always includes all downloads on the system, and requires the new permission ACCESS_ALL_DOWNLOADS. This permission is currently protectionLevel=signature -- this could be relaxed later to support third-party download managers. All download manager code has been changed to use /all_downloads URIs, except when passing a URI to another app. In making this change across the download manager code, I've taken some liberties in cleaning things up. Other apps are unchanged and will use /my_downloads. Finally, this incorporates changes to DownloadManager to return a content URI for /cache downloads -- the download UI no longer assumes it's a file URI, and it grants permissions to the receiver of the VIEW intent. The public API test has also been updated. I've also fixed some null cursor checking in DownloadManager. Change-Id: I05a501eb4388249fe80c43724405657c950d7238
* | am 71e7fda9: Further work on the new downloads UI.Steve Howard2010-09-121-1/+1
|\| | | | | | | | | | | | | Merge commit '71e7fda9135a0915af1fd419d07ebf85ad09beb4' into gingerbread-plus-aosp * commit '71e7fda9135a0915af1fd419d07ebf85ad09beb4': Further work on the new downloads UI.
| * Further work on the new downloads UI.Steve Howard2010-09-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * add support for downloads not visible in the UI * add support for restarting failed downloads and downloads for which the file is missing * add "clear selection" button to selection menu * fix DateSortedExpandableListAdapter to ensure the view refreshes properly anytime the underlying data changes * make DownloadList handle when a selected download gets deleted by another app * make DownloadList close a dialog for a pending download when the download starts * show a dialog when the user tries to open a download but the file is missing * display "<Unknown>" when no title is provided for a download * add a test case for DownloadManager.orderBy() (should've gone in the previous commit) Change-Id: Ibf3062e8228e7f2c1270be24d8d5527dfb064658
* | am 89e4816f: Added support for downloading files with unicode charactersAndreas Sandblad2010-08-301-2/+52
|\ \ | |/ |/| | | | | | | | | Merge commit '89e4816fe5f06f4bc2c2fe0e38e63c7fbe468cd7' into gingerbread-plus-aosp * commit '89e4816fe5f06f4bc2c2fe0e38e63c7fbe468cd7': Added support for downloading files with unicode characters
| * Added support for downloading files with unicode charactersAndreas Sandblad2010-08-301-2/+52
| | | | | | | | | | | | | | | | | | | | | | Currently only certain ASCII characters are allowed in a filename, all other characters are replaced with an underscore. This gives bad usability for foreign languages (e.g. japanese). This fix replaces the current regexp with a method which replaces only those characters unsafe to be used on VFAT filesystems (should work on most other filesystems as well). Change-Id: I114d47b4b35f28490e6b12493138355532fda499
* | Clean up error codes returned by download manager.Steve Howard2010-08-161-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This set of changes cleans up the error codes returned by the download manager in various failure cases, aiming for improved consistency. Error codes are part of the public API so it's important to get this right now. The main changes here are: * Refactoring the flow of error status information throughout DownloadThread to make it more explicit, by having StopRequest accept a status code in its constructor and eliminating State.mFinaStatus. * Eliminating the use of valid HTTP 4xx statuses when those statuses weren't actually returned by the server. Now, if the returned error code is a valid HTTP status code, that means it was returned by the server. These cases have been replaced with more sensible artificial error codes, including a new ERROR_CANNOT_RESUME when an interrupted download can't be resumed. * Improvements to some of the error handling code paths -- ensuring we don't clear the cache for external downloads, ensuring we don't fail with CANNOT_RESUME when the download hasn't actually started yet, removing the restriction on acceptable mime types for public API downloads. Change-Id: I0d825845fe0fe7ed5df74bad26e8d34ac0d1cc4e
* | Fix bug with closing output stream for external downloads.Steve Howard2010-07-271-4/+3
| | | | | | | | | | | | | | | | I added a unit test to cover this, and it caught another issue with disallowing external destinations outside of the default downloads directory (which are now allowed with the new API). Change-Id: I4df6442bebb06458ad28c85f6bc8cbcbf3ce67a1
* | Make DownloadProvider accessible for public API usage.Steve Howard2010-07-221-7/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change removes the requirement that apps have the ACCESS_DOWNLOAD_MANAGER permission in order to access DownloadProvider. This enables the public API to work. Instead, DownloadProvider enforces the new permissions model for the public API: * insert() requires INTERNET permission * insert() checks that input fits within the restricted input allowed for the public API * insert() also strictly checks the file URI provided with DESTINATION_FILE_URI (and still requires WRITE_EXTERNAL_STORAGE permission if that is supplied) Note that if an app has the ACCESS_DOWNLOAD_MANAGER permission, legacy behavior is retained. I've added a test to cover this new access, and updated the existing permissions tests. I also fixed a bug in WHERE clause construction in update() and delete(), and refactored the code to eliminate duplication. Change-Id: I53a08df137b35c2788c36350276c9dff24858af1
* | Major refactoring of DownloadThread.run().Steve Howard2010-07-201-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Motivation: I need to fix the handling of 302s, so that after a disconnect, subsequent retries will use the original URI, not the redirected one. Rather than store extra information in the DB, I'd like to just keep the redirected URI in memory and make the redirected request within the same DownloadThread. This involves working with the large-scale structure of DownloadThread.run(). Since run() was a ~700 line method, I didn't feel comfortable making such changes. So this change refactors run() into a ~80 line method which calls into a collection of ~20 other short methods. The state previously kept in local variables has been pulled into a couple of state-only inner classes. The error-handling control flow, formerly handled by "break http_request_loop" statements, is now handled by throwing a "StopRequest" exception. The remaining structure of run() has been simplified -- the outermost for loop, for example, could never actually repeat and has been removed for now. Some other bits of code have been cleaned up a bit, but the functionality has not been modified. There are many good next steps to this refactoring. Besides various other cleanup bits, a major improvement would be to consolidate the State/InnerState classes, move some functionality to this new class (there are many functions of the form "void foo(State)" which would be good candidates), and promote it to a top-level class. But I want to take things one step at a time, and I think what I've got here is a major improvement and should be enough to allow me to safely implement the changes to redirection handling. In the process of doing this refactoring I added many test cases to PublicApiFunctionalTest to exercise some of the pieces of code I was moving around. I also moved some test cases from DownloadManagerFunctionalTest. Over time I'd like to move everything over to use the PublicApiFunctionalTest approach, and then I may break that into some smaller suites. Other minor changes: * use longs instead of ints to track file sizes, as these may be getting quite large in the future * provide a default DB value of -1 for COLUMN_TOTAL_BYTES, as this simplifies some logic in DownloadThread * small extensions to MockResponse to faciliate new test cases Change-Id: If7862349296ad79ff6cdc97e554ad14c01ce1f49
* | Support for max download size that may go over mobileSteve Howard2010-07-191-11/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change introduces support for a maximum download size that may go over a mobile connection. Downloads above this limit will wait for a wifi connection. To accomplish this, I moved a lot of the logic for checking connectivity info into DownloadInfo itself. I then moved the code to call these checks from DownloadService, where it would call the checks before spawning a DownloadThread, into DownloadThread itself. This makes it simpler to check connectivity after we get Content-Length info. It also eliminates the risk of a race condition where connectivity changes between the check and the actual request execution. I realize this change reduces efficiency, because we now call into ConnectivityManager/TelephonyManager twice per DownloadThread, rather than once per DownloadService "tick". I feel that it's OK since its a small amount of computation running relatively infrequently. If we feel that it's a serious concern, and that the efficiency issues outweigh the race problem, I can go easily back to the old approach. I've left out the code to actually fetch the limit. I think this will come from system settings, but I want to double-check, so I'll put it in a separate change. Other changes: * simplify SystemFacade's interface to get connectivity info - rather than returning all connected types, just return the active type, since that should be all we care about * adding @LargeTest to PublicApiFunctionalTest Change-Id: Id1faa2c45bf2dade9fe779440721a1d42cbdfcd1
* | Introduce a seam to ConnectivityManager and TelephonyManagerSteve Howard2010-07-151-47/+4
| | | | | | | | | | | | | | | | | | This change abstracts access to ConnectivityManager and TelephonyManager behind methods on SystemFacade, moving the code from Helpers into RealSystemFacade and adding fake implementations to FakeSystemFacade. This facilitates new connectivity tests. Change-Id: Id6c6b861e1d4ca45b3c1572bfb8ae0aa26af756b
* | Support for file URI destinations + last modified timestampSteve Howard2010-07-141-52/+94
| | | | | | | | | | | | | | | | | | | | | | | | | | File URI destinations: * permission checking in DownloadProvider * implementation in Helpers.generateSaveFile(). it's a fairly small amount of logic added here, but I did some significant method extraction to simplify this change and clean up the code in general. * added test case Last modified timestamp: * made DownloadProvider use a SystemFacade for getting system time, so I could properly test timestamps * updated test cases to cover last modified time + handle new ordering
* | Improve error message when SQL parser gets illegal characterSteve Howard2010-07-131-1/+1
|/ | | | Change-Id: Ife165361ebd75d558b311710e62abdfbdc355f1b
* b/2383073 Use new fine-grained download status codes.Attila Bodis2010-01-261-29/+36
| | | | | Takes advantage of two new download status codes (STATUS_DEVICE_NOT_FOUND_ERROR and STATUS_INSUFFICIENT_SPACE_ERROR) when reporting failed download attempts.
* Revert "Download files even if there is no activity to launch them."Leon Scroggins2010-01-221-0/+27
| | | | | | | This reverts commit 0f1aae327a9e4c68044d767e9bafbac747b6d985. I misunderstood the bug. We do not want to be able to download files for which there is currently no Activity to launch them.
* Download files even if there is no activity to launch them.Leon Scroggins2010-01-211-27/+0
| | | | Fixes http://b/issue?id=2367247
* Use the private legacy APIJean-Baptiste Queru2010-01-141-23/+23
| | | | | | | | | | The public API is getting deeply reworked for forward compatibility, but since the Download Manager and the Browser need to continue using the old API, a separate copy is being kept on the side. Bug: 2245521 Change-Id: I85eff6ba9efc68600aa80e8dffa6720b0f2ed155
* Merge commit 'f0fa1cdc' into manualmergeJean-Baptiste Queru2009-07-061-2/+2
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix crash in discardPurgeableFiles with proper selection syntax. The basic crash is that this codepath was doing a query to the download provider without properly quoting its selection arguments (which is mandated by the download provider). A secondary crash is that the DESTINATION column wasn't readable. This fixes bug 1941125. Tested by force-calling discardPurgeableFiles for each download to /cache, locally adding a few debugging statements to be sure that the codepath was getting executed, and doing a market download. Conflicts: src/com/android/providers/downloads/DownloadProvider.java src/com/android/providers/downloads/Helpers.java
| * Fix crash in discardPurgeableFiles with proper selection syntax.Jean-Baptiste Queru2009-07-021-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The basic crash is that this codepath was doing a query to the download provider without properly quoting its selection arguments (which is mandated by the download provider). A secondary crash is that the DESTINATION column wasn't readable. This fixes bug 1941125. Tested by force-calling discardPurgeableFiles for each download to /cache, locally adding a few debugging statements to be sure that the codepath was getting executed, and doing a market download.
| * auto import from //depot/cupcake/@135843The Android Open Source Project2009-03-031-0/+793
| |
| * auto import from //depot/cupcake/@135843The Android Open Source Project2009-03-031-793/+0
| |
| * auto import from //branches/cupcake/...@132276The Android Open Source Project2009-02-191-3/+2
| |
* | Optimize call to queryIntentActivities()Jean-Baptiste Queru2009-02-271-4/+2
| | | | | | | | | | | | | | | | Replace a call to queryIntentActivities() with a calls to resolveActivity(). This is done since the only purpose of the call is to check if the returned list is empty or non-empty. It's inefficient to move an entire list across the process boundary, only to discard it.
* | Use the new download manager APIs introduced in change 7400Jean-Baptiste Queru2009-01-211-4/+4
| |
* | Match the official code style guide.Jean-Baptiste Queru2009-01-201-4/+4
|/ | | | | | This fixes a number of style violations that weren't caught by automated tools and brings those files closer to compliance with the official style guide for this language.