summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* Clean up error codes returned by download manager.Steve Howard2010-08-164-99/+112
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Extend PublicApiAccessTest to exercise DownloadManager.Steve Howard2010-08-162-0/+28
| | | | | | | | | This change adds a new test case to PublicApiAccessTest to enqueue a request through DownloadManager, ensuring that the values constructed by DownloadManager fit within the allowed bounds. It also fixes a bug with allowing http header values exposed by the new test. Change-Id: I94fec57d7a41298ac42ddaab338516e6a60c4e75
* Import revised translations. DO NOT MERGEEric Fischer2010-08-1020-40/+120
| | | | Change-Id: Ib2ce8f6ee48925ab4371c39266ef4696cb812f91
* Merge "Make all public API downloads visible." into gingerbreadSteve Howard2010-08-065-24/+58
|\
| * Make all public API downloads visible.Steve Howard2010-07-285-24/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change makes all downloads through the public API visible by default. It removes the API that had allowed applications to control notifications while the download runs. This has been replaced with a hidden API, since such behavior is needed by SystemUpdater and Market (for self-updates). Additionally, the behavior is now protected by a new permission. I'm making this permission signatureOrSystem, and changing the non-purgeable permission to the same (it should've been that, I just didn't know). I'm also adding string descriptions to appease the translation folks. Change-Id: I192e8b19ff9b0e425257cef0db081c3d75996ea5
* | Import revised translations. DO NOT MERGEEric Fischer2010-08-0420-0/+80
|/ | | | Change-Id: Ic6f84636b3bbb635ecc790711ba5828dd094f878
* Get wifi limit from secure settings.Steve Howard2010-07-285-7/+14
| | | | Change-Id: I750654c28cb3d9f9aa67bd56e4d8d770dbfde4b4
* Add test for many interruptions to a single download.Steve Howard2010-07-273-103/+94
| | | | | | | | | | | | | | | Adding a new test case for downloads that undergo many interruptions (as may happen with a very large download that takes many hours). Includes some refactoring in the test suite. Early on, this test exposed a race condition in which the download manager got some I/O exception while reading from the MockWebServer. I went in and improved/refactored much of the error logging code in DownloadThread to try and track this down. Unfortunately, once I finished, the race condition no longer seems to be reproducible, even with hundreds of runs of the test case. So I've given up on it for now. In any event, error logging is better and much duplicate code has been eliminated.
* Improved support for 302/307 redirects.Steve Howard2010-07-272-69/+94
| | | | | | | | | | | | | | | | | Change the download manager's handling of 302/307 temporary redirects so that after an interruption of any kind, the delayed retry/resume will return to the original URI. This complies better with the HTTP spec. This change also makes the download manager handle other redirects immediately rather than using the delay that's otherwise applied to download errors. I made one more method extraction in DownloadThread to simplify this change, pulling the top-level logic for a single request into executeDownload(). It was then just a matter of introducing a new RetryDownload exeception, similar to StopRequest, and making the redirection code use it. Change-Id: Ic719c5725a9fd2e5eebe4dc03453ee71d9f27cd4
* Fix bug with closing output stream for external downloads.Steve Howard2010-07-273-5/+19
| | | | | | | | 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
* Serialize threading for download manager testing.Steve Howard2010-07-2710-264/+269
| | | | | | | | | | | | | | | | | | | | | | | | | | | The download manager uses threading in a simple way -- it launches two threads, UpdateThread and DownloadThread, and both are "fire and forget". This is fortunate for testing, since it means we can eliminate multithreading and simply run each thread in order, and everything still works. This change does just that, abstracting Thread.start() behind SystemFacade and making FakeSystemFacade put new threads into a queue and then run through them serially. This simplifies much of the test code and makes it all much more predictable. I've simplified the test code as much as possible here and moved a few more tests over to PublicApiFunctionalTest, leaving only a minimum in DownloadManagerFunctionalTest, which will eventually be deleted altogether. I've also improved testing in some areas -- for example, we can now test that running notifications get cancelled after the download completes in a robust way. There is one test case that checks for race conditions and requires multithreading. I've moved this into a new ThreadingTest class, which uses a custom FakeSystemFacade that allows multithreading. I've extracted AbstractPublicApiTest for the newly shared code. Change-Id: Ic1d5c76bfa9913fe053174c3d8b516790ca8b25f
* Stub out and test system notifications.Steve Howard2010-07-238-23/+103
| | | | | | | | | | | | | This change abstracts NotificationManager interactions behind SystemFacade and takes advantage of that to test notifications, to a limited degree. It also fixes a silly typo in AbstractDownloadManagerFunctionalTest, and it introduces an extra sleep between tests to avoid some flakiness. I'll look for a better solution to that problem after this change goes in. Change-Id: I3a0307f828955cd45b0e3581ad499da28cc0556e
* Test + utilize change notification in DownloadProviderSteve Howard2010-07-232-6/+54
| | | | | | | | | Now that I've learned how ContentResolver.notifyChange() works, add a test to explicitly check it's being called in DownloadProvider, and take advantage of it in waitForDownloadToStop to get rid of the ugly old polling mechanism. Change-Id: Iba71bdf1b0d31454cc4e186ceb4fdd9fdb5faad5
* Support for non-purgeable downloads through the public API.Steve Howard2010-07-233-5/+31
| | | | | | | | | | | This change adds a permission, android.permission.DOWNLOAD_CACHE_NON_PURGEABLE. When an app has this permission, any downloads it requests through the public API to the download cache will automatically become non-purgeable, i.e. they'll never be automatically deleted by the download manager to free up space. This is intended for use only by the system updater. Change-Id: I35cdd44f7e5d46bc70443d1a9743f61a51395ddb
* Make DownloadProvider accessible for public API usage.Steve Howard2010-07-227-67/+311
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* Make COLUMN_URI readable and tighten UID restrictions.Steve Howard2010-07-212-39/+15
| | | | | | | | | | | | I need to make COLUMN_URI readable by apps, since the public API exposes that field. In order to avoid any possible security issues, I got rid of the feature that potentially allowed apps to view downloads from other UIDs. No one was using that feature and the public API exposes no such feature (yet). While at it, I cleaned up some related code in update() and delete(). Change-Id: I5384115d2a865255d009fbe37449488fd2269389
* Public API support for broadcasts and connectivity control.Steve Howard2010-07-219-27/+268
| | | | | | | | | | | | | | | | * Three new DB fields, one indicating whether a download was initiated by the public API or not, two to hold connectivity control info. DB migration to add these fields and code in DownloadProvider.insert() to handle them. * Change broadcast intent code to match public API spec, for public API downloads only. (Legacy code can go away once existing clients are converted over to the new API.) * Introduce SystemFacade methods for sending broadcasts and checking package ownership; this facilitates new tests of broadcast code. * Change DownloadInfo.canUseNetwork() to obey new connectivity controls available in public API, but again, retain legacy behavior for downloads initiated directly through DownloadProvider * New test cases to cover the new behavior Also made a couple changes to reduce some test flakiness I was observing: * in tearDown(), wait for any running UpdateThread to complete * in PublicApiFunctionalTest.setUp(), if the test directory already exists, remove it rather than aborting DB changes for broadcast + roaming support Change-Id: I60f39fc133f678f3510880ea6eb9f639358914b4
* Major refactoring of DownloadThread.run().Steve Howard2010-07-208-677/+876
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Fix bug with deciding when to restart a download.Steve Howard2010-07-203-21/+36
| | | | | | | | | | | | | | In previous refactoring I had combined the code for starting a download (from DownloadService.insertDownload()) and restarting a download (from DownloadService.updateDownload()). I'd missed the fact that the former checks DownloadInfo.isReadyToStart() while the latter checks DownloadInfo.isReadyToRestart(). This cause a race condition where multiple startService() calls during a download would cause the service to try to spawn a second thread for the same running download. I've fixed the bug and added a test case to exercise this. Change-Id: Ia968331a030137daac7c8b5792a01e3e19065b38
* Support for max download size that may go over mobileSteve Howard2010-07-198-128/+139
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Merge "Introduce a seam to ConnectivityManager and TelephonyManager" into ↵Steve Howard2010-07-1911-228/+145
|\ | | | | | | gingerbread
| * Introduce a seam to ConnectivityManager and TelephonyManagerSteve Howard2010-07-1511-228/+145
| | | | | | | | | | | | | | | | | | 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
* | Revert "fix permissons/targets in download provider tests"Guang Zhu2010-07-162-2/+3
|/ | | | This reverts commit c7717b4d1e6cf51ab8d8de03fe23dcad2dc97f52.
* Merge "Support for custom HTTP headers on download requests" into gingerbreadSteve Howard2010-07-155-175/+295
|\
| * Support for custom HTTP headers on download requestsSteve Howard2010-07-155-175/+295
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Provider changes: * new many-to-one DB table holding headers for each download. since there was no real migration logic in DownloadProvider, I implemented some. * DownloadProvider.insert() reads request headers out of the ContentValues and puts them into the new table * DownloadProvider.query() supports a new URI form, download/#/headers, to fetch the headers associated with a download * DownloadProvider.delete() removes request headers from this table Service changes: * made DownloadInfo store request headers upon initialization. While I was at it, I refactored the initialization logic into DownloadInfo to get rid of the massive 24-parameter constructor. The right next step would be to move the update logic into DownloadInfo and merge it with the initialization logic; however, I realized that headers don't need to be updatable, and in the future, we won't need the update logic at all, so i didn't bother touching the update code. * made DownloadThread read headers from the DownloadInfo and include them in the request; merged the custom Cookie and Referer logic into this logic Also added a couple new test cases for this stuff. Change-Id: I421ce1f0a694e815f2e099795182393650fcb3ff
* | Merge "fix permissons/targets in download provider tests" into gingerbreadGuang Zhu2010-07-152-3/+2
|\ \
| * | fix permissons/targets in download provider testsGuang Zhu2010-07-152-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | * permission tests package should be signed with the same cert as download provider itself * permission tests should not target on itself Change-Id: Ic4307119ed6c41cbffd98fe165ebc360e2b38c8e
* | | Cleanup whitespace in DownloadNotificationSteve Howard2010-07-151-24/+24
| |/ |/| | | | | Change-Id: I598ece9690649573d44d3089e473612e25f2974b
* | Support for file URI destinations + last modified timestampSteve Howard2010-07-144-64/+170
|/ | | | | | | | | | | | | 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
* New functional test for download manager public API.Steve Howard2010-07-133-246/+535
| | | | | | | | | | I refactored a lot of the logic from DownloadManagerFunctionalTest into a new abstract class so that it could be shared with the new PublicApiFunctionalTest. There could be even more sharing, but it's not entirely clear it'd be worthwhile at this point. The new test covers most features of the new public API. Change-Id: I8c6859411f44b6430f8b348cf26a61225f5768cb
* Change AnimatedImageViews to ImageViews.Steve Howard2010-07-011-2/+2
| | | | | | | The AnimatedImageView class was private and should not have been used. When it was removed, the decision was made to change these to unanimated images. The first frame will show, which should be good enough, and it'll safe a bit of CPU.
* Stub out the system clock in the download manager, add testsSteve Howard2010-07-018-69/+181
| | | | | | | | | | | | | | Introduce SystemFacade, an interface that allows us to stub out the system clock for testing the download manager. This allows us to test retrying a failed download without having the test wait 60 seconds. This interface can include other dependencies in the future as well. I've also used this to add tests for 503 (retry-after) and 301 (redirect), and I've added a test for download to the cache partition. Other changes: * made MockWebServer capable of checking + rethrowing exceptions from child threads * refactoring + cleanup of DownloadManagerFunctionalTest
* Fix build in master - new method in FakeIConnectivityManagerSteve Howard2010-06-291-0/+4
| | | | Change-Id: I76996b9a7b6d0f725480cacb1da032cec2dade0b
* First pass at a functional test for the Download Manager.Steve Howard2010-06-287-27/+648
| | | | | | | | | | | | | | | | | | | | | This "Large" test sets up an HTTP server on the device using MockWebServer and then initiates downloads from that server through the download manager. It uses ServiceTestCase to control the construction and execution of the DownloadService, and it uses some logic from ProviderTestCase2 to construct a DownloadProvider and a ContentResolver that uses it. This setup gives us some ability to mock dependencies. This commit includes use of a fake ConnectivityManager to test responses to connectivity changes, and use of some customizations to MockWebServer to test resuming an interrupted download. This test is disabled, though, since it requires a very long sleep. Avoiding that, and achieving certain other things, will require changes to the Download Manager code itself to introduce new seams. I wanted to check this in before I started such changes. Change-Id: Iefb13b3c3cccdc13fabe5cc18703e13244805539
* am 8fed41c3: Merge "Don\'t inadvertantly include tests in the build." into ↵Steve Howard2010-06-211-1/+2
|\ | | | | | | | | | | | | | | | | kraken Merge commit '8fed41c37e52a3e186e8f36b18a0b6433278acd3' into gingerbread * commit '8fed41c37e52a3e186e8f36b18a0b6433278acd3': Don't inadvertantly include tests in the build.
| * Merge "Don't inadvertantly include tests in the build." into krakenSteve Howard2010-06-211-1/+2
| |\
| | * Don't inadvertantly include tests in the build.Steve Howard2010-06-211-1/+2
| | | | | | | | | | | | Change-Id: Ic57f0b66dd81da1b6acc7132f792b024e974f74c
* | | am 4c54154c: Check in copies of MockWebServer + friends.Steve Howard2010-06-213-0/+486
|\| | | | | | | | | | | | | | | | | | | | Merge commit '4c54154c83a5b3516d81903140b31349f196cbe2' into gingerbread * commit '4c54154c83a5b3516d81903140b31349f196cbe2': Check in copies of MockWebServer + friends.
| * | Check in copies of MockWebServer + friends.Steve Howard2010-06-213-0/+486
| |/ | | | | | | | | | | | | | | | | | | This commit includes unmodified copies of MockWebServer and its supporting classes, taken from dalvik-dev:libcore/support/src/tests/java. My test will require some changes, but I'm committing unchanged versions first so I can more easily track my changes and eventually merge them back over. Change-Id: Ic4b79c7a2cbd3bd439864ed94c43fe985eae8e78
* | am 09330001: Import revised translationsKenny Root2010-06-212-6/+6
|\ \ | |/ |/| | | | | | | | | Merge commit '09330001cc50f8a5ffe2ef527dbb5729080f52e2' into gingerbread * commit '09330001cc50f8a5ffe2ef527dbb5729080f52e2': Import revised translations
| * Import revised translationsKenny Root2010-06-202-6/+6
| | | | | | | | Change-Id: I012450adc3ff91ce5cfbd28e21eed1aa6833c56f
* | merge from open-source masterThe Android Open Source Project2010-05-101-1/+13
|\ \ | |/ |/| | | Change-Id: If84d4054324db6d10fd0cdbd2169c039c6675726
| * code left opened files behindusul2010-05-101-1/+13
| | | | | | | | | | | | | | verified with lsof DownloadProvider after downloading a file shows: ${proc} 338 10034 33w REG 179,0 167634 5 /sdcard/download/fw4-1.pdf Change-Id: I8e2412fe9a6348f5ece6f5ca3a9ebf99a4474bce
| * Merge "Show correct date for downloads in the statusbar"Jean-Baptiste Queru2010-05-101-2/+1
| |\
| | * Show correct date for downloads in the statusbarPer Edelberg2010-02-101-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The date was not set properly in notifications when the text for expanded view was created. This fix sets the displayed time to the download time for each individual file. The DownloadProvider recreates the notifications several times but don't set the time before the expanded message is created. The expanded message will therefore display the time the notification was created and not the time a file was downloaded. The displayed time will in most case be the time when the last file was downloaded. This fix sets the displayed time to the downloaded time for each individual file.
* | | Import revised translationsKenny Root2010-04-274-6/+6
| | | | | | | | | | | | Change-Id: I800cdf6e7d34180e13d7af74abfe0887e1f20316
* | | Adjust DownloadProvider's makefile so its tests get built.Brett Chabot2010-04-051-0/+3
| | | | | | | | | | | | | | | | | | Bug 2562721 Change-Id: I7dfd73d4e30fcc5dc80c9ed024432c0b833a011a
* | | Import revised translationsKenny Root2010-03-1720-40/+60
| | | | | | | | | | | | Change-Id: Iac9bc801179d35cf266b6398c2c6557f5abc524e
* | | Add an empty CleanSpec.mkJean-Baptiste Queru2010-03-081-0/+49
| | | | | | | | | | | | Change-Id: Idbb6ff1607b2885ed2da0749fc99b39f815fac15