summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2014-10-28 00:45:43 +0000
committerandroid-build-merger <android-build-merger@google.com>2014-10-28 00:45:43 +0000
commit94a5718e1d7c4b8ab2bf4c6a45ed9f1be187ef4b (patch)
tree6a3a4d1ddad5ecfce965a2d09f16bdc661f19d66
parent5b2bfeee5257c6ec2952157343314eaea6fb86b3 (diff)
parentda9d77a478a2ab33ad81066012cab73b7c9dee3f (diff)
downloadandroid_packages_providers_DownloadProvider-94a5718e1d7c4b8ab2bf4c6a45ed9f1be187ef4b.tar.gz
android_packages_providers_DownloadProvider-94a5718e1d7c4b8ab2bf4c6a45ed9f1be187ef4b.tar.bz2
android_packages_providers_DownloadProvider-94a5718e1d7c4b8ab2bf4c6a45ed9f1be187ef4b.zip
Ensure that downloads stop quickly.
automerge: da9d77a * commit 'da9d77a478a2ab33ad81066012cab73b7c9dee3f': Ensure that downloads stop quickly.
-rw-r--r--src/com/android/providers/downloads/DownloadThread.java33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java
index aa0190bf..51e71b27 100644
--- a/src/com/android/providers/downloads/DownloadThread.java
+++ b/src/com/android/providers/downloads/DownloadThread.java
@@ -17,6 +17,7 @@
package com.android.providers.downloads;
import static android.provider.Downloads.Impl.STATUS_BAD_REQUEST;
+import static android.provider.Downloads.Impl.STATUS_CANCELED;
import static android.provider.Downloads.Impl.STATUS_CANNOT_RESUME;
import static android.provider.Downloads.Impl.STATUS_FILE_ERROR;
import static android.provider.Downloads.Impl.STATUS_HTTP_DATA_ERROR;
@@ -143,10 +144,7 @@ public class DownloadThread implements Runnable {
mETag = info.mETag;
}
- /**
- * Push update of current delta values to provider.
- */
- public void writeToDatabase() {
+ private ContentValues buildContentValues() {
final ContentValues values = new ContentValues();
values.put(Downloads.Impl.COLUMN_URI, mUri);
@@ -162,7 +160,26 @@ public class DownloadThread implements Runnable {
values.put(Downloads.Impl.COLUMN_LAST_MODIFICATION, mSystemFacade.currentTimeMillis());
values.put(Downloads.Impl.COLUMN_ERROR_MSG, mErrorMsg);
- mContext.getContentResolver().update(mInfo.getAllDownloadsUri(), values, null, null);
+ return values;
+ }
+
+ /**
+ * Blindly push update of current delta values to provider.
+ */
+ public void writeToDatabase() {
+ mContext.getContentResolver().update(mInfo.getAllDownloadsUri(), buildContentValues(),
+ null, null);
+ }
+
+ /**
+ * Push update of current delta values to provider, asserting strongly
+ * that we haven't been paused or deleted.
+ */
+ public void writeToDatabaseOrThrow() throws StopRequestException {
+ if (mContext.getContentResolver().update(mInfo.getAllDownloadsUri(),
+ buildContentValues(), Downloads.Impl.COLUMN_DELETED + " == '0'", null) == 0) {
+ throw new StopRequestException(STATUS_CANCELED, "Download deleted or missing!");
+ }
}
}
@@ -666,7 +683,7 @@ public class DownloadThread implements Runnable {
/**
* Report download progress through the database if necessary.
*/
- private void updateProgress(FileDescriptor outFd) throws IOException {
+ private void updateProgress(FileDescriptor outFd) throws IOException, StopRequestException {
final long now = SystemClock.elapsedRealtime();
final long currentBytes = mInfoDelta.mCurrentBytes;
@@ -697,7 +714,7 @@ public class DownloadThread implements Runnable {
// so we can always resume based on latest database information.
outFd.sync();
- mInfoDelta.writeToDatabase();
+ mInfoDelta.writeToDatabaseOrThrow();
mLastUpdateBytes = currentBytes;
mLastUpdateTime = now;
@@ -736,7 +753,7 @@ public class DownloadThread implements Runnable {
mInfoDelta.mETag = conn.getHeaderField("ETag");
- mInfoDelta.writeToDatabase();
+ mInfoDelta.writeToDatabaseOrThrow();
// Check connectivity again now that we know the total size
checkConnectivity();