FileDocCategorySizeDatePackage
DrmRights.javaAPI DocAndroid 5.1 API5969Thu Mar 12 22:22:30 GMT 2015android.drm

DrmRights

public class DrmRights extends Object
An entity class that wraps the license information retrieved from the online DRM server.

A caller can instantiate a {@link DrmRights} object by first invoking the {@link DrmManagerClient#processDrmInfo(DrmInfo)} method and then using the resulting {@link ProcessedData} object to invoke the {@link DrmRights#DrmRights(ProcessedData, String)} constructor.

A caller can also instantiate a {@link DrmRights} object by using the {@link DrmRights#DrmRights(String, String)} constructor, which takes a path to a file containing rights information instead of a ProcessedData.

Please note that the account id and subscription id is not mandatory by all DRM agents or plugins. When account id or subscription id is not required by the specific DRM agent or plugin, they can be either null, or an empty string, or any other don't-care string value.

Fields Summary
private byte[]
mData
private String
mMimeType
private String
mAccountId
private String
mSubscriptionId
Constructors Summary
public DrmRights(String rightsFilePath, String mimeType)
Creates a DrmRights object with the given parameters.

param
rightsFilePath Path to the file containing rights information.
param
mimeType MIME type. Must not be null or an empty string.

        File file = new File(rightsFilePath);
        instantiate(file, mimeType);
    
public DrmRights(String rightsFilePath, String mimeType, String accountId)
Creates a DrmRights object with the given parameters.

param
rightsFilePath Path to the file containing rights information.
param
mimeType MIME type. Must not be null or an empty string.
param
accountId Account ID of the user.

        this(rightsFilePath, mimeType);

        mAccountId = accountId;
    
public DrmRights(String rightsFilePath, String mimeType, String accountId, String subscriptionId)
Creates a DrmRights object with the given parameters.

param
rightsFilePath Path to the file containing rights information.
param
mimeType MIME type. Must not be null or an empty string.
param
accountId Account ID of the user.
param
subscriptionId Subscription ID of the user.

        this(rightsFilePath, mimeType);

        mAccountId = accountId;
        mSubscriptionId = subscriptionId;
    
public DrmRights(File rightsFile, String mimeType)
Creates a DrmRights object with the given parameters.

param
rightsFile File containing rights information.
param
mimeType MIME type. Must not be null or an empty string.

        instantiate(rightsFile, mimeType);
    
public DrmRights(ProcessedData data, String mimeType)
Creates a DrmRights object with the given parameters.

param
data A {@link ProcessedData} object containing rights information. Must not be null.
param
mimeType The MIME type. It must not be null or an empty string.

        if (data == null) {
            throw new IllegalArgumentException("data is null");
        }

        mData = data.getData();
        mAccountId = data.getAccountId();
        mSubscriptionId = data.getSubscriptionId();
        mMimeType = mimeType;

        if (!isValid()) {
            final String msg = "mimeType: " + mMimeType + "," +
                               "data: " + mData;
            throw new IllegalArgumentException(msg);
        }
    
Methods Summary
public java.lang.StringgetAccountId()
Retrieves the account ID associated with this DrmRights object.

return
The account ID.

        return mAccountId;
    
public byte[]getData()
Retrieves the rights data associated with this DrmRights object.

return
A byte array representing the rights data.

        return mData;
    
public java.lang.StringgetMimeType()
Retrieves the MIME type associated with this DrmRights object.

return
The MIME type.

        return mMimeType;
    
public java.lang.StringgetSubscriptionId()
Retrieves the subscription ID associated with this DrmRights object.

return
The subscription ID.

        return mSubscriptionId;
    
private voidinstantiate(java.io.File rightsFile, java.lang.String mimeType)

        try {
            mData = DrmUtils.readBytes(rightsFile);
        } catch (IOException e) {
            e.printStackTrace();
        }

        mMimeType = mimeType;
        if (!isValid()) {
            final String msg = "mimeType: " + mMimeType + "," +
                               "data: " + mData;
            throw new IllegalArgumentException(msg);
        }
    
booleanisValid()
Determines whether this instance is valid or not.

return
True if valid; false if invalid.

        return (null != mMimeType && !mMimeType.equals("")
                && null != mData && mData.length > 0);