FileDocCategorySizeDatePackage
DrmWrapper.javaAPI DocAndroid 1.5 API7075Wed May 06 22:42:46 BST 2009com.android.mms.drm

DrmWrapper

public class DrmWrapper extends Object
The Drm Wrapper.

Fields Summary
private android.drm.mobile1.DrmRights
mRight
The DRM right object.
private final android.drm.mobile1.DrmRawContent
mDrmObject
The DrmRawContent.
private final android.net.Uri
mDataUri
private final byte[]
mData
private byte[]
mDecryptedData
The decrypted data.
private static final String
LOG_TAG
The log tag.
private static final boolean
DEBUG
private static final boolean
LOCAL_LOGV
Constructors Summary
public DrmWrapper(String drmContentType, android.net.Uri uri, byte[] drmData)
Constructor.

param
uri


            
          
               
        if ((drmContentType == null) || (drmData == null)) {
            throw new IllegalArgumentException(
                    "Content-Type or data may not be null.");
        }

        mDataUri = uri;
        mData = drmData;

        ByteArrayInputStream drmDataStream = new ByteArrayInputStream(drmData);
        mDrmObject = new DrmRawContent(drmDataStream, drmDataStream.available(),
                                       drmContentType);
        // Install rights if necessary.
        if (!isRightsInstalled()) {
            if (LOCAL_LOGV) {
                Log.v(LOG_TAG, "DRM rights not installed yet.");
            }
            installRights(drmData);
        }
    
Methods Summary
public booleanconsumeRights()
Consume the rights.

return
true if consume success false if consume failure

        if (mRight == null) {
            return false;
        }

        return mRight.consumeRights(getPermission());
    
public java.lang.StringgetContentType()
Get the decrypted object's content-type.

return
the content-type

        return mDrmObject.getContentType();
    
public byte[]getDecryptedData()
Get decrypted data.

return
the decrypted content if decryption was successful.
throws
IOException

        if ((mDecryptedData == null) && (mRight != null)) {
            // Decrypt it.
            InputStream decryptedDataStream = mDrmObject.getContentInputStream(mRight);
            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                byte[] buffer = new byte[256];
                int len;
                while ((len = decryptedDataStream.read(buffer)) > 0) {
                    baos.write(buffer, 0, len);
                }
                mDecryptedData = baos.toByteArray();
            } finally {
                try {
                    decryptedDataStream.close();
                } catch (IOException e) {
                    Log.e(LOG_TAG, e.getMessage(), e);
                }
            }
        }

        if (mDecryptedData != null) {
            byte[] decryptedData = new byte[mDecryptedData.length];
            System.arraycopy(mDecryptedData, 0, decryptedData, 0, mDecryptedData.length);
            return decryptedData;
        }
        return null;
    
public byte[]getOriginalData()

        return mData;
    
public android.net.UrigetOriginalUri()

        return mDataUri;
    
private intgetPermission()
Get permission type for the decrypted content-type.

return
the permission

        String contentType = mDrmObject.getContentType();

        if (ContentType.isAudioType(contentType) ||
                ContentType.isVideoType(contentType)) {
            return DrmRights.DRM_PERMISSION_PLAY;
        }
        return DrmRights.DRM_PERMISSION_DISPLAY;
    
public java.lang.StringgetRightsAddress()
Get URL of right.

return
the right's URL

        if (mDrmObject == null) {
            return null;
        }
        return mDrmObject.getRightsAddress();
    
public voidinstallRights(byte[] rightData)
Install Right.

param
rightData right's data
throws
IOException
throws
DrmException

        if (rightData == null) {
            throw new DrmException("Right data may not be null.");
        }

        if (LOCAL_LOGV) {
            Log.v(LOG_TAG, "Installing DRM rights.");
        }

        ByteArrayInputStream rightDataStream = new ByteArrayInputStream(rightData);
        mRight = DrmRightsManager.getInstance().installRights(
                rightDataStream, rightData.length,
                DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING);
    
public booleanisAllowedToForward()
Check whether this DRM object can be forwarded.

return
true if this object can be forwarded false if not

        if (DrmRawContent.DRM_SEPARATE_DELIVERY != mDrmObject.getRawType()) {
            return false;
        }
        return true;
    
public static booleanisDrmObject(java.lang.String contentType)
Check whether a object is DRM object.

param
contentType the mimetype of the object
return
true if it is false if not

        if (contentType == null) {
            return false;
        }

        if (contentType.equalsIgnoreCase(DrmRawContent.DRM_MIMETYPE_CONTENT_STRING) ||
                contentType.equalsIgnoreCase(DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING)) {
            return true;
        }

        return false;
    
public booleanisRightsInstalled()
Check whether the DRM object's right is existed. If not, we should download it.

return
true if it is existed false if not

        if (mRight != null) {
            return true;
        }

        mRight = DrmRightsManager.getInstance().queryRights(mDrmObject);
        return mRight != null ? true : false;