summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/DownloadDrmHelper.java
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2012-12-06 15:54:44 -0800
committerJeff Sharkey <jsharkey@android.com>2012-12-13 15:42:32 -0800
commit5cff4ecb10e89e4fb39cd9e39b8753a31efbe3cc (patch)
tree9713a0f3b22fb5e025847acde2accba0a8a3b3fe /src/com/android/providers/downloads/DownloadDrmHelper.java
parent1244a63f799ab689a2d7d94415133be26580ae70 (diff)
downloadandroid_packages_providers_DownloadProvider-5cff4ecb10e89e4fb39cd9e39b8753a31efbe3cc.tar.gz
android_packages_providers_DownloadProvider-5cff4ecb10e89e4fb39cd9e39b8753a31efbe3cc.tar.bz2
android_packages_providers_DownloadProvider-5cff4ecb10e89e4fb39cd9e39b8753a31efbe3cc.zip
Cleaner I/O.
This cleans up writing of downloaded data by always writing through OutputStream interface, which applies DRM if needed. Hands I/O streams along with method calls to give clearer chain of ownership. Only retry writes once after verifying free space. Remove checkCanHandleDownload() check, since most downloads are now using public API. Release DrmManagerClient sessions when finished. Change-Id: I49e479089a8218690b556d31ec65a030930ad368
Diffstat (limited to 'src/com/android/providers/downloads/DownloadDrmHelper.java')
-rw-r--r--src/com/android/providers/downloads/DownloadDrmHelper.java58
1 files changed, 13 insertions, 45 deletions
diff --git a/src/com/android/providers/downloads/DownloadDrmHelper.java b/src/com/android/providers/downloads/DownloadDrmHelper.java
index 10cb792c..d1358246 100644
--- a/src/com/android/providers/downloads/DownloadDrmHelper.java
+++ b/src/com/android/providers/downloads/DownloadDrmHelper.java
@@ -19,7 +19,8 @@ package com.android.providers.downloads;
import android.content.Context;
import android.drm.DrmManagerClient;
-import android.util.Log;
+
+import java.io.File;
public class DownloadDrmHelper {
@@ -32,31 +33,6 @@ public class DownloadDrmHelper {
public static final String EXTENSION_INTERNAL_FWDL = ".fl";
/**
- * Checks if the Media Type is a DRM Media Type
- *
- * @param drmManagerClient A DrmManagerClient
- * @param mimetype Media Type to check
- * @return True if the Media Type is DRM else false
- */
- public static boolean isDrmMimeType(Context context, String mimetype) {
- boolean result = false;
- if (context != null) {
- try {
- DrmManagerClient drmClient = new DrmManagerClient(context);
- if (drmClient != null && mimetype != null && mimetype.length() > 0) {
- result = drmClient.canHandle("", mimetype);
- }
- } catch (IllegalArgumentException e) {
- Log.w(Constants.TAG,
- "DrmManagerClient instance could not be created, context is Illegal.");
- } catch (IllegalStateException e) {
- Log.w(Constants.TAG, "DrmManagerClient didn't initialize properly.");
- }
- }
- return result;
- }
-
- /**
* Checks if the Media Type needs to be DRM converted
*
* @param mimetype Media type of the content
@@ -83,28 +59,20 @@ public class DownloadDrmHelper {
}
/**
- * Gets the original mime type of DRM protected content.
- *
- * @param context The context
- * @param path Path to the file
- * @param containingMime The current mime type of of the file i.e. the
- * containing mime type
- * @return The original mime type of the file if DRM protected else the
- * currentMime
+ * Return the original MIME type of the given file, using the DRM framework
+ * if the file is protected content.
*/
- public static String getOriginalMimeType(Context context, String path, String containingMime) {
- String result = containingMime;
- DrmManagerClient drmClient = new DrmManagerClient(context);
+ public static String getOriginalMimeType(Context context, File file, String currentMime) {
+ final DrmManagerClient client = new DrmManagerClient(context);
try {
- if (drmClient.canHandle(path, null)) {
- result = drmClient.getOriginalMimeType(path);
+ final String rawFile = file.toString();
+ if (client.canHandle(rawFile, null)) {
+ return client.getOriginalMimeType(rawFile);
+ } else {
+ return currentMime;
}
- } catch (IllegalArgumentException ex) {
- Log.w(Constants.TAG,
- "Can't get original mime type since path is null or empty string.");
- } catch (IllegalStateException ex) {
- Log.w(Constants.TAG, "DrmManagerClient didn't initialize properly.");
+ } finally {
+ client.release();
}
- return result;
}
}