Many improvements to download storage management.
authorJeff Sharkey <jsharkey@android.com>
Thu, 30 Jan 2014 23:01:39 +0000 (15:01 -0800)
committerJeff Sharkey <jsharkey@android.com>
Thu, 6 Feb 2014 18:42:46 +0000 (10:42 -0800)
commitdffbb9c4567e9d29d19964a83129e38dceab7055
tree773bb59bc04f75e19e3a39acba06de574f75a385
parent9b731a5521f569c91aeb419d43fa098a34cf78cb
Many improvements to download storage management.

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
18 files changed:
AndroidManifest.xml
src/com/android/providers/downloads/Constants.java
src/com/android/providers/downloads/DownloadInfo.java
src/com/android/providers/downloads/DownloadProvider.java
src/com/android/providers/downloads/DownloadService.java
src/com/android/providers/downloads/DownloadThread.java
src/com/android/providers/downloads/Helpers.java
src/com/android/providers/downloads/StopRequestException.java
src/com/android/providers/downloads/StorageManager.java [deleted file]
src/com/android/providers/downloads/StorageUtils.java [new file with mode: 0644]
tests/AndroidManifest.xml
tests/src/com/android/providers/downloads/AbstractDownloadProviderFunctionalTest.java
tests/src/com/android/providers/downloads/AbstractPublicApiTest.java
tests/src/com/android/providers/downloads/FakeSystemFacade.java
tests/src/com/android/providers/downloads/HelpersTest.java
tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java
tests/src/com/android/providers/downloads/StorageTest.java [new file with mode: 0644]
tests/src/com/android/providers/downloads/ThreadingTest.java