FileDocCategorySizeDatePackage
DrmStore.javaAPI DocAndroid 1.5 API5964Wed May 06 22:41:56 BST 2009android.provider

DrmStore

public final class DrmStore extends Object
The DRM provider contains forward locked DRM content.
hide

Fields Summary
private static final String
TAG
public static final String
AUTHORITY
private static final String
ACCESS_DRM_PERMISSION
This is in the Manifest class of the drm provider, but that isn't visible in the framework.
Constructors Summary
Methods Summary
public static final android.content.IntentaddDrmFile(android.content.ContentResolver cr, java.io.File file, java.lang.String title)
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)
return
uri to the DRM record or null

    

                                                   
              
        FileInputStream fis = null;
        OutputStream os = null;
        Intent result = null;

        try {
            fis = new FileInputStream(file);
            DrmRawContent content = new DrmRawContent(fis, (int) file.length(),
                    DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING);
            String mimeType = content.getContentType();

            DrmRightsManager manager = manager = DrmRightsManager.getInstance();
            DrmRights rights = manager.queryRights(content);
            InputStream stream = content.getContentInputStream(rights);
            long size = stream.available();

            Uri contentUri = null;
            if (mimeType.startsWith("audio/")) {
                contentUri = DrmStore.Audio.CONTENT_URI;
            } else if (mimeType.startsWith("image/")) {
                contentUri = DrmStore.Images.CONTENT_URI;
            } else {
                Log.w(TAG, "unsupported mime type " + mimeType);
            }

            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);

                Uri uri = cr.insert(contentUri, values);
                if (uri != null) {
                    os = cr.openOutputStream(uri);

                    byte[] buffer = new byte[1000];
                    int count;

                    while ((count = stream.read(buffer)) != -1) {
                        os.write(buffer, 0, count);
                    }
                    result = new Intent();
                    result.setDataAndType(uri, mimeType);

                }
            }
        } catch (Exception e) {
            Log.e(TAG, "pushing file failed", e);
        } finally {
            try {
                if (fis != null)
                    fis.close();
                if (os != null)
                    os.close();
            } catch (IOException e) {
                Log.e(TAG, "IOException in DrmTest.onCreate()", e);
            }
        }

        return result;
    
public static voidenforceAccessDrmPermission(android.content.Context context)
Utility function to enforce any permissions required to access DRM content.

param
context A context used for checking calling permission.

        if (context.checkCallingOrSelfPermission(ACCESS_DRM_PERMISSION) !=
                PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException("Requires DRM permission");
        }