Merge change 8575
* changes: Support INSTALL_DRM permission
This commit is contained in:
@@ -35,7 +35,7 @@ import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* The DRM provider contains forward locked DRM content.
|
||||
*
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public final class DrmStore
|
||||
@@ -43,13 +43,13 @@ public final class DrmStore
|
||||
private static final String TAG = "DrmStore";
|
||||
|
||||
public static final String AUTHORITY = "drm";
|
||||
|
||||
|
||||
/**
|
||||
* This is in the Manifest class of the drm provider, but that isn't visible
|
||||
* in the framework.
|
||||
*/
|
||||
private static final String ACCESS_DRM_PERMISSION = "android.permission.ACCESS_DRM";
|
||||
|
||||
|
||||
/**
|
||||
* Fields for DRM database
|
||||
*/
|
||||
@@ -82,18 +82,18 @@ public final class DrmStore
|
||||
}
|
||||
|
||||
public interface Images extends Columns {
|
||||
|
||||
|
||||
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/images");
|
||||
}
|
||||
|
||||
|
||||
public interface Audio extends Columns {
|
||||
|
||||
|
||||
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/audio");
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function for inserting a file into the DRM content provider.
|
||||
*
|
||||
*
|
||||
* @param cr The content resolver to use
|
||||
* @param file The file to insert
|
||||
* @param title The title for the content (or null)
|
||||
@@ -101,12 +101,46 @@ public final class DrmStore
|
||||
*/
|
||||
public static final Intent addDrmFile(ContentResolver cr, File file, String title) {
|
||||
FileInputStream fis = null;
|
||||
OutputStream os = null;
|
||||
Intent result = null;
|
||||
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
DrmRawContent content = new DrmRawContent(fis, (int) file.length(),
|
||||
if (title == null) {
|
||||
title = file.getName();
|
||||
int lastDot = title.lastIndexOf('.');
|
||||
if (lastDot > 0) {
|
||||
title = title.substring(0, lastDot);
|
||||
}
|
||||
}
|
||||
result = addDrmFile(cr, fis, title);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "pushing file failed", e);
|
||||
} finally {
|
||||
try {
|
||||
if (fis != null)
|
||||
fis.close();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "IOException in DrmStore.addDrmFile()", e);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function for inserting a file stream into the DRM content provider.
|
||||
*
|
||||
* @param cr The content resolver to use
|
||||
* @param fileStream The FileInputStream to insert
|
||||
* @param title The title for the content (or null)
|
||||
* @return uri to the DRM record or null
|
||||
*/
|
||||
public static final Intent addDrmFile(ContentResolver cr, FileInputStream fis, String title) {
|
||||
OutputStream os = null;
|
||||
Intent result = null;
|
||||
|
||||
try {
|
||||
DrmRawContent content = new DrmRawContent(fis, (int) fis.available(),
|
||||
DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING);
|
||||
String mimeType = content.getContentType();
|
||||
|
||||
@@ -126,14 +160,6 @@ public final class DrmStore
|
||||
|
||||
if (contentUri != null) {
|
||||
ContentValues values = new ContentValues(3);
|
||||
// compute title from file name, if it is not specified
|
||||
if (title == null) {
|
||||
title = file.getName();
|
||||
int lastDot = title.lastIndexOf('.');
|
||||
if (lastDot > 0) {
|
||||
title = title.substring(0, lastDot);
|
||||
}
|
||||
}
|
||||
values.put(DrmStore.Columns.TITLE, title);
|
||||
values.put(DrmStore.Columns.SIZE, size);
|
||||
values.put(DrmStore.Columns.MIME_TYPE, mimeType);
|
||||
@@ -162,7 +188,7 @@ public final class DrmStore
|
||||
if (os != null)
|
||||
os.close();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "IOException in DrmTest.onCreate()", e);
|
||||
Log.e(TAG, "IOException in DrmStore.addDrmFile()", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +198,7 @@ public final class DrmStore
|
||||
/**
|
||||
* Utility function to enforce any permissions required to access DRM
|
||||
* content.
|
||||
*
|
||||
*
|
||||
* @param context A context used for checking calling permission.
|
||||
*/
|
||||
public static void enforceAccessDrmPermission(Context context) {
|
||||
@@ -181,5 +207,5 @@ public final class DrmStore
|
||||
throw new SecurityException("Requires DRM permission");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user