summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/DownloadThread.java
diff options
context:
space:
mode:
authorGloria Wang <gwang@google.com>2011-02-16 11:58:51 -0800
committerGloria Wang <gwang@google.com>2011-04-19 15:16:47 -0700
commit0a17c2a28738d6ecb274def0e8e54f556d89f5f3 (patch)
tree7a253972d336b5ce0832344deae9cf06cfbb309d /src/com/android/providers/downloads/DownloadThread.java
parent21775dca6a8d39c2d46532a43d01fcfce795a2f2 (diff)
downloadandroid_packages_providers_DownloadProvider-0a17c2a28738d6ecb274def0e8e54f556d89f5f3.tar.gz
android_packages_providers_DownloadProvider-0a17c2a28738d6ecb274def0e8e54f556d89f5f3.tar.bz2
android_packages_providers_DownloadProvider-0a17c2a28738d6ecb274def0e8e54f556d89f5f3.zip
Download provider change for DRM Forward Lock plugin:
to convert .dm files to .fl files during downloading For bug 3188041 Change-Id: I882b851664432fba3e57dc25a6be827b48006e69
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 fbd3b82c..2e3543dc 100644
--- a/src/com/android/providers/downloads/DownloadThread.java
+++ b/src/com/android/providers/downloads/DownloadThread.java
@@ -21,14 +21,12 @@ 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.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;
@@ -56,6 +54,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) {
@@ -281,13 +280,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);
}
/**
@@ -295,6 +290,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();
@@ -332,30 +331,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) {
@@ -420,10 +395,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) {
@@ -433,6 +414,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);
+ }
}
}
}
@@ -527,6 +512,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,
@@ -852,8 +844,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);
}
}