summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/DownloadThread.java
diff options
context:
space:
mode:
authorGloria Wang <gwang@google.com>2011-06-03 14:36:27 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-06-03 14:36:27 -0700
commit9356a4a9b1b1e5be9a3bd639cd89bb30aa6a5ae5 (patch)
treeca73fdc56dc900decb29980d03cb4f8778e3e8eb /src/com/android/providers/downloads/DownloadThread.java
parent9321f8656228b57f42549536512de684ce584a4d (diff)
parent0a17c2a28738d6ecb274def0e8e54f556d89f5f3 (diff)
downloadandroid_packages_providers_DownloadProvider-9356a4a9b1b1e5be9a3bd639cd89bb30aa6a5ae5.tar.gz
android_packages_providers_DownloadProvider-9356a4a9b1b1e5be9a3bd639cd89bb30aa6a5ae5.tar.bz2
android_packages_providers_DownloadProvider-9356a4a9b1b1e5be9a3bd639cd89bb30aa6a5ae5.zip
Merge "Download provider change for DRM Forward Lock plugin: to convert .dm files to .fl files during downloading For bug 3188041"
Diffstat (limited to 'src/com/android/providers/downloads/DownloadThread.java')
-rw-r--r--src/com/android/providers/downloads/DownloadThread.java69
1 files changed, 30 insertions, 39 deletions
diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java
index 082caa22..7ddfe959 100644
--- a/src/com/android/providers/downloads/DownloadThread.java
+++ b/src/com/android/providers/downloads/DownloadThread.java
@@ -21,7 +21,6 @@ import org.apache.http.conn.params.ConnRouteParams;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
-import android.drm.mobile1.DrmRawContent;
import android.net.http.AndroidHttpClient;
import android.net.Proxy;
import android.net.TrafficStats;
@@ -29,7 +28,6 @@ import android.os.FileUtils;
import android.os.PowerManager;
import android.os.Process;
import android.provider.Downloads;
-import android.provider.DrmStore;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
@@ -57,6 +55,7 @@ public class DownloadThread extends Thread {
private final DownloadInfo mInfo;
private final SystemFacade mSystemFacade;
private final StorageManager mStorageManager;
+ private DrmConvertSession mDrmConvertSession;
public DownloadThread(Context context, SystemFacade systemFacade, DownloadInfo info,
StorageManager storageManager) {
@@ -290,13 +289,9 @@ public class DownloadThread extends Thread {
* Called after a successful completion to take any necessary action on the downloaded file.
*/
private void finalizeDestinationFile(State state) throws StopRequestException {
- if (isDrmFile(state)) {
- transferToDrm(state);
- } else {
- // make sure the file is readable
- FileUtils.setPermissions(state.mFilename, 0644, -1, -1);
- syncDestination(state);
- }
+ // make sure the file is readable
+ FileUtils.setPermissions(state.mFilename, 0644, -1, -1);
+ syncDestination(state);
}
/**
@@ -304,6 +299,10 @@ public class DownloadThread extends Thread {
* the downloaded file.
*/
private void cleanupDestination(State state, int finalStatus) {
+ if (mDrmConvertSession != null) {
+ finalStatus = mDrmConvertSession.close(state.mFilename);
+ }
+
closeDestination(state);
if (state.mFilename != null && Downloads.Impl.isStatusError(finalStatus)) {
new File(state.mFilename).delete();
@@ -341,30 +340,6 @@ public class DownloadThread extends Thread {
}
/**
- * @return true if the current download is a DRM file
- */
- private boolean isDrmFile(State state) {
- return DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING.equalsIgnoreCase(state.mMimeType);
- }
-
- /**
- * Transfer the downloaded destination file to the DRM store.
- */
- private void transferToDrm(State state) throws StopRequestException {
- File file = new File(state.mFilename);
- Intent item = DrmStore.addDrmFile(mContext.getContentResolver(), file, null);
- file.delete();
-
- if (item == null) {
- throw new StopRequestException(Downloads.Impl.STATUS_UNKNOWN_ERROR,
- "unable to add file to DrmProvider");
- } else {
- state.mFilename = item.getDataString();
- state.mMimeType = item.getType();
- }
- }
-
- /**
* Close the destination output stream.
*/
private void closeDestination(State state) {
@@ -429,10 +404,16 @@ public class DownloadThread extends Thread {
}
mStorageManager.verifySpaceBeforeWritingToFile(mInfo.mDestination, state.mFilename,
bytesRead);
- state.mStream.write(data, 0, bytesRead);
- if (mInfo.mDestination == Downloads.Impl.DESTINATION_EXTERNAL
- && !isDrmFile(state)) {
- closeDestination(state);
+ if (!DownloadDrmHelper.isDrmConvertNeeded(mInfo.mMimeType)) {
+ state.mStream.write(data, 0, bytesRead);
+ } else {
+ byte[] convertedData = mDrmConvertSession.convert(data, bytesRead);
+ if (convertedData != null) {
+ state.mStream.write(convertedData, 0, convertedData.length);
+ } else {
+ throw new StopRequestException(Downloads.Impl.STATUS_FILE_ERROR,
+ "Error converting drm data.");
+ }
}
return;
} catch (IOException ex) {
@@ -442,6 +423,10 @@ public class DownloadThread extends Thread {
if (state.mStream != null) {
mStorageManager.verifySpace(mInfo.mDestination, state.mFilename, bytesRead);
}
+ } finally {
+ if (mInfo.mDestination == Downloads.Impl.DESTINATION_EXTERNAL) {
+ closeDestination(state);
+ }
}
}
}
@@ -536,6 +521,13 @@ public class DownloadThread extends Thread {
}
readResponseHeaders(state, innerState, response);
+ if (DownloadDrmHelper.isDrmConvertNeeded(state.mMimeType)) {
+ mDrmConvertSession = DrmConvertSession.open(mContext, state.mMimeType);
+ if (mDrmConvertSession == null) {
+ throw new StopRequestException(Downloads.Impl.STATUS_NOT_ACCEPTABLE, "Mimetype "
+ + state.mMimeType + " can not be converted.");
+ }
+ }
state.mFilename = Helpers.generateSaveFile(
mContext,
@@ -861,8 +853,7 @@ public class DownloadThread extends Thread {
}
}
- if (state.mStream != null && mInfo.mDestination == Downloads.Impl.DESTINATION_EXTERNAL
- && !isDrmFile(state)) {
+ if (state.mStream != null && mInfo.mDestination == Downloads.Impl.DESTINATION_EXTERNAL) {
closeDestination(state);
}
}