FileDocCategorySizeDatePackage
DrmRawContent.javaAPI DocAndroid 1.5 API13685Wed May 06 22:42:00 BST 2009android.drm.mobile1

DrmRawContent

public class DrmRawContent extends Object
This class provides interfaces to access the DRM raw content.

Fields Summary
public static final String
DRM_MIMETYPE_MESSAGE_STRING
The "application/vnd.oma.drm.message" mime type.
public static final String
DRM_MIMETYPE_CONTENT_STRING
The "application/vnd.oma.drm.content" mime type.
public static final int
DRM_FORWARD_LOCK
The DRM delivery type: Forward-Lock
public static final int
DRM_COMBINED_DELIVERY
The DRM delivery type: Combined Delivery
public static final int
DRM_SEPARATE_DELIVERY
The DRM delivery type: Separate Delivery
public static final int
DRM_SEPARATE_DELIVERY_DM
The DRM delivery type: Separate Delivery in DRM message
public static final int
DRM_UNKNOWN_DATA_LEN
The DRM media content length is unknown currently
private static final int
DRM_MIMETYPE_MESSAGE
The id of "application/vnd.oma.drm.message" mime type.
private static final int
DRM_MIMETYPE_CONTENT
The id of "application/vnd.oma.drm.content" mime type.
private static final int
JNI_DRM_SUCCESS
Successful operation.
private static final int
JNI_DRM_FAILURE
General failure.
private static final int
JNI_DRM_EOF
Indicates the end of the DRM content is reached.
private static final int
JNI_DRM_UNKNOWN_DATA_LEN
The media content length is unknown from native method
private BufferedInputStream
inData
The member to save the original InputStream data.
private int
inDataLen
The member to save the original InputStream data length.
private int
id
The unique id to this DRM content. It will be initialized in constructor by native method. And it will not be changed after initialization.
private String
rightsIssuer
The rights issuer address of this DRM object.
private String
mediaType
The media content type of this DRM object.
private int
rawType
The delivery method type of this DRM object.
Constructors Summary
public DrmRawContent(InputStream inRawdata, int len, String mimeTypeStr)
Construct a DrmRawContent object.

param
inRawdata object of DRM raw data stream.
param
len the length of raw data can be read.
param
mimeTypeStr the mime type of the DRM content.



                                                        
              
        int mimeType;

        id = -1;
        inData = new BufferedInputStream(inRawdata, 1024);
        inDataLen = len;

        if (DRM_MIMETYPE_MESSAGE_STRING.equals(mimeTypeStr))
            mimeType = DRM_MIMETYPE_MESSAGE;
        else if (DRM_MIMETYPE_CONTENT_STRING.equals(mimeTypeStr))
            mimeType = DRM_MIMETYPE_CONTENT;
        else
            throw new IllegalArgumentException("mimeType must be DRM_MIMETYPE_MESSAGE or DRM_MIMETYPE_CONTENT");

        if (len <= 0)
            throw new IllegalArgumentException("len must be > 0");

        /* call native method to initialize this DRM content */
        id = nativeConstructDrmContent(inData, inDataLen, mimeType);

        if (JNI_DRM_FAILURE == id)
            throw new DrmException("nativeConstructDrmContent() returned JNI_DRM_FAILURE");

        /* init the rights issuer field. */
        rightsIssuer = nativeGetRightsAddress();

        /* init the raw content type. */
        rawType = nativeGetDeliveryMethod();
        if (JNI_DRM_FAILURE == rawType)
            throw new DrmException("nativeGetDeliveryMethod() returned JNI_DRM_FAILURE");

        /* init the media content type. */
        mediaType = nativeGetContentType();
        if (null == mediaType)
            throw new DrmException("nativeGetContentType() returned null");
    
Methods Summary
protected native voidfinalize()
The finalizer of the DRMRawContent. Do some cleanup.

public java.io.InputStreamgetContentInputStream(DrmRights rights)
Get one InputStream object to read decrypted content.

param
rights the rights object contain decrypted key.
return
the InputStream object of decrypted media content.

        if (null == rights)
            throw new NullPointerException();

        return new DrmInputStream(rights);
    
public intgetContentLength(DrmRights rights)
Get the length of the decrypted media content.

param
rights the rights object contain decrypted key.
return
the length of the decrypted media content. #DRM_UNKNOWN_DATA_LEN if the length is unknown currently.

        /**
         * Because currently the media object associate with rights object
         * has been handled in native logic, so here it is not need to deal
         * the rights. But for the apps, it is mandatory for user to get
         * the rights object before get the media content length.
         */
        if (null == rights)
            throw new NullPointerException();

        int mediaLen = nativeGetContentLength();

        if (JNI_DRM_FAILURE == mediaLen)
            throw new DrmException("nativeGetContentLength() returned JNI_DRM_FAILURE");

        if (JNI_DRM_UNKNOWN_DATA_LEN == mediaLen)
            return DRM_UNKNOWN_DATA_LEN;

        return mediaLen;
    
public java.lang.StringgetContentType()
Get the type of the decrypted media content.

return
the decrypted media content type of this DRM content.

        return mediaType;
    
public intgetRawType()
Get the type of the raw DRM content.

return
one of the following delivery type of this DRM content: #DRM_FORWARD_LOCK #DRM_COMBINED_DELIVERY #DRM_SEPARATE_DELIVERY #DRM_SEPARATE_DELIVERY_DM

        return rawType;
    
public java.lang.StringgetRightsAddress()
Get rights address from raw Seperate Delivery content.

return
the string of the rights issuer address, or null if no rights issuer.

        return rightsIssuer;
    
private native intnativeConstructDrmContent(java.io.InputStream data, int len, int mimeType)
native method: construct a DRM content according the mime type.

param
data input DRM content data to be parsed.
param
len the length of the data.
param
mimeType the mime type of this DRM content. the value of this field includes: #DRM_MIMETYPE_MESSAGE #DRM_MIMETYPE_CONTENT
return
#the id of the DRM content if succeed. #JNI_DRM_FAILURE if fail.

private native intnativeGetContentLength()
native method: get this DRM decrypted media content length.

return
the length of decrypted media content. #JNI_DRM_FAILURE if fail. #JNI_DRM_UNKNOWN_DATA_LEN if the length is unknown currently.

private native java.lang.StringnativeGetContentType()
native method: get this DRM content type.

return
the decrypted media content type. null if fail.

private native intnativeGetDeliveryMethod()
native method: get this DRM content delivery type.

return
the delivery method, the value may be one of the following: #DRM_FORWARD_LOCK #DRM_COMBINED_DELIVERY #DRM_SEPARATE_DELIVERY #DRM_SEPARATE_DELIVERY_DM #JNI_DRM_FAILURE if fail.

private native java.lang.StringnativeGetRightsAddress()
native method: get this DRM content rights issuer.

return
the address of rights issuer if in case of separate delivery. null if not separete delivery, or otherwise.

private native intnativeReadContent(byte[] buf, int bufOff, int len, int mediaOff)
native method: get a piece of media content data.

param
buf the buffer to save DRM media content data.
param
bufOff the offset of the buffer to start to save data.
param
len the number of byte to read.
param
mediaOff the offset of the media content data to start to read.
return
the length of the media content data has been read. #JNI_DRM_EOF if reach to end of the media content. #JNI_DRM_FAILURE if fail.