summaryrefslogtreecommitdiffstats
path: root/drm/java
diff options
context:
space:
mode:
authorTakeshi Aimi <aimitakeshi@gmail.com>2010-10-08 23:05:49 +0900
committerTakeshi Aimi <aimitakeshi@gmail.com>2010-11-02 08:06:06 +0900
commitc7b3ccc564448cb4b918728421f9402bc18278c5 (patch)
tree7d97c647cef5ae086048f62636bad3343f193459 /drm/java
parent5b4d0e84d314bd58efb9dcf4e7f23f0d0e3fc630 (diff)
downloadframeworks_base-c7b3ccc564448cb4b918728421f9402bc18278c5.zip
frameworks_base-c7b3ccc564448cb4b918728421f9402bc18278c5.tar.gz
frameworks_base-c7b3ccc564448cb4b918728421f9402bc18278c5.tar.bz2
Update of DRM framework
- Overload openDecryptSession() with uri parameter in order to accept URI of DRM content, Following API is added, DecryptHandle*openDecryptSession(const char* uri);. - Unify texisting three event types of processDrmInfo() so that caller of DRM framework does not have to handle many event types. - Let DrmManagerService call load/unload plugins API so that client of DRM framework does not have to manage plug-in load/unload. - Trivial fix in DrmManagerClient.java is also incorporated. Changes are made by Sony Corporation. Change-Id: If62b47fa0360718fdc943e6e6143671d7db26adc
Diffstat (limited to 'drm/java')
-rw-r--r--drm/java/android/drm/DrmErrorEvent.java24
-rw-r--r--drm/java/android/drm/DrmEvent.java28
-rw-r--r--drm/java/android/drm/DrmInfoStatus.java5
-rw-r--r--drm/java/android/drm/DrmManagerClient.java182
-rw-r--r--drm/java/android/drm/DrmUtils.java3
5 files changed, 60 insertions, 182 deletions
diff --git a/drm/java/android/drm/DrmErrorEvent.java b/drm/java/android/drm/DrmErrorEvent.java
index 8e71634..9294884 100644
--- a/drm/java/android/drm/DrmErrorEvent.java
+++ b/drm/java/android/drm/DrmErrorEvent.java
@@ -45,35 +45,19 @@ public class DrmErrorEvent extends DrmEvent {
*/
public static final int TYPE_NO_INTERNET_CONNECTION = 2005;
/**
- * TYPE_REGISTRATION_FAILED, when failed to register with the service.
+ * TYPE_PROCESS_DRM_INFO_FAILED, when failed to process DrmInfo.
*/
- public static final int TYPE_REGISTRATION_FAILED = 2006;
- /**
- * TYPE_UNREGISTRATION_FAILED, when failed to unregister with the service.
- */
- public static final int TYPE_UNREGISTRATION_FAILED = 2007;
- /**
- * TYPE_RIGHTS_ACQUISITION_FAILED, when failed to acquire the rights information required.
- */
- public static final int TYPE_RIGHTS_ACQUISITION_FAILED = 2008;
- /**
- * TYPE_INITIALIZE_FAILED, when failed to load and initialize the available plugins.
- */
- public static final int TYPE_INITIALIZE_FAILED = 2009;
- /**
- * TYPE_FINALIZE_FAILED, when failed to unload and finalize the loaded plugins.
- */
- public static final int TYPE_FINALIZE_FAILED = 2010;
+ public static final int TYPE_PROCESS_DRM_INFO_FAILED = 2006;
/**
* TYPE_REMOVE_ALL_RIGHTS_FAILED, when failed to remove all the rights objects
* associated with all DRM schemes.
*/
- public static final int TYPE_REMOVE_ALL_RIGHTS_FAILED = 2011;
+ public static final int TYPE_REMOVE_ALL_RIGHTS_FAILED = 2007;
/**
* TYPE_DRM_INFO_ACQUISITION_FAILED, when failed to get the required information to
* communicate with the service.
*/
- public static final int TYPE_DRM_INFO_ACQUISITION_FAILED = 2012;
+ public static final int TYPE_DRM_INFO_ACQUISITION_FAILED = 2008;
/**
* constructor to create DrmErrorEvent object with given parameters
diff --git a/drm/java/android/drm/DrmEvent.java b/drm/java/android/drm/DrmEvent.java
index d6e0c3a..583337f 100644
--- a/drm/java/android/drm/DrmEvent.java
+++ b/drm/java/android/drm/DrmEvent.java
@@ -23,35 +23,19 @@ package android.drm;
*/
public class DrmEvent {
/**
- * Constant field signifies that unload and finalize the loaded plugins successfully
- */
- public static final int TYPE_FINALIZED = 1001;
- /**
- * Constant field signifies that register with the service successfully
- */
- public static final int TYPE_REGISTERED = 1002;
- /**
- * Constant field signifies that load and initialized the available plugins successfully
- */
- public static final int TYPE_INITIALIZED = 1003;
- /**
- * Constant field signifies that unregister with the service successfully
- */
- public static final int TYPE_UNREGISTERED = 1004;
- /**
- * Constant field signifies that rights information is acquired successfully
- */
- public static final int TYPE_RIGHTS_ACQUIRED = 1005;
- /**
* Constant field signifies that all the rights information associated with
* all DRM schemes are removed successfully
*/
- public static final int TYPE_ALL_RIGHTS_REMOVED = 1006;
+ public static final int TYPE_ALL_RIGHTS_REMOVED = 1001;
+ /**
+ * Constant field signifies that given information is processed successfully
+ */
+ public static final int TYPE_DRM_INFO_PROCESSED = 1002;
/**
* Constant field signifies that the required information to communicate with
* the service is acquired sucessfully
*/
- public static final int TYPE_DRM_INFO_ACQUIRED = 1007;
+ public static final int TYPE_DRM_INFO_ACQUIRED = 1003;
public static final String DRM_INFO_STATUS_OBJECT = "drm_info_status_object";
public static final String DRM_INFO_OBJECT = "drm_info_object";
diff --git a/drm/java/android/drm/DrmInfoStatus.java b/drm/java/android/drm/DrmInfoStatus.java
index 7e9ca3e..b37ea51 100644
--- a/drm/java/android/drm/DrmInfoStatus.java
+++ b/drm/java/android/drm/DrmInfoStatus.java
@@ -31,6 +31,7 @@ public class DrmInfoStatus {
public static final int STATUS_ERROR = 2;
public final int statusCode;
+ public final int infoType;
public final String mimeType;
public final ProcessedData data;
@@ -38,11 +39,13 @@ public class DrmInfoStatus {
* constructor to create DrmInfoStatus object with given parameters
*
* @param _statusCode Status of the communication
+ * @param _infoType Type of the DRM information processed
* @param _data The processed data
* @param _mimeType MIME type
*/
- public DrmInfoStatus(int _statusCode, ProcessedData _data, String _mimeType) {
+ public DrmInfoStatus(int _statusCode, int _infoType, ProcessedData _data, String _mimeType) {
statusCode = _statusCode;
+ infoType = _infoType;
data = _data;
mimeType = _mimeType;
}
diff --git a/drm/java/android/drm/DrmManagerClient.java b/drm/java/android/drm/DrmManagerClient.java
index 147c530..5044d36 100644
--- a/drm/java/android/drm/DrmManagerClient.java
+++ b/drm/java/android/drm/DrmManagerClient.java
@@ -16,9 +16,11 @@
package android.drm;
+import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
+import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.os.Handler;
import android.os.HandlerThread;
@@ -99,14 +101,9 @@ public class DrmManagerClient {
public void onError(DrmManagerClient client, DrmErrorEvent event);
}
- private static final int STATE_UNINITIALIZED = 0;
- private static final int STATE_INITIALIZED = 1;
-
- private static final int ACTION_INITIALIZE = 1000;
- private static final int ACTION_FINALIZE = 1001;
- private static final int ACTION_REMOVE_ALL_RIGHTS = 1002;
- private static final int ACTION_ACQUIRE_DRM_INFO = 1003;
- private static final int ACTION_PROCESS_DRM_INFO = 1004;
+ private static final int ACTION_REMOVE_ALL_RIGHTS = 1001;
+ private static final int ACTION_ACQUIRE_DRM_INFO = 1002;
+ private static final int ACTION_PROCESS_DRM_INFO = 1003;
private int mUniqueId;
private int mNativeContext;
@@ -116,7 +113,6 @@ public class DrmManagerClient {
private OnInfoListener mOnInfoListener;
private OnEventListener mOnEventListener;
private OnErrorListener mOnErrorListener;
- private int mCurrentState = STATE_UNINITIALIZED;
private class EventHandler extends Handler {
@@ -130,16 +126,6 @@ public class DrmManagerClient {
HashMap<String, Object> attributes = new HashMap<String, Object>();
switch(msg.what) {
- case ACTION_INITIALIZE: {
- if (ERROR_NONE == _loadPlugIns(mUniqueId, msg.obj)) {
- mCurrentState = STATE_INITIALIZED;
- event = new DrmEvent(mUniqueId, DrmEvent.TYPE_INITIALIZED, null);
- } else {
- error = new DrmErrorEvent(mUniqueId,
- DrmErrorEvent.TYPE_INITIALIZE_FAILED, null);
- }
- break;
- }
case ACTION_ACQUIRE_DRM_INFO: {
final DrmInfoRequest request = (DrmInfoRequest) msg.obj;
DrmInfo drmInfo = _acquireDrmInfo(mUniqueId, request);
@@ -157,10 +143,10 @@ public class DrmManagerClient {
DrmInfoStatus status = _processDrmInfo(mUniqueId, drmInfo);
if (null != status && DrmInfoStatus.STATUS_OK == status.statusCode) {
attributes.put(DrmEvent.DRM_INFO_STATUS_OBJECT, status);
- event = new DrmEvent(mUniqueId, getEventType(drmInfo.getInfoType()), null);
+ event = new DrmEvent(mUniqueId, getEventType(status.infoType), null);
} else {
- error = new DrmErrorEvent(mUniqueId,
- getErrorType(drmInfo.getInfoType()), null);
+ int infoType = (null != status) ? status.infoType : drmInfo.getInfoType();
+ error = new DrmErrorEvent(mUniqueId, getErrorType(infoType), null);
}
break;
}
@@ -173,16 +159,6 @@ public class DrmManagerClient {
}
break;
}
- case ACTION_FINALIZE: {
- if (ERROR_NONE == _unloadPlugIns(mUniqueId)) {
- mCurrentState = STATE_UNINITIALIZED;
- event = new DrmEvent(mUniqueId, DrmEvent.TYPE_FINALIZED, null);
- } else {
- error = new DrmErrorEvent(mUniqueId,
- DrmErrorEvent.TYPE_FINALIZE_FAILED, null);
- }
- break;
- }
default:
Log.e(TAG, "Unknown message type " + msg.what);
return;
@@ -283,6 +259,12 @@ public class DrmManagerClient {
// save the unique id
mUniqueId = hashCode();
+
+ _initialize(mUniqueId, new WeakReference<DrmManagerClient>(this));
+ }
+
+ protected void finalize() {
+ _finalize(mUniqueId);
}
/**
@@ -322,58 +304,11 @@ public class DrmManagerClient {
}
/**
- * Initializes DrmFramework, which loads all available plug-ins
- * in the default plug-in directory path
- *
- * @return
- * ERROR_NONE for success
- * ERROR_UNKNOWN for failure
- */
- public int loadPlugIns() {
- int result = ERROR_UNKNOWN;
- if (STATE_UNINITIALIZED == getState()) {
- if (null != mEventHandler) {
- Message msg = mEventHandler.obtainMessage(
- ACTION_INITIALIZE, new WeakReference<DrmManagerClient>(this));
- result = (mEventHandler.sendMessage(msg)) ? ERROR_NONE : result;
- }
- } else {
- result = ERROR_NONE;
- }
- return result;
- }
-
- /**
- * Finalize DrmFramework, which release resources associated with each plug-in
- * and unload all plug-ins.
- *
- * @return
- * ERROR_NONE for success
- * ERROR_UNKNOWN for failure
- */
- public int unloadPlugIns() {
- int result = ERROR_UNKNOWN;
- if (STATE_INITIALIZED == getState()) {
- if (null != mEventHandler) {
- Message msg = mEventHandler.obtainMessage(ACTION_FINALIZE);
- result = (mEventHandler.sendMessage(msg)) ? ERROR_NONE : result;
- }
- } else {
- result = ERROR_NONE;
- }
- return result;
- }
-
- /**
* Retrieves informations about all the plug-ins registered with DrmFramework.
*
* @return Array of DrmEngine plug-in strings
*/
public String[] getAvailableDrmEngines() {
- if (STATE_UNINITIALIZED == getState()) {
- throw new IllegalStateException("Not Initialized yet");
- }
-
DrmSupportInfo[] supportInfos = _getAllSupportInfo(mUniqueId);
ArrayList<String> descriptions = new ArrayList<String>();
@@ -396,8 +331,6 @@ public class DrmManagerClient {
public ContentValues getConstraints(String path, int action) {
if (null == path || path.equals("") || !DrmStore.Action.isValid(action)) {
throw new IllegalArgumentException("Given usage or path is invalid/null");
- } else if (STATE_UNINITIALIZED == getState()) {
- throw new IllegalStateException("Not Initialized yet");
}
return _getConstraints(mUniqueId, path, action);
}
@@ -411,6 +344,9 @@ public class DrmManagerClient {
* or null in case of failure
*/
public ContentValues getConstraints(Uri uri, int action) {
+ if (null == uri || Uri.EMPTY == uri) {
+ throw new IllegalArgumentException("Uri should be non null");
+ }
return getConstraints(convertUriToPath(uri), action);
}
@@ -432,8 +368,6 @@ public class DrmManagerClient {
DrmRights drmRights, String rightsPath, String contentPath) throws IOException {
if (null == drmRights || !drmRights.isValid()) {
throw new IllegalArgumentException("Given drmRights or contentPath is not valid");
- } else if (STATE_UNINITIALIZED == getState()) {
- throw new IllegalStateException("Not Initialized yet");
}
if (null != rightsPath && !rightsPath.equals("")) {
DrmUtils.writeToFile(rightsPath, drmRights.getData());
@@ -451,8 +385,6 @@ public class DrmManagerClient {
if (null == engineFilePath || engineFilePath.equals("")) {
throw new IllegalArgumentException(
"Given engineFilePath: "+ engineFilePath + "is not valid");
- } else if (STATE_UNINITIALIZED == getState()) {
- throw new IllegalStateException("Not Initialized yet");
}
_installDrmEngine(mUniqueId, engineFilePath);
}
@@ -464,14 +396,11 @@ public class DrmManagerClient {
* @param mimeType Mimetype of the object to be handled
* @return
* true - if the given mimeType or path can be handled
- * false - cannot be handled. false will be return in case
- * the state is uninitialized
+ * false - cannot be handled.
*/
public boolean canHandle(String path, String mimeType) {
if ((null == path || path.equals("")) && (null == mimeType || mimeType.equals(""))) {
throw new IllegalArgumentException("Path or the mimetype should be non null");
- } else if (STATE_UNINITIALIZED == getState()) {
- throw new IllegalStateException("Not Initialized yet");
}
return _canHandle(mUniqueId, path, mimeType);
}
@@ -483,8 +412,7 @@ public class DrmManagerClient {
* @param mimeType Mimetype of the object to be handled
* @return
* true - if the given mimeType or path can be handled
- * false - cannot be handled. false will be return in case
- * the state is uninitialized
+ * false - cannot be handled.
*/
public boolean canHandle(Uri uri, String mimeType) {
if ((null == uri || Uri.EMPTY == uri) && (null == mimeType || mimeType.equals(""))) {
@@ -504,8 +432,6 @@ public class DrmManagerClient {
public int processDrmInfo(DrmInfo drmInfo) {
if (null == drmInfo || !drmInfo.isValid()) {
throw new IllegalArgumentException("Given drmInfo is invalid/null");
- } else if (STATE_UNINITIALIZED == getState()) {
- throw new IllegalStateException("Not Initialized yet");
}
int result = ERROR_UNKNOWN;
if (null != mEventHandler) {
@@ -526,8 +452,6 @@ public class DrmManagerClient {
public int acquireDrmInfo(DrmInfoRequest drmInfoRequest) {
if (null == drmInfoRequest || !drmInfoRequest.isValid()) {
throw new IllegalArgumentException("Given drmInfoRequest is invalid/null");
- } else if (STATE_UNINITIALIZED == getState()) {
- throw new IllegalStateException("Not Initialized yet");
}
int result = ERROR_UNKNOWN;
if (null != mEventHandler) {
@@ -550,8 +474,6 @@ public class DrmManagerClient {
public int getDrmObjectType(String path, String mimeType) {
if ((null == path || path.equals("")) && (null == mimeType || mimeType.equals(""))) {
throw new IllegalArgumentException("Path or the mimetype should be non null");
- } else if (STATE_UNINITIALIZED == getState()) {
- throw new IllegalStateException("Not Initialized yet");
}
return _getDrmObjectType(mUniqueId, path, mimeType);
}
@@ -589,8 +511,6 @@ public class DrmManagerClient {
public String getOriginalMimeType(String path) {
if (null == path || path.equals("")) {
throw new IllegalArgumentException("Given path should be non null");
- } else if (STATE_UNINITIALIZED == getState()) {
- throw new IllegalStateException("Not Initialized yet");
}
return _getOriginalMimeType(mUniqueId, path);
}
@@ -644,8 +564,6 @@ public class DrmManagerClient {
public int checkRightsStatus(String path, int action) {
if (null == path || path.equals("") || !DrmStore.Action.isValid(action)) {
throw new IllegalArgumentException("Given path or action is not valid");
- } else if (STATE_UNINITIALIZED == getState()) {
- throw new IllegalStateException("Not Initialized yet");
}
return _checkRightsStatus(mUniqueId, path, action);
}
@@ -676,8 +594,6 @@ public class DrmManagerClient {
public int removeRights(String path) {
if (null == path || path.equals("")) {
throw new IllegalArgumentException("Given path should be non null");
- } else if (STATE_UNINITIALIZED == getState()) {
- throw new IllegalStateException("Not Initialized yet");
}
return _removeRights(mUniqueId, path);
}
@@ -706,9 +622,6 @@ public class DrmManagerClient {
* ERROR_UNKNOWN for failure
*/
public int removeAllRights() {
- if (STATE_UNINITIALIZED == getState()) {
- throw new IllegalStateException("Not Initialized yet");
- }
int result = ERROR_UNKNOWN;
if (null != mEventHandler) {
Message msg = mEventHandler.obtainMessage(ACTION_REMOVE_ALL_RIGHTS);
@@ -729,8 +642,6 @@ public class DrmManagerClient {
public int openConvertSession(String mimeType) {
if (null == mimeType || mimeType.equals("")) {
throw new IllegalArgumentException("Path or the mimeType should be non null");
- } else if (STATE_UNINITIALIZED == getState()) {
- throw new IllegalStateException("Not Initialized yet");
}
return _openConvertSession(mUniqueId, mimeType);
}
@@ -750,8 +661,6 @@ public class DrmManagerClient {
public DrmConvertedStatus convertData(int convertId, byte[] inputData) {
if (null == inputData || 0 >= inputData.length) {
throw new IllegalArgumentException("Given inputData should be non null");
- } else if (STATE_UNINITIALIZED == getState()) {
- throw new IllegalStateException("Not Initialized yet");
}
return _convertData(mUniqueId, convertId, inputData);
}
@@ -769,28 +678,17 @@ public class DrmManagerClient {
* the application on which offset these signature data should be appended.
*/
public DrmConvertedStatus closeConvertSession(int convertId) {
- if (STATE_UNINITIALIZED == getState()) {
- throw new IllegalStateException("Not Initialized yet");
- }
return _closeConvertSession(mUniqueId, convertId);
}
- private int getState() {
- return mCurrentState;
- }
-
private int getEventType(int infoType) {
int eventType = -1;
switch (infoType) {
case DrmInfoRequest.TYPE_REGISTRATION_INFO:
- eventType = DrmEvent.TYPE_REGISTERED;
- break;
case DrmInfoRequest.TYPE_UNREGISTRATION_INFO:
- eventType = DrmEvent.TYPE_UNREGISTERED;
- break;
case DrmInfoRequest.TYPE_RIGHTS_ACQUISITION_INFO:
- eventType = DrmEvent.TYPE_RIGHTS_ACQUIRED;
+ eventType = DrmEvent.TYPE_DRM_INFO_PROCESSED;
break;
}
return eventType;
@@ -801,13 +699,9 @@ public class DrmManagerClient {
switch (infoType) {
case DrmInfoRequest.TYPE_REGISTRATION_INFO:
- error = DrmErrorEvent.TYPE_REGISTRATION_FAILED;
- break;
case DrmInfoRequest.TYPE_UNREGISTRATION_INFO:
- error = DrmErrorEvent.TYPE_UNREGISTRATION_FAILED;
- break;
case DrmInfoRequest.TYPE_RIGHTS_ACQUISITION_INFO:
- error = DrmErrorEvent.TYPE_RIGHTS_ACQUISITION_FAILED;
+ error = DrmErrorEvent.TYPE_PROCESS_DRM_INFO_FAILED;
break;
}
return error;
@@ -822,25 +716,35 @@ public class DrmManagerClient {
* <row_index> the index of the content in given table
*/
private String convertUriToPath(Uri uri) {
+ String path = null;
String scheme = uri.getScheme();
- if (null == scheme || scheme.equals("file")) {
- return uri.getPath();
- }
- String[] projection = new String[] {MediaStore.MediaColumns.DATA};
- Cursor cursor = mContext.getContentResolver().query(uri, projection, null, null, null);
- if (null == cursor || 0 == cursor.getCount() || !cursor.moveToFirst()) {
- throw new IllegalArgumentException("Given Uri could not be found in media store");
+ if (null == scheme || scheme.equals("") || scheme.equals(ContentResolver.SCHEME_FILE)) {
+ path = uri.getPath();
+ } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
+ String[] projection = new String[] {MediaStore.MediaColumns.DATA};
+ Cursor cursor = null;
+ try {
+ cursor = mContext.getContentResolver().query(uri, projection, null, null, null);
+ } catch (SQLiteException e) {
+ throw new IllegalArgumentException("Given Uri is not formatted in a way " +
+ "so that it can be found in media store.");
+ }
+ if (null == cursor || 0 == cursor.getCount() || !cursor.moveToFirst()) {
+ throw new IllegalArgumentException("Given Uri could not be found in media store");
+ }
+ int pathIndex = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
+ path = cursor.getString(pathIndex);
+ cursor.close();
+ } else {
+ throw new IllegalArgumentException("Given Uri scheme is not supported");
}
- int pathIndex = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
- String path = cursor.getString(pathIndex);
- cursor.close();
return path;
}
// private native interfaces
- private native int _loadPlugIns(int uniqueId, Object weak_this);
+ private native void _initialize(int uniqueId, Object weak_this);
- private native int _unloadPlugIns(int uniqueId);
+ private native void _finalize(int uniqueId);
private native void _installDrmEngine(int uniqueId, String engineFilepath);
diff --git a/drm/java/android/drm/DrmUtils.java b/drm/java/android/drm/DrmUtils.java
index 5e5397c..8903485 100644
--- a/drm/java/android/drm/DrmUtils.java
+++ b/drm/java/android/drm/DrmUtils.java
@@ -167,6 +167,9 @@ public class DrmUtils {
//Fetch Value
String strValue = readMultipleBytes(constraintData, valueLength, index);
+ if (strValue.equals(" ")) {
+ strValue = "";
+ }
index += valueLength;
mMap.put(strKey, strValue);
}