summaryrefslogtreecommitdiff
path: root/drm/java
diff options
context:
space:
mode:
Diffstat (limited to 'drm/java')
-rwxr-xr-xdrm/java/android/drm/DrmErrorEvent.java30
-rwxr-xr-xdrm/java/android/drm/DrmEvent.java4
-rwxr-xr-xdrm/java/android/drm/DrmInfo.java14
-rwxr-xr-xdrm/java/android/drm/DrmInfoEvent.java40
-rwxr-xr-xdrm/java/android/drm/DrmInfoRequest.java5
-rwxr-xr-xdrm/java/android/drm/DrmInfoStatus.java4
-rwxr-xr-xdrm/java/android/drm/DrmManagerClient.java1
-rwxr-xr-xdrm/java/android/drm/DrmRights.java62
-rwxr-xr-xdrm/java/android/drm/DrmStore.java62
-rwxr-xr-xdrm/java/android/drm/DrmSupportInfo.java11
-rwxr-xr-xdrm/java/android/drm/DrmUtils.java30
11 files changed, 214 insertions, 49 deletions
diff --git a/drm/java/android/drm/DrmErrorEvent.java b/drm/java/android/drm/DrmErrorEvent.java
index 2cb82e67e14b..c61819dacd99 100755
--- a/drm/java/android/drm/DrmErrorEvent.java
+++ b/drm/java/android/drm/DrmErrorEvent.java
@@ -24,6 +24,10 @@ import java.util.HashMap;
*
*/
public class DrmErrorEvent extends DrmEvent {
+
+ // Please add newly defined type constants to the end of the list,
+ // and modify checkTypeValidity() accordingly.
+
/**
* Something went wrong installing the rights.
*/
@@ -60,28 +64,46 @@ public class DrmErrorEvent extends DrmEvent {
*/
public static final int TYPE_ACQUIRE_DRM_INFO_FAILED = 2008;
+ // Add more type constants here...
+
+ // FIXME:
+ // We may want to add a user-defined type constant, such as
+ // TYPE_VENDOR_SPECIFIC_FAILED, to take care vendor specific use
+ // cases.
+
+
/**
* Creates a <code>DrmErrorEvent</code> object with the specified parameters.
*
* @param uniqueId Unique session identifier.
- * @param type Type of the event. Could be any of the event types defined above.
- * @param message Message description.
+ * @param type Type of the event. Must be any of the event types defined above.
+ * @param message Message description. It can be null.
*/
public DrmErrorEvent(int uniqueId, int type, String message) {
super(uniqueId, type, message);
+ checkTypeValidity(type);
}
/**
* Creates a <code>DrmErrorEvent</code> object with the specified parameters.
*
* @param uniqueId Unique session identifier.
- * @param type Type of the event. Could be any of the event types defined above.
+ * @param type Type of the event. Must be any of the event types defined above.
* @param message Message description.
* @param attributes Attributes for extensible information. Could be any
- * information provided by the plug-in.
+ * information provided by the plug-in. It can be null.
*/
public DrmErrorEvent(int uniqueId, int type, String message,
HashMap<String, Object> attributes) {
super(uniqueId, type, message, attributes);
+ checkTypeValidity(type);
+ }
+
+ private void checkTypeValidity(int type) {
+ if (type < TYPE_RIGHTS_NOT_INSTALLED ||
+ type > TYPE_ACQUIRE_DRM_INFO_FAILED) {
+ final String msg = "Unsupported type: " + type;
+ throw new IllegalArgumentException(msg);
+ }
}
}
diff --git a/drm/java/android/drm/DrmEvent.java b/drm/java/android/drm/DrmEvent.java
index 4053eb39e799..1a19f5c62b94 100755
--- a/drm/java/android/drm/DrmEvent.java
+++ b/drm/java/android/drm/DrmEvent.java
@@ -23,6 +23,10 @@ import java.util.HashMap;
*
*/
public class DrmEvent {
+
+ // Please do not add type constants in this class. More event type constants
+ // should go to DrmInfoEvent or DrmErrorEvent classes.
+
/**
* All of the rights information associated with all DRM schemes have been successfully removed.
*/
diff --git a/drm/java/android/drm/DrmInfo.java b/drm/java/android/drm/DrmInfo.java
index 8812bfe5a11e..22d06c7bd20e 100755
--- a/drm/java/android/drm/DrmInfo.java
+++ b/drm/java/android/drm/DrmInfo.java
@@ -49,6 +49,13 @@ public class DrmInfo {
mInfoType = infoType;
mMimeType = mimeType;
mData = data;
+ if (!isValid()) {
+ final String msg = "infoType: " + infoType + "," +
+ "mimeType: " + mimeType + "," +
+ "data: " + data;
+
+ throw new IllegalArgumentException(msg);
+ }
}
/**
@@ -69,6 +76,13 @@ public class DrmInfo {
// call would fail with IllegalArgumentException because of mData = null
mData = null;
}
+ if (!isValid()) {
+ final String msg = "infoType: " + infoType + "," +
+ "mimeType: " + mimeType + "," +
+ "data: " + mData;
+
+ throw new IllegalArgumentException();
+ }
}
/**
diff --git a/drm/java/android/drm/DrmInfoEvent.java b/drm/java/android/drm/DrmInfoEvent.java
index 67aa0a96b636..2826dcee4f67 100755
--- a/drm/java/android/drm/DrmInfoEvent.java
+++ b/drm/java/android/drm/DrmInfoEvent.java
@@ -24,6 +24,10 @@ import java.util.HashMap;
*
*/
public class DrmInfoEvent extends DrmEvent {
+
+ // Please add newly defined type constants to the end of the list,
+ // and modify checkTypeValidity() accordingly.
+
/**
* The registration has already been done by another account ID.
*/
@@ -50,29 +54,57 @@ public class DrmInfoEvent extends DrmEvent {
*/
public static final int TYPE_RIGHTS_REMOVED = 6;
+ // Add more type constants here...
+
+ // FIXME:
+ // We may want to add a user-defined type constant, such as
+ // TYPE_VENDOR_SPECIFIC, to take care vendor specific use
+ // cases.
+
/**
* Creates a <code>DrmInfoEvent</code> object with the specified parameters.
*
* @param uniqueId Unique session identifier.
- * @param type Type of the event. Could be any of the event types defined above.
- * @param message Message description.
+ * @param type Type of the event. Must be any of the event types defined above,
+ * or the constants defined in {@link DrmEvent}.
+ * @param message Message description. It can be null.
*/
public DrmInfoEvent(int uniqueId, int type, String message) {
super(uniqueId, type, message);
+ checkTypeValidity(type);
}
/**
* Creates a <code>DrmInfoEvent</code> object with the specified parameters.
*
* @param uniqueId Unique session identifier.
- * @param type Type of the event. Could be any of the event types defined above.
- * @param message Message description.
+ * @param type Type of the event. Must be any of the event types defined above,
+ * or the constants defined in {@link DrmEvent}
+ * @param message Message description. It can be null.
* @param attributes Attributes for extensible information. Could be any
* information provided by the plug-in.
*/
public DrmInfoEvent(int uniqueId, int type, String message,
HashMap<String, Object> attributes) {
super(uniqueId, type, message, attributes);
+ checkTypeValidity(type);
+ }
+
+ /*
+ * Check the validity of the given type.
+ * To overcome a design flaw, we need also accept the type constants
+ * defined in super class, DrmEvent.
+ */
+ private void checkTypeValidity(int type) {
+ if (type < TYPE_ALREADY_REGISTERED_BY_ANOTHER_ACCOUNT ||
+ type > TYPE_RIGHTS_REMOVED) {
+
+ if (type != TYPE_ALL_RIGHTS_REMOVED &&
+ type != TYPE_DRM_INFO_PROCESSED) {
+ final String msg = "Unsupported type: " + type;
+ throw new IllegalArgumentException(msg);
+ }
+ }
}
}
diff --git a/drm/java/android/drm/DrmInfoRequest.java b/drm/java/android/drm/DrmInfoRequest.java
index 1429fa516e1d..621da413bf97 100755
--- a/drm/java/android/drm/DrmInfoRequest.java
+++ b/drm/java/android/drm/DrmInfoRequest.java
@@ -67,6 +67,11 @@ public class DrmInfoRequest {
public DrmInfoRequest(int infoType, String mimeType) {
mInfoType = infoType;
mMimeType = mimeType;
+ if (!isValid()) {
+ final String msg = "infoType: " + infoType + "," +
+ "mimeType: " + mimeType;
+ throw new IllegalArgumentException(msg);
+ }
}
/**
diff --git a/drm/java/android/drm/DrmInfoStatus.java b/drm/java/android/drm/DrmInfoStatus.java
index 5c12ae3c031a..2fe0a78ce9b9 100755
--- a/drm/java/android/drm/DrmInfoStatus.java
+++ b/drm/java/android/drm/DrmInfoStatus.java
@@ -56,6 +56,10 @@ public class DrmInfoStatus {
* @param _mimeType The MIME type.
*/
public DrmInfoStatus(int _statusCode, int _infoType, ProcessedData _data, String _mimeType) {
+ if (!DrmInfoRequest.isValidType(_infoType)) {
+ throw new IllegalArgumentException("infoType: " + _infoType);
+ }
+
statusCode = _statusCode;
infoType = _infoType;
data = _data;
diff --git a/drm/java/android/drm/DrmManagerClient.java b/drm/java/android/drm/DrmManagerClient.java
index f9567a56ae19..482ab0ab1c5c 100755
--- a/drm/java/android/drm/DrmManagerClient.java
+++ b/drm/java/android/drm/DrmManagerClient.java
@@ -363,6 +363,7 @@ public class DrmManagerClient {
*
* @return A {@link android.content.ContentValues} instance that contains
* key-value pairs representing the constraints. Null in case of failure.
+ * The keys are defined in {@link DrmStore.ConstraintsColumns}.
*/
public ContentValues getConstraints(String path, int action) {
if (null == path || path.equals("") || !DrmStore.Action.isValid(action)) {
diff --git a/drm/java/android/drm/DrmRights.java b/drm/java/android/drm/DrmRights.java
index ef9c21dc7dc4..a9b4f0575bf1 100755
--- a/drm/java/android/drm/DrmRights.java
+++ b/drm/java/android/drm/DrmRights.java
@@ -30,19 +30,24 @@ import java.io.IOException;
* 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 <code>ProcessedData</code>.
+ *<p>
+ * 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.
*
*/
public class DrmRights {
private byte[] mData;
private String mMimeType;
- private String mAccountId = "_NO_USER";
- private String mSubscriptionId = "";
+ private String mAccountId;
+ private String mSubscriptionId;
/**
* Creates a <code>DrmRights</code> object with the given parameters.
*
* @param rightsFilePath Path to the file containing rights information.
- * @param mimeType MIME type.
+ * @param mimeType MIME type. Must not be null or an empty string.
*/
public DrmRights(String rightsFilePath, String mimeType) {
File file = new File(rightsFilePath);
@@ -53,22 +58,20 @@ public class DrmRights {
* Creates a <code>DrmRights</code> object with the given parameters.
*
* @param rightsFilePath Path to the file containing rights information.
- * @param mimeType MIME type.
+ * @param mimeType MIME type. Must not be null or an empty string.
* @param accountId Account ID of the user.
*/
public DrmRights(String rightsFilePath, String mimeType, String accountId) {
this(rightsFilePath, mimeType);
- if (null != accountId && !accountId.equals("")) {
- mAccountId = accountId;
- }
+ mAccountId = accountId;
}
/**
* Creates a <code>DrmRights</code> object with the given parameters.
*
* @param rightsFilePath Path to the file containing rights information.
- * @param mimeType MIME type.
+ * @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.
*/
@@ -76,20 +79,15 @@ public class DrmRights {
String rightsFilePath, String mimeType, String accountId, String subscriptionId) {
this(rightsFilePath, mimeType);
- if (null != accountId && !accountId.equals("")) {
- mAccountId = accountId;
- }
-
- if (null != subscriptionId && !subscriptionId.equals("")) {
- mSubscriptionId = subscriptionId;
- }
+ mAccountId = accountId;
+ mSubscriptionId = subscriptionId;
}
/**
* Creates a <code>DrmRights</code> object with the given parameters.
*
* @param rightsFile File containing rights information.
- * @param mimeType MIME type.
+ * @param mimeType MIME type. Must not be null or an empty string.
*/
public DrmRights(File rightsFile, String mimeType) {
instantiate(rightsFile, mimeType);
@@ -103,31 +101,35 @@ public class DrmRights {
}
mMimeType = mimeType;
+ if (!isValid()) {
+ final String msg = "mimeType: " + mMimeType + "," +
+ "data: " + mData;
+ throw new IllegalArgumentException(msg);
+ }
}
/**
* Creates a <code>DrmRights</code> object with the given parameters.
*
* @param data A {@link ProcessedData} object containing rights information.
- * data could be null because it's optional for some DRM schemes.
- * @param mimeType The MIME type.
+ * Must not be null.
+ * @param mimeType The MIME type. It must not be null or an empty string.
*/
public DrmRights(ProcessedData data, String mimeType) {
- if (data != null) {
- mData = data.getData();
-
- String accountId = data.getAccountId();
- if (null != accountId && !accountId.equals("")) {
- mAccountId = accountId;
- }
-
- String subscriptionId = data.getSubscriptionId();
- if (null != subscriptionId && !subscriptionId.equals("")) {
- mSubscriptionId = subscriptionId;
- }
+ 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);
+ }
}
/**
diff --git a/drm/java/android/drm/DrmStore.java b/drm/java/android/drm/DrmStore.java
index ae311de73861..3a77ea19a19b 100755
--- a/drm/java/android/drm/DrmStore.java
+++ b/drm/java/android/drm/DrmStore.java
@@ -23,45 +23,65 @@ package android.drm;
public class DrmStore {
/**
* Interface definition for the columns that represent DRM constraints.
+ * {@link android.drm.DrmManagerClient#getConstraints DrmManagerClient.getConstraints()}
+ * can be called by an application to find out the contraints on the
+ * {@link android.drm.DrmStore.Action actions} that can be performed
+ * on right-protected content. The constants defined in this interface
+ * represent three most common types of constraints: count-based,
+ * date-based, and duration-based. Two or more constraints can be used
+ * at the same time to represent more sophisticated constraints.
+ * In addition, user-defined constraint,
+ * {@link #EXTENDED_METADATA extended metadata}, can be
+ * used if these three types of constraints are not sufficient.
*/
public interface ConstraintsColumns {
/**
- * The maximum repeat count.
+ * This is a count-based constraint. It represents the maximum
+ * repeat count that can be performed on an
+ * {@link android.drm.DrmStore.Action action}.
* <p>
* Type: INTEGER
*/
public static final String MAX_REPEAT_COUNT = "max_repeat_count";
/**
- * The remaining repeat count.
+ * This is a count-based constraint. It represents the remaining
+ * repeat count that can be performed on an
+ * {@link android.drm.DrmStore.Action action}.
* <p>
* Type: INTEGER
*/
public static final String REMAINING_REPEAT_COUNT = "remaining_repeat_count";
/**
- * The time before which the rights-protected file cannot be played/viewed.
+ * This is a date-based constraint. It represents the time before which
+ * an {@link android.drm.DrmStore.Action action} can be performed on
+ * the rights-protected content.
* <p>
* Type: TEXT
*/
public static final String LICENSE_START_TIME = "license_start_time";
/**
- * The time after which the rights-protected file cannot be played/viewed.
+ * This is a date-based constaint. It represents the time after which
+ * an {@link android.drm.DrmStore.Action action} can not be performed on
+ * the rights-protected content.
* <p>
* Type: TEXT
*/
public static final String LICENSE_EXPIRY_TIME = "license_expiry_time";
/**
- * The available time left before the license expires.
+ * This is a duration-based constaint. It represents the available time left
+ * before the license expires.
* <p>
* Type: TEXT
*/
public static final String LICENSE_AVAILABLE_TIME = "license_available_time";
/**
- * The data stream for extended metadata.
+ * This is a user-defined constraint. It represents the additional constraint
+ * using extended metadata.
* <p>
* Type: TEXT
*/
@@ -88,6 +108,12 @@ public class DrmStore {
* A trigger information object type.
*/
public static final int TRIGGER_OBJECT = 0x03;
+
+ /**
+ * @deprecated This class should have been an interface instead.
+ * The default constuctor should have not been exposed.
+ */
+ public DrmObjectType() {}
}
/**
@@ -123,6 +149,12 @@ public class DrmStore {
}
return isValid;
}
+
+ /**
+ * @deprecated This class should have been an interface instead.
+ * The default constuctor should have not been exposed.
+ */
+ public Playback() {}
}
/**
@@ -178,6 +210,12 @@ public class DrmStore {
}
return isValid;
}
+
+ /**
+ * @deprecated This class should have been an interface instead.
+ * The default constuctor should have not been exposed.
+ */
+ public Action() {}
}
/**
@@ -200,6 +238,18 @@ public class DrmStore {
* The digital rights have not been acquired for the rights-protected content.
*/
public static final int RIGHTS_NOT_ACQUIRED = 0x03;
+
+ /**
+ * @deprecated This class should have been an interface instead.
+ * The default constuctor should have not been exposed.
+ */
+ public RightsStatus() {}
}
+
+ /**
+ * @deprecated This class should have been an interface instead.
+ * The default constuctor should have not been exposed.
+ */
+ public DrmStore() {}
}
diff --git a/drm/java/android/drm/DrmSupportInfo.java b/drm/java/android/drm/DrmSupportInfo.java
index 720c545282a9..6484fa71dbd2 100755
--- a/drm/java/android/drm/DrmSupportInfo.java
+++ b/drm/java/android/drm/DrmSupportInfo.java
@@ -85,12 +85,23 @@ public class DrmSupportInfo {
* Retrieves the DRM plug-in (agent) description.
*
* @return The plug-in description.
+ * @deprecated The method name is mis-spelled, and it is replaced by
+ * {@link #getDescription()}.
*/
public String getDescriprition() {
return mDescription;
}
/**
+ * Retrieves the DRM plug-in (agent) description.
+ *
+ * @return The plug-in description.
+ */
+ public String getDescription() {
+ return mDescription;
+ }
+
+ /**
* Overridden hash code implementation.
*
* @return The hash code value.
diff --git a/drm/java/android/drm/DrmUtils.java b/drm/java/android/drm/DrmUtils.java
index dc5f1fa3d087..4f7cb224fd65 100755
--- a/drm/java/android/drm/DrmUtils.java
+++ b/drm/java/android/drm/DrmUtils.java
@@ -55,8 +55,8 @@ public class DrmUtils {
bufferedStream.read(data);
}
} finally {
- quiteDispose(bufferedStream);
- quiteDispose(inputStream);
+ quietlyDispose(bufferedStream);
+ quietlyDispose(inputStream);
}
return data;
}
@@ -70,7 +70,7 @@ public class DrmUtils {
outputStream = new FileOutputStream(path);
outputStream.write(data);
} finally {
- quiteDispose(outputStream);
+ quietlyDispose(outputStream);
}
}
}
@@ -80,7 +80,7 @@ public class DrmUtils {
file.delete();
}
- private static void quiteDispose(InputStream stream) {
+ private static void quietlyDispose(InputStream stream) {
try {
if (null != stream) {
stream.close();
@@ -90,7 +90,7 @@ public class DrmUtils {
}
}
- private static void quiteDispose(OutputStream stream) {
+ private static void quietlyDispose(OutputStream stream) {
try {
if (null != stream) {
stream.close();
@@ -175,14 +175,34 @@ public class DrmUtils {
}
}
+ /**
+ * This method returns an iterator object that can be used to iterate over
+ * all values of the metadata.
+ *
+ * @return The iterator object.
+ */
public Iterator<String> iterator() {
return mMap.values().iterator();
}
+ /**
+ * This method returns an iterator object that can be used to iterate over
+ * all keys of the metadata.
+ *
+ * @return The iterator object.
+ */
public Iterator<String> keyIterator() {
return mMap.keySet().iterator();
}
+ /**
+ * This method retrieves the metadata value associated with a given key.
+ *
+ * @param key The key whose value is being retrieved.
+ *
+ * @return The metadata value associated with the given key. Returns null
+ * if the key is not found.
+ */
public String get(String key) {
return mMap.get(key);
}