summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/DownloadThread.java
Commit message (Collapse)AuthorAgeFilesLines
* Don't ignore COLUMN_MEDIA_SCANNED values from caller.Sudheer Shanka2019-01-291-6/+1
| | | | | | | | | | | | | | | | | | | | Right now, DownloadProvider only uses the COLUMN_MEDIA_SCANNED value if it is coming from addCompletedDownload and for the rest of the requests, it ignores the incoming COLUMN_MEDIA_SCANNED value and always invokes mediascanner. This is not what the documentation says. For e.g., if the caller uses DownloadManager.setDestinationUri() API, then unless otherwise specified, the download doesn't need to be mediascanned. Also, since we are inserting user visible downloads to MediaProvider, use that info to populate the COLUMN_MEDIAPROVIDER_URI column as well and update DownloadProvider to not invoke MediaScanner. Bug: 123440050 Test: atest DownloadProviderTests Test: atest cts/tests/app/src/android/app/cts/DownloadManagerTest.java Test: atest cts/tests/tests/provider/src/android/provider/cts/MediaStore* Change-Id: Ia667319a811d502d42a0602581bdc34ed46d88f7
* Use the network security config's cleartext settingsChad Brubaker2018-04-131-2/+3
| | | | | | | | | | Previously DownloadManager only respected the manifest attribute, this change makes DownloadManager handle both the manifest and the network security config Change-Id: I5666a1eea6278acc3864620a0e5a4c3ae37635b8 Fixes: 78028215 Test: atest CtsNetSecConfigDownloadManagerTestCases
* Merge "Add new no-op interface method." am: 726cb52790 am: 338dd4bda1Jeff Sharkey2018-01-191-1/+1
|\ | | | | | | | | | | am: 3a68c0ff91 Change-Id: If38cd52a3766aaadd43484ea1db58d74440b7428
| * Add new no-op interface method.Jeff Sharkey2018-01-181-1/+1
| | | | | | | | | | | | | | | | Test: bit FrameworksNetTests:android.net.,com.android.server.net. Test: bit FrameworksTelephonyTests:com.android.internal.telephony.dataconnection.DataConnectionTest Change-Id: Iebd6a6ad465f1b1d6678aefc3b146ea9bcd4b74e Exempt-From-Owner-Approval: trivial no-op overload Bug: 64133169
* | Move to NOT_ROAMING capability.Jeff Sharkey2017-11-091-4/+8
| | | | | | | | | | | | | | | | | | Checking new capability is perferred way to verify a network isn't roaming; isRoaming() is now deprecated. Test: bit DownloadProviderTests:* Bug: 68397798 Change-Id: I11d19fd5a389b52e199c604a6906423d405072e2
* | Use explicit Network from JobParameters.Jeff Sharkey2017-10-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | On devices with multiple active networks, or rapidly switching between networks, we need an API to tell jobs explicitly which network to use. (For example, the default route could meet all job criteria, but we could have changed the default network by the time we spun up the JobService.) Test: verified via DownloadManager Bug: 64133169 Change-Id: I9c131818d7199f79e147893d85c281473d00bee9
* | Prevent duplicate jobs for same download.Jeff Sharkey2017-09-281-2/+3
|/ | | | | | | | | | | Before this CL, we could have started duplicate jobs for the same download ID in parallel. Now, we ignore duplicate jobs for the same download. This requires us to only reschedule a job after removing it from mActiveThreads, so slight refactoring there. Test: bit DownloadProviderTests:* Bug: 36227864 Change-Id: I3103480859c5eb9488817165187c5dae05b2d843
* Allocate space using new StorageManager API.Jeff Sharkey2017-07-151-32/+15
| | | | | | | | | | | | | | Instead of reaching directly into PackageManager, use the new StorageManager API to allocate disk space for downloads. This wraps both clearing cached files and fallocate() into a single method. Remove support for storing downloads on the /cache partition, which doesn't exist on many devices. Bug: 63057877 Test: bit DownloadProviderTests:* Exempt-From-Owner-Approval: Bug 63673347 Change-Id: I5749f7a2f7ded9157fea763dc652bf4da88d86ff
* Follow removal of NetworkInfo metered flag.Jeff Sharkey2017-07-141-2/+2
| | | | | | | | | | The OS now completely relies on NET_CAPABILITY_NOT_METERED to avoid confusion and staleness. Bug: 63391323 Test: builds, boots, Wi-Fi policy is upgraded Exempt-From-Owner-Approval: Bug 63673347 Change-Id: Iea83e0afd8cbd2be10d85b8a35c903047716b5b9
* Only send DOWNLOAD_COMPLETE broadcast once.Jeff Sharkey2016-10-141-5/+0
| | | | | | | | | | | Apps might end up confused if we tell them a download was completed multiple times, so only send the broadcast exactly once when we transition it into a "completed" state, either during an update() or a delete() operation. Test: verified single broadcast with test app Bug: 31619480 Change-Id: I0b9139ea0e37f6d212b84314048692cd0c4f9cdf
* Fixed INetworkPolicyListener callbacks.Felipe Leme2016-08-241-9/+1
| | | | | | Change-Id: I0ac813875f73035c63d833294f85ee42306e8b95 Test: manual BUG: 28791717
* Send "completed" broadcast if download cancelled.Jeff Sharkey2016-08-231-1/+5
| | | | | | | | | | When a download is deleted, we may not have an active thread, so always send the broadcast from the provider. If an active thread encounters a deleted download, skip sending the broadcast twice. Change-Id: If8d5b99a1b7232bb64c6d11f22fdb4f5d6dbbfec Test: none Bug: 30883889
* Make scanning decisions based on latest data.Jeff Sharkey2016-06-251-2/+3
| | | | | | | | | When deciding to kick off a media scan of a newly-downloaded file, use the latest values from InfoDelta, instead of stale values from the last database read, which may lead us to skip the scan. Bug: 29234780 Change-Id: I7ffbcdd1edb9965999b7f5f100f57a9c2933f3a5
* Re-schedule downloads queued for unmetered.Jeff Sharkey2016-06-221-8/+12
| | | | | | | | | | When a download is stopped due to a metered network, we should reschedule the job just like any other network failure. If a download requires an unmetered network, treat WAITING_FOR_NETWORK as QUEUED_FOR_WIFI so we show a meaningful notification. Bug: 29440531 Change-Id: I31e6535c575fd32e2982ef840ae501acf1db3927
* Use calling app's Network Security Config for HTTPS downloadsChad Brubaker2016-06-201-0/+16
| | | | | Bug:29505888 Change-Id: Ifc33fd75e44d1dbc5a4ce5caa8e1ff938b94623e
* Implemented onRestrictBackgroundBlacklistChanged().Felipe Leme2016-05-161-0/+8
| | | | | | BUG: 28743623 Change-Id: I314febe06e5516dfa69062da691e0189b051dac5
* Removed onRestrictPowerChanged().Felipe Leme2016-05-101-6/+0
| | | | | | BUG: 28521946 Change-Id: I32129977c121b610bdd1a780fd371baaff3ead4b
* Implemented onRestrictPowerChanged().Felipe Leme2016-05-031-0/+6
| | | | | BUG: 28521946 Change-Id: I31658e680e67da9e1a420a9749a67949cfe09689
* Visible downloads should run while blocked/dozing.Jeff Sharkey2016-04-291-6/+17
| | | | | | | | | | | Downloads with visible notifications should behave as if the requesting app was running a foreground service. The easiest way to implement this for now is to ignore any BLOCKED network status and use the new setWillBeForeground() API so job scheduling ignores any active blocked/dozing status. Bug: 26571724 Change-Id: I8ea2b2a7cdb5f469adc11b4d897ff55bd8a9db9a
* Move DownloadManager to use JobScheduler.Jeff Sharkey2016-04-251-86/+96
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | JobScheduler is in a much better position to coordinate tasks across the platform to optimize battery and RAM usage. This change removes a bunch of manual scheduling logic by representing each download as a separate job with relevant scheduling constraints. Requested network types, retry backoff timing, and newly added charging and idle constraints are plumbed through as job parameters. When a job times out, we halt the download and schedule it to resume later. The majority of downloads should have ETag values to enable resuming like this. Remove local wakelocks, since the platform now acquires and blames our jobs on the requesting app. When an active download is pushing updates to the database, check for both paused and cancelled state to quickly halt an ongoing download. Shift DownloadNotifier to update directly based on a Cursor, since we no longer have the overhead of fully-parsed DownloadInfo objects. Unify a handful of worker threads into a single shared thread. Remove legacy "large download" activity that was thrown in the face of the user; the UX best-practice is to go through notification, and update that dialog to let the user override and continue if under the hard limit. Bug: 28098882, 26571724 Change-Id: I33ebe59b3c2ea9c89ec526f70b1950c734abc4a7
* Implemented onRestrictBackgroundWhitelistChanged().Felipe Leme2016-04-191-0/+6
| | | | | BUG: 27481520 Change-Id: I84db23b62f60dadefc01ead78f13ed689943baad
* Extra comments for multinetwork downloadingRobin Lee2016-04-081-0/+4
| | | | | Bug: 27074270 Change-Id: I7145fcdf0c8af0f0c299ca491f01eaef6204e2cb
* Implement multi-network downloadsRobin Lee2016-04-071-1/+9
| | | | | | | | | Downloads should use the default network for the caller. This prevents applications from, for example, bypassing VPN by routing all requests through the DownloadProvider. Bug: 27074270 Change-Id: I7830226dd2910757d3a5c78f373330f84637ccfa
* Remove chmod(0644) for finished downloads.Jeff Sharkey2016-03-211-6/+0
| | | | | | | | | | Now that PackageInstaller can read APKs from content:// Uris, we don't need to make downloads world-readable. This is mostly just cleanup, since our top-level private data directory is no longer o+x, so other apps can't traverse in anyway. Bug: 5464052 Change-Id: I45de6a40c28b85c64d5afbc13068fe3ae8341d93
* Make DownloadProvider honor the cleartext traffic policy.Alex Klyubin2015-04-011-0/+10
| | | | | | | | | | | | | | | | | | | This makes the Provider-side of the DownloadManager framework honor the per-UID cleartext network traffic policy. The policy is enforced in the Provider rather than in its client (DownloadManager) because download URLs could get redirected between HTTPS and HTTP and only the Provider currently has visibility into and control over this. Whether cleartext network traffic is permitted is a per-package policy. However, the DownloadProvider can only access the UID of the requesting application. Multiple packages can run under the same UID. In that scenario, cleartext traffic is permited for the UID if cleartext traffic is permitted for any of the packages running under the UID. This could be improved by making the DownloadManager provide the package name in addition to the UID. Bug: 19215516 Change-Id: Ib37585a7a2fc2869954d52a1b08052926f49bc9b
* 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