();
+
+ for (int i = 0; i < supportInfos.length; i++) {
+ descriptions.add(supportInfos[i].getDescriprition());
+ }
+
+ String[] drmEngines = new String[descriptions.size()];
+ return descriptions.toArray(drmEngines);
+ }
+
+ /**
+ * Get constraints information evaluated from DRM content
+ *
+ * @param path Content path from where DRM constraints would be retrieved.
+ * @param action Actions defined in {@link DrmStore.Action}
+ * @return ContentValues instance in which constraints key-value pairs are embedded
+ * or null in case of failure
+ */
+ 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 (getState() == STATE_UNINITIALIZED) {
+ throw new IllegalStateException("Not Initialized yet");
+ }
+ return _getConstraints(mUniqueId, path, action);
+ }
+
+ /**
+ * Save DRM rights to specified rights path
+ * and make association with content path.
+ *
+ * @param drmRights DrmRights to be saved
+ * @param rightsPath File path where rights to be saved
+ * @param contentPath File path where content was saved
+ * @throws IOException if failed to save rights information in the given path
+ *
+ * @note In case of OMA or WM-DRM, rightsPath and contentPath could be null
+ */
+ public void saveRights(
+ DrmRights drmRights, String rightsPath, String contentPath) throws IOException {
+ if (null == drmRights || !drmRights.isValid()
+ || null == contentPath || contentPath.equals("")) {
+ throw new IllegalArgumentException("Given drmRights or contentPath is not valid");
+ } else if (getState() == STATE_UNINITIALIZED) {
+ throw new IllegalStateException("Not Initialized yet");
+ }
+ if (null != rightsPath && !rightsPath.equals("")) {
+ DrmUtils.writeToFile(rightsPath, drmRights.getData());
+ }
+ _saveRights(mUniqueId, drmRights, rightsPath, contentPath);
+ }
+
+ /**
+ * Install new DRM Engine Plug-in at the runtime
+ *
+ * @param engineFilePath Path of the plug-in file to be installed
+ * {@hide}
+ */
+ public void installDrmEngine(String engineFilePath) {
+ if (null == engineFilePath || engineFilePath.equals("")) {
+ throw new IllegalArgumentException(
+ "Given engineFilePath: "+ engineFilePath + "is not valid");
+ } else if (getState() == STATE_UNINITIALIZED) {
+ throw new IllegalStateException("Not Initialized yet");
+ }
+ _installDrmEngine(mUniqueId, engineFilePath);
+ }
+
+ /**
+ * Check whether the given mimetype or path can be handled.
+ *
+ * @param path Path of the content to be handled
+ * @param mimeType Mimetype of the object to be handled
+ * @return
+ * true - if the given mimeType or path can be handled
+ * false - cannot be handled.
+ * @note false will be return in case the state is uninitialized
+ */
+ 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 (getState() == STATE_UNINITIALIZED) {
+ throw new IllegalStateException("Not Initialized yet");
+ }
+ return _canHandle(mUniqueId, path, mimeType);
+ }
+
+ /**
+ * Executes given drm information based on its type
+ *
+ * @param drmInfo Information needs to be processed
+ * @return DrmInfoStatus Instance as a result of processing given input
+ */
+ public DrmInfoStatus processDrmInfo(DrmInfo drmInfo) {
+ if (null == drmInfo || !drmInfo.isValid()) {
+ throw new IllegalArgumentException("Given drmInfo is invalid/null");
+ } else if (getState() == STATE_UNINITIALIZED) {
+ throw new IllegalStateException("Not Initialized yet");
+ }
+ return _processDrmInfo(mUniqueId, drmInfo);
+ }
+
+ /**
+ * Retrieves necessary information for register, unregister or rights acquisition.
+ *
+ * @param drmInfoRequest Request information to retrieve drmInfo
+ * @return DrmInfo Instance as a result of processing given input
+ */
+ public DrmInfo acquireDrmInfo(DrmInfoRequest drmInfoRequest) {
+ if (null == drmInfoRequest || !drmInfoRequest.isValid()) {
+ throw new IllegalArgumentException("Given drmInfoRequest is invalid/null");
+ } else if (getState() == STATE_UNINITIALIZED) {
+ throw new IllegalStateException("Not Initialized yet");
+ }
+ return _acquireDrmInfo(mUniqueId, drmInfoRequest);
+ }
+
+ /**
+ * Retrieves the type of the protected object (content, rights, etc..)
+ * using specified path or mimetype. At least one parameter should be non null
+ * to retrieve DRM object type
+ *
+ * @param path Path of the content or null.
+ * @param mimeType Mimetype of the content or null.
+ * @return Type of the DRM content.
+ * @see DrmStore.DrmObjectType
+ */
+ 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 (getState() == STATE_UNINITIALIZED) {
+ throw new IllegalStateException("Not Initialized yet");
+ }
+ return _getDrmObjectType(mUniqueId, path, mimeType);
+ }
+
+ /**
+ * Retrieves the mime type embedded inside the original content
+ *
+ * @param path Path of the protected content
+ * @return Mimetype of the original content, such as "video/mpeg"
+ */
+ public String getOriginalMimeType(String path) {
+ if (null == path || path.equals("")) {
+ throw new IllegalArgumentException("Given path should be non null");
+ } else if (getState() == STATE_UNINITIALIZED) {
+ throw new IllegalStateException("Not Initialized yet");
+ }
+ return _getOriginalMimeType(mUniqueId, path);
+ }
+
+ /**
+ * Check whether the given content has valid rights or not
+ *
+ * @param path Path of the protected content
+ * @return Status of the rights for the protected content
+ * @see DrmStore.RightsStatus
+ */
+ public int checkRightsStatus(String path) {
+ return checkRightsStatus(path, DrmStore.Action.DEFAULT);
+ }
+
+ /**
+ * Check whether the given content has valid rights or not for specified action.
+ *
+ * @param path Path of the protected content
+ * @param action Action to perform
+ * @return Status of the rights for the protected content
+ * @see DrmStore.RightsStatus
+ */
+ 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 (getState() == STATE_UNINITIALIZED) {
+ throw new IllegalStateException("Not Initialized yet");
+ }
+ return _checkRightsStatus(mUniqueId, path, action);
+ }
+
+ /**
+ * Removes the rights associated with the given protected content
+ *
+ * @param path Path of the protected content
+ */
+ public void removeRights(String path) {
+ if (null == path || path.equals("")) {
+ throw new IllegalArgumentException("Given path should be non null");
+ } else if (getState() == STATE_UNINITIALIZED) {
+ throw new IllegalStateException("Not Initialized yet");
+ }
+ _removeRights(mUniqueId, path);
+ }
+
+ /**
+ * Removes all the rights information of every plug-in associated with
+ * DRM framework. Will be used in master reset
+ */
+ public void removeAllRights() {
+ if (getState() == STATE_UNINITIALIZED) {
+ throw new IllegalStateException("Not Initialized yet");
+ }
+ _removeAllRights(mUniqueId);
+ }
+
+ /**
+ * This API is for Forward Lock based DRM scheme.
+ * Each time the application tries to download a new DRM file
+ * which needs to be converted, then the application has to
+ * begin with calling this API.
+ *
+ * @param mimeType Description/MIME type of the input data packet
+ * @return convert ID which will be used for maintaining convert session.
+ */
+ public int openConvertSession(String mimeType) {
+ if (null == mimeType || mimeType.equals("")) {
+ throw new IllegalArgumentException("Path or the mimeType should be non null");
+ } else if (getState() == STATE_UNINITIALIZED) {
+ throw new IllegalStateException("Not Initialized yet");
+ }
+ return _openConvertSession(mUniqueId, mimeType);
+ }
+
+ /**
+ * Accepts and converts the input data which is part of DRM file.
+ * The resultant converted data and the status is returned in the DrmConvertedInfo
+ * object. This method will be called each time there are new block
+ * of data received by the application.
+ *
+ * @param convertId Handle for the convert session
+ * @param inputData Input Data which need to be converted
+ * @return Return object contains the status of the data conversion,
+ * the output converted data and offset. In this case the
+ * application will ignore the offset information.
+ */
+ public DrmConvertedStatus convertData(int convertId, byte[] inputData) {
+ if (null == inputData || 0 >= inputData.length) {
+ throw new IllegalArgumentException("Given inputData should be non null");
+ } else if (getState() == STATE_UNINITIALIZED) {
+ throw new IllegalStateException("Not Initialized yet");
+ }
+ return _convertData(mUniqueId, convertId, inputData);
+ }
+
+ /**
+ * Informs the Drm Agent when there is no more data which need to be converted
+ * or when an error occurs. Upon successful conversion of the complete data,
+ * the agent will inform that where the header and body signature
+ * should be added. This signature appending is needed to integrity
+ * protect the converted file.
+ *
+ * @param convertId Handle for the convert session
+ * @return Return object contains the status of the data conversion,
+ * the header and body signature data. It also informs
+ * the application on which offset these signature data should be appended.
+ */
+ public DrmConvertedStatus closeConvertSession(int convertId) {
+ if (getState() == STATE_UNINITIALIZED) {
+ throw new IllegalStateException("Not Initialized yet");
+ }
+ return _closeConvertSession(mUniqueId, convertId);
+ }
+
+ private int getState() {
+ return mCurrentState;
+ }
+
+ // private native interfaces
+ private native void _loadPlugIns(int uniqueId, Object weak_this);
+
+ private native void _unloadPlugIns(int uniqueId);
+
+ private native void _installDrmEngine(int uniqueId, String engineFilepath);
+
+ private native ContentValues _getConstraints(int uniqueId, String path, int usage);
+
+ private native boolean _canHandle(int uniqueId, String path, String mimeType);
+
+ private native DrmInfoStatus _processDrmInfo(int uniqueId, DrmInfo drmInfo);
+
+ private native DrmInfo _acquireDrmInfo(int uniqueId, DrmInfoRequest drmInfoRequest);
+
+ private native void _saveRights(
+ int uniqueId, DrmRights drmRights, String rightsPath, String contentPath);
+
+ private native int _getDrmObjectType(int uniqueId, String path, String mimeType);
+
+ private native String _getOriginalMimeType(int uniqueId, String path);
+
+ private native int _checkRightsStatus(int uniqueId, String path, int action);
+
+ private native void _removeRights(int uniqueId, String path);
+
+ private native void _removeAllRights(int uniqueId);
+
+ private native int _openConvertSession(int uniqueId, String mimeType);
+
+ private native DrmConvertedStatus _convertData(int uniqueId, int convertId, byte[] inputData);
+
+ private native DrmConvertedStatus _closeConvertSession(int uniqueId, int convertId);
+
+ private native DrmSupportInfo[] _getAllSupportInfo(int uniqueId);
+}
+
diff --git a/drm/java/android/drm/DrmRights.java b/drm/java/android/drm/DrmRights.java
new file mode 100644
index 0000000000000..103af0742f95a
--- /dev/null
+++ b/drm/java/android/drm/DrmRights.java
@@ -0,0 +1,182 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.drm;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * This is an entity class which wraps the license information which was
+ * retrieved from the online DRM server.
+ *
+ * Caller can instantiate {@link DrmRights} by
+ * invoking {@link DrmRights#DrmRights(ProcessedData, String)}
+ * constructor by using the result of {@link DrmManagerClient#processDrmInfo(DrmInfo)} interface.
+ * Caller can also instantiate {@link DrmRights} using the file path
+ * which contains rights information.
+ *
+ */
+public class DrmRights {
+ private byte[] mData;
+ private String mMimeType;
+ private String mAccountId = "_NO_USER";
+ private String mSubscriptionId = "";
+
+ /**
+ * constructor to create DrmRights object with given parameters
+ *
+ * @param rightsFilePath Path of the file containing rights data
+ * @param mimeType MIME type
+ */
+ public DrmRights(String rightsFilePath, String mimeType) {
+ File file = new File(rightsFilePath);
+ instantiate(file, mimeType);
+ }
+
+ /**
+ * constructor to create DrmRights object with given parameters
+ *
+ * @param rightsFilePath Path of the file containing rights data
+ * @param mimeType MIME type
+ * @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;
+ }
+ }
+
+ /**
+ * constructor to create DrmRights object with given parameters
+ *
+ * @param rightsFilePath Path of the file containing rights data
+ * @param mimeType MIME type
+ * @param accountId Account Id of the user
+ * @param subscriptionId Subscription Id of the user
+ */
+ public 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;
+ }
+ }
+
+ /**
+ * constructor to create DrmRights object with given parameters
+ *
+ * @param rightsFile File containing rights data
+ * @param mimeType MIME type
+ */
+ public DrmRights(File rightsFile, String mimeType) {
+ instantiate(rightsFile, mimeType);
+ }
+
+ private void instantiate(File rightsFile, String mimeType) {
+ try {
+ mData = DrmUtils.readBytes(rightsFile);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ mMimeType = mimeType;
+ }
+
+ /**
+ * constructor to create DrmRights object with given parameters
+ * The user can pass String or binary data
+ * Usage:
+ * i) String(e.g. data is instance of String):
+ * - new DrmRights(data.getBytes(), mimeType)
+ * ii) Binary data
+ * - new DrmRights(binaryData[], mimeType)
+ *
+ * @param data Processed data
+ * @param mimeType MIME type
+ */
+ public DrmRights(ProcessedData data, String mimeType) {
+ 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;
+ }
+
+ mMimeType = mimeType;
+ }
+
+ /**
+ * Returns the rights data associated with this object
+ *
+ * @return Rights data
+ */
+ public byte[] getData() {
+ return mData;
+ }
+
+ /**
+ * Returns the mimetype associated with this object
+ *
+ * @return MIME type
+ */
+ public String getMimeType() {
+ return mMimeType;
+ }
+
+ /**
+ * Returns the account-id associated with this object
+ *
+ * @return Account Id
+ */
+ public String getAccountId() {
+ return mAccountId;
+ }
+
+ /**
+ * Returns the subscription-id associated with this object
+ *
+ * @return Subscription Id
+ */
+ public String getSubscriptionId() {
+ return mSubscriptionId;
+ }
+
+ /**
+ * Returns whether this instance is valid or not
+ *
+ * @return
+ * true if valid
+ * false if invalid
+ */
+ /*package*/ boolean isValid() {
+ return (null != mMimeType && !mMimeType.equals("")
+ && null != mData && mData.length > 0);
+ }
+}
+
diff --git a/drm/java/android/drm/DrmStore.java b/drm/java/android/drm/DrmStore.java
new file mode 100644
index 0000000000000..44df90c6687ce
--- /dev/null
+++ b/drm/java/android/drm/DrmStore.java
@@ -0,0 +1,199 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.drm;
+
+/**
+ * This class defines all the constants used by DRM framework
+ *
+ */
+public class DrmStore {
+ /**
+ * Columns representing drm constraints
+ */
+ public interface ConstraintsColumns {
+ /**
+ * The max repeat count
+ *
Type: INTEGER
+ */
+ public static final String MAX_REPEAT_COUNT = "max_repeat_count";
+
+ /**
+ * The remaining repeat count
+ * Type: INTEGER
+ */
+ public static final String REMAINING_REPEAT_COUNT = "remaining_repeat_count";
+
+ /**
+ * The time before which the protected file can not be played/viewed
+ * Type: TEXT
+ */
+ public static final String LICENSE_START_TIME = "license_start_time";
+
+ /**
+ * The time after which the protected file can not be played/viewed
+ * Type: TEXT
+ */
+ public static final String LICENSE_EXPIRY_TIME = "license_expiry_time";
+
+ /**
+ * The available time for license
+ * Type: TEXT
+ */
+ public static final String LICENSE_AVAILABLE_TIME = "license_available_time";
+
+ /**
+ * The data stream for extended metadata
+ * Type: TEXT
+ */
+ public static final String EXTENDED_METADATA = "extended_metadata";
+ }
+
+ /**
+ * Defines constants related to DRM types
+ */
+ public static class DrmObjectType {
+ /**
+ * Field specifies the unknown type
+ */
+ public static final int UNKNOWN = 0x00;
+ /**
+ * Field specifies the protected content type
+ */
+ public static final int CONTENT = 0x01;
+ /**
+ * Field specifies the rights information
+ */
+ public static final int RIGHTS_OBJECT = 0x02;
+ /**
+ * Field specifies the trigger information
+ */
+ public static final int TRIGGER_OBJECT = 0x03;
+ }
+
+ /**
+ * Defines constants related to playback
+ */
+ public static class Playback {
+ /**
+ * Constant field signifies playback start
+ */
+ public static final int START = 0x00;
+ /**
+ * Constant field signifies playback stop
+ */
+ public static final int STOP = 0x01;
+ /**
+ * Constant field signifies playback paused
+ */
+ public static final int PAUSE = 0x02;
+ /**
+ * Constant field signifies playback resumed
+ */
+ public static final int RESUME = 0x03;
+
+ /* package */ static boolean isValid(int playbackStatus) {
+ boolean isValid = false;
+
+ switch (playbackStatus) {
+ case START:
+ case STOP:
+ case PAUSE:
+ case RESUME:
+ isValid = true;
+ }
+ return isValid;
+ }
+ }
+
+ /**
+ * Defines actions that can be performed on protected content
+ */
+ public static class Action {
+ /**
+ * Constant field signifies that the default action
+ */
+ public static final int DEFAULT = 0x00;
+ /**
+ * Constant field signifies that the content can be played
+ */
+ public static final int PLAY = 0x01;
+ /**
+ * Constant field signifies that the content can be set as ring tone
+ */
+ public static final int RINGTONE = 0x02;
+ /**
+ * Constant field signifies that the content can be transfered
+ */
+ public static final int TRANSFER = 0x03;
+ /**
+ * Constant field signifies that the content can be set as output
+ */
+ public static final int OUTPUT = 0x04;
+ /**
+ * Constant field signifies that preview is allowed
+ */
+ public static final int PREVIEW = 0x05;
+ /**
+ * Constant field signifies that the content can be executed
+ */
+ public static final int EXECUTE = 0x06;
+ /**
+ * Constant field signifies that the content can displayed
+ */
+ public static final int DISPLAY = 0x07;
+
+ /* package */ static boolean isValid(int action) {
+ boolean isValid = false;
+
+ switch (action) {
+ case DEFAULT:
+ case PLAY:
+ case RINGTONE:
+ case TRANSFER:
+ case OUTPUT:
+ case PREVIEW:
+ case EXECUTE:
+ case DISPLAY:
+ isValid = true;
+ }
+ return isValid;
+ }
+ }
+
+ /**
+ * Defines constants related to status of the rights
+ */
+ public static class RightsStatus {
+ /**
+ * Constant field signifies that the rights are valid
+ */
+ public static final int RIGHTS_VALID = 0x00;
+ /**
+ * Constant field signifies that the rights are invalid
+ */
+ public static final int RIGHTS_INVALID = 0x01;
+ /**
+ * Constant field signifies that the rights are expired for the content
+ */
+ public static final int RIGHTS_EXPIRED = 0x02;
+ /**
+ * Constant field signifies that the rights are not acquired for the content
+ */
+ public static final int RIGHTS_NOT_ACQUIRED = 0x03;
+ }
+}
+
diff --git a/drm/java/android/drm/DrmSupportInfo.java b/drm/java/android/drm/DrmSupportInfo.java
new file mode 100644
index 0000000000000..0886af8e8da03
--- /dev/null
+++ b/drm/java/android/drm/DrmSupportInfo.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.drm;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * This is an entity class which wraps the capability of each plug-in,
+ * such as mimetype's and file suffixes it could handle.
+ *
+ * Plug-in developer could return the capability of the plugin by passing
+ * {@link DrmSupportInfo} instance.
+ *
+ */
+public class DrmSupportInfo {
+ private final ArrayList mFileSuffixList = new ArrayList();
+ private final ArrayList mMimeTypeList = new ArrayList();
+ private String mDescription = "";
+
+ /**
+ * Add the mime-type to the support info such that respective plug-in is
+ * capable of handling the given mime-type.
+ *
+ * @param mimeType MIME type
+ */
+ public void addMimeType(String mimeType) {
+ mMimeTypeList.add(mimeType);
+ }
+
+ /**
+ * Add the file suffix to the support info such that respective plug-in is
+ * capable of handling the given file suffix.
+ *
+ * @param fileSuffix File suffix which can be handled
+ */
+ public void addFileSuffix(String fileSuffix) {
+ mFileSuffixList.add(fileSuffix);
+ }
+
+ /**
+ * Returns the iterator to walk to through mime types of this object
+ *
+ * @return Iterator object
+ */
+ public Iterator getMimeTypeIterator() {
+ return mMimeTypeList.iterator();
+ }
+
+ /**
+ * Returns the iterator to walk to through file suffixes of this object
+ *
+ * @return Iterator object
+ */
+ public Iterator getFileSuffixIterator() {
+ return mFileSuffixList.iterator();
+ }
+
+ /**
+ * Set the unique description about the plugin
+ *
+ * @param description Unique description
+ */
+ public void setDescription(String description) {
+ if (null != description) {
+ mDescription = description;
+ }
+ }
+
+ /**
+ * Returns the unique description associated with the plugin
+ *
+ * @return Unique description
+ */
+ public String getDescriprition() {
+ return mDescription;
+ }
+
+ /**
+ * Overridden hash code implementation
+ *
+ * @return Hash code value
+ */
+ public int hashCode() {
+ return mFileSuffixList.hashCode() + mMimeTypeList.hashCode() + mDescription.hashCode();
+ }
+
+ /**
+ * Overridden equals implementation
+ *
+ * @param object The object to be compared
+ * @return
+ * true if equal
+ * false if not equal
+ */
+ public boolean equals(Object object) {
+ boolean result = false;
+
+ if (object instanceof DrmSupportInfo) {
+ result = mFileSuffixList.equals(((DrmSupportInfo) object).mFileSuffixList) &&
+ mMimeTypeList.equals(((DrmSupportInfo) object).mMimeTypeList) &&
+ mDescription.equals(((DrmSupportInfo) object).mDescription);
+ }
+ return result;
+ }
+
+ /**
+ * Returns whether given mime-type is supported or not
+ *
+ * @param mimeType MIME type
+ * @return
+ * true if mime type is supported
+ * false if mime type is not supported
+ */
+ /* package */ boolean isSupportedMimeType(String mimeType) {
+ if (null != mimeType && !mimeType.equals("")) {
+ for (int i = 0; i < mMimeTypeList.size(); i++) {
+ String completeMimeType = mMimeTypeList.get(i);
+ if (completeMimeType.startsWith(mimeType)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns whether given file suffix is supported or not
+ *
+ * @param fileSuffix File suffix
+ * @return
+ * true - if file suffix is supported
+ * false - if file suffix is not supported
+ */
+ /* package */ boolean isSupportedFileSuffix(String fileSuffix) {
+ return mFileSuffixList.contains(fileSuffix);
+ }
+}
+
diff --git a/drm/java/android/drm/DrmUtils.java b/drm/java/android/drm/DrmUtils.java
new file mode 100644
index 0000000000000..5e5397c45874c
--- /dev/null
+++ b/drm/java/android/drm/DrmUtils.java
@@ -0,0 +1,188 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.drm;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Iterator;
+
+/**
+ * The utility class used in the DRM Framework. This inclueds APIs for file operations
+ * and ExtendedMetadataParser for parsing extended metadata BLOB in DRM constraints.
+ *
+ */
+public class DrmUtils {
+ /* Should be used when we need to read from local file */
+ /* package */ static byte[] readBytes(String path) throws IOException {
+ File file = new File(path);
+ return readBytes(file);
+ }
+
+ /* Should be used when we need to read from local file */
+ /* package */ static byte[] readBytes(File file) throws IOException {
+ FileInputStream inputStream = new FileInputStream(file);
+ BufferedInputStream bufferedStream = new BufferedInputStream(inputStream);
+ byte[] data = null;
+
+ try {
+ int length = bufferedStream.available();
+ if (length > 0) {
+ data = new byte[length];
+ // read the entire data
+ bufferedStream.read(data);
+ }
+ } finally {
+ quiteDispose(bufferedStream);
+ quiteDispose(inputStream);
+ }
+ return data;
+ }
+
+ /* package */ static void writeToFile(final String path, byte[] data) throws IOException {
+ /* check for invalid inputs */
+ FileOutputStream outputStream = null;
+
+ if (null != path && null != data) {
+ try {
+ outputStream = new FileOutputStream(path);
+ outputStream.write(data);
+ } finally {
+ quiteDispose(outputStream);
+ }
+ }
+ }
+
+ /* package */ static void removeFile(String path) throws IOException {
+ File file = new File(path);
+ file.delete();
+ }
+
+ private static void quiteDispose(InputStream stream) {
+ try {
+ if (null != stream) {
+ stream.close();
+ }
+ } catch (IOException e) {
+ // no need to care, at least as of now
+ }
+ }
+
+ private static void quiteDispose(OutputStream stream) {
+ try {
+ if (null != stream) {
+ stream.close();
+ }
+ } catch (IOException e) {
+ // no need to care
+ }
+ }
+
+ /**
+ * Get an instance of ExtendedMetadataParser to be used for parsing
+ * extended metadata BLOB in DRM constraints.
+ *
+ * extendedMetadata BLOB is retrieved by specifing
+ * key DrmStore.ConstraintsColumns.EXTENDED_METADATA.
+ *
+ * @param extendedMetadata BLOB in which key-value pairs of extended metadata are embedded.
+ *
+ */
+ public static ExtendedMetadataParser getExtendedMetadataParser(byte[] extendedMetadata) {
+ return new ExtendedMetadataParser(extendedMetadata);
+ }
+
+ /**
+ * Utility parser to parse the extended meta-data embedded inside DRM constraints
+ *
+ * Usage example
+ * byte[] extendedMetadata
+ * =
+ * constraints.getAsByteArray(DrmStore.ConstraintsColumns.EXTENDED_METADATA);
+ * ExtendedMetadataParser parser = getExtendedMetadataParser(extendedMetadata);
+ * Iterator keyIterator = parser.keyIterator();
+ * while (keyIterator.hasNext()) {
+ * String extendedMetadataKey = keyIterator.next();
+ * String extendedMetadataValue =
+ * parser.get(extendedMetadataKey);
+ * }
+ */
+ public static class ExtendedMetadataParser {
+ HashMap mMap = new HashMap();
+
+ private int readByte(byte[] constraintData, int arrayIndex) {
+ //Convert byte[] into int.
+ return (int)constraintData[arrayIndex];
+ }
+
+ private String readMultipleBytes(
+ byte[] constraintData, int numberOfBytes, int arrayIndex) {
+ byte[] returnBytes = new byte[numberOfBytes];
+ for (int j = arrayIndex, i = 0; j < arrayIndex + numberOfBytes; j++,i++) {
+ returnBytes[i] = constraintData[j];
+ }
+ return new String(returnBytes);
+ }
+
+ /*
+ * This will parse the following format
+ * KeyLengthValueLengthKeyValueKeyLength1ValueLength1Key1Value1..\0
+ */
+ private ExtendedMetadataParser(byte[] constraintData) {
+ //Extract KeyValue Pair Info, till terminator occurs.
+ int index = 0;
+
+ while (index < constraintData.length) {
+ //Parse Key Length
+ int keyLength = readByte(constraintData, index);
+ index++;
+
+ //Parse Value Length
+ int valueLength = readByte(constraintData, index);
+ index++;
+
+ //Fetch key
+ String strKey = readMultipleBytes(constraintData, keyLength, index);
+ index += keyLength;
+
+ //Fetch Value
+ String strValue = readMultipleBytes(constraintData, valueLength, index);
+ index += valueLength;
+ mMap.put(strKey, strValue);
+ }
+ }
+
+ public Iterator iterator() {
+ return mMap.values().iterator();
+ }
+
+ public Iterator keyIterator() {
+ return mMap.keySet().iterator();
+ }
+
+ public String get(String key) {
+ return mMap.get(key);
+ }
+ }
+}
+
diff --git a/drm/java/android/drm/ProcessedData.java b/drm/java/android/drm/ProcessedData.java
new file mode 100644
index 0000000000000..579264f00ba2f
--- /dev/null
+++ b/drm/java/android/drm/ProcessedData.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.drm;
+
+/**
+ * This is an entity class which wraps the result of transaction between
+ * device and online DRM server by using {@link DrmManagerClient#processDrmInfo(DrmInfo)}
+ *
+ * In license acquisition scenario this class would hold the binary data
+ * of rights information.
+ *
+ */
+public class ProcessedData {
+ private final byte[] mData;
+ private String mAccountId = "_NO_USER";
+ private String mSubscriptionId = "";
+
+ /**
+ * constructor to create ProcessedData object with given parameters
+ *
+ * @param data Rights data
+ * @param accountId Account Id of the user
+ */
+ /* package */ ProcessedData(byte[] data, String accountId) {
+ mData = data;
+ mAccountId = accountId;
+ }
+
+ /**
+ * constructor to create ProcessedData object with given parameters
+ *
+ * @param data Rights data
+ * @param accountId Account Id of the user
+ * @param subscriptionId Subscription Id of the user
+ */
+ /* package */ ProcessedData(byte[] data, String accountId, String subscriptionId) {
+ mData = data;
+ mAccountId = accountId;
+ mSubscriptionId = subscriptionId;
+ }
+
+ /**
+ * Returns the processed data as a result.
+ *
+ * @return Rights data associated
+ */
+ public byte[] getData() {
+ return mData;
+ }
+
+ /**
+ * Returns the account-id associated with this object
+ *
+ * @return Account Id associated
+ */
+ public String getAccountId() {
+ return mAccountId;
+ }
+
+ /**
+ * Returns the subscription-id associated with this object
+ *
+ * @return Subscription Id associated
+ */
+ public String getSubscriptionId() {
+ return mSubscriptionId;
+ }
+}
+
diff --git a/drm/jni/Android.mk b/drm/jni/Android.mk
new file mode 100644
index 0000000000000..0731755189b11
--- /dev/null
+++ b/drm/jni/Android.mk
@@ -0,0 +1,43 @@
+#
+# Copyright (C) 2010 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= \
+ android_drm_DrmManagerClient.cpp
+
+LOCAL_MODULE:= libdrmframework_jni
+
+LOCAL_SHARED_LIBRARIES := \
+ libdrmframework \
+ libutils \
+ libandroid_runtime \
+ libnativehelper \
+ libbinder \
+ libdl
+
+LOCAL_STATIC_LIBRARIES :=
+
+LOCAL_C_INCLUDES += \
+ $(JNI_H_INCLUDE) \
+ $(TOP)/frameworks/base/drm/libdrmframework/include \
+ $(TOP)/frameworks/base/drm/libdrmframework/plugins/common/include \
+ $(TOP)/frameworks/base/include
+
+LOCAL_PRELINK_MODULE := false
+
+include $(BUILD_SHARED_LIBRARY)
+
diff --git a/drm/jni/android_drm_DrmManagerClient.cpp b/drm/jni/android_drm_DrmManagerClient.cpp
new file mode 100644
index 0000000000000..bc5a7bfcd400a
--- /dev/null
+++ b/drm/jni/android_drm_DrmManagerClient.cpp
@@ -0,0 +1,755 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "DrmManager-JNI"
+#include
+
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+using namespace android;
+
+/**
+ * Utility class used to extract the value from the provided java object.
+ * May need to add some utility function to create java object.
+ */
+class Utility {
+public:
+ static String8 getStringValue(JNIEnv* env, jobject object, const char* fieldName);
+
+ static char* getByteArrayValue(
+ JNIEnv* env, jobject object, const char* fieldName, int* dataLength);
+
+ static char* getByteArrayValue(
+ JNIEnv* env, jbyteArray byteArray, int* dataLength);
+
+ static String8 getStringValue(JNIEnv* env, jstring string);
+
+ static int getIntValue(JNIEnv* env, jobject object, const char* fieldName);
+};
+
+String8 Utility::getStringValue(JNIEnv* env, jobject object, const char* fieldName) {
+ String8 dataString("");
+
+ /* Look for the instance field with the name fieldName */
+ jfieldID fieldID
+ = env->GetFieldID(env->GetObjectClass(object), fieldName , "Ljava/lang/String;");
+
+ if (NULL != fieldID) {
+ jstring valueString = (jstring) env->GetObjectField(object, fieldID);
+
+ if (NULL != valueString && valueString != env->NewStringUTF("")) {
+ char* bytes = const_cast< char* > (env->GetStringUTFChars(valueString, NULL));
+
+ const int length = strlen(bytes) + 1;
+ char *data = new char[length];
+ strncpy(data, bytes, length);
+ dataString = String8(data);
+
+ env->ReleaseStringUTFChars(valueString, bytes);
+ delete [] data; data = NULL;
+ } else {
+ LOGD("Failed to retrieve the data from the field %s", fieldName);
+ }
+ }
+ return dataString;
+}
+
+String8 Utility::getStringValue(JNIEnv* env, jstring string) {
+ String8 dataString("");
+
+ if (NULL != string && string != env->NewStringUTF("")) {
+ char* bytes = const_cast< char* > (env->GetStringUTFChars(string, NULL));
+
+ const int length = strlen(bytes) + 1;
+ char *data = new char[length];
+ strncpy(data, bytes, length);
+ dataString = String8(data);
+
+ env->ReleaseStringUTFChars(string, bytes);
+ delete [] data; data = NULL;
+ }
+ return dataString;
+}
+
+char* Utility::getByteArrayValue(
+ JNIEnv* env, jobject object, const char* fieldName, int* dataLength) {
+ char* data = NULL;
+ *dataLength = 0;
+
+ jfieldID fieldID = env->GetFieldID(env->GetObjectClass(object), fieldName , "[B");
+
+ if (NULL != fieldID) {
+ jbyteArray byteArray = (jbyteArray) env->GetObjectField(object, fieldID);
+ if (NULL != byteArray) {
+ jint length = env->GetArrayLength(byteArray);
+
+ *dataLength = length;
+ if (0 < *dataLength) {
+ data = new char[length];
+ env->GetByteArrayRegion(byteArray, (jint)0, length, (jbyte *) data);
+ }
+ }
+ }
+ return data;
+}
+
+char* Utility::getByteArrayValue(JNIEnv* env, jbyteArray byteArray, int* dataLength) {
+ char* data = NULL;
+ if (NULL != byteArray) {
+ jint length = env->GetArrayLength(byteArray);
+
+ *dataLength = length;
+ if (0 < *dataLength) {
+ data = new char[length];
+ env->GetByteArrayRegion(byteArray, (jint)0, length, (jbyte *) data);
+ }
+ }
+ return data;
+}
+
+int Utility::getIntValue(JNIEnv* env, jobject object, const char* fieldName) {
+ jfieldID fieldID;
+ int intValue = -1;
+
+ /* Get a reference to obj’s class */
+ jclass clazz = env->GetObjectClass(object);
+ /* Look for the instance field with the name fieldName */
+ fieldID = env->GetFieldID(clazz, fieldName , "I");
+
+ if (NULL != fieldID) {
+ intValue = (int) env->GetIntField(object, fieldID);
+ }
+
+ return intValue;
+}
+
+class JNIOnInfoListener : public DrmManagerClient::OnInfoListener {
+public:
+ JNIOnInfoListener(JNIEnv* env, jobject thiz, jobject weak_thiz);
+
+ virtual ~JNIOnInfoListener();
+ void onInfo(const DrmInfoEvent& event);
+
+private:
+ JNIOnInfoListener();
+ jclass mClass;
+ jobject mObject;
+};
+
+JNIOnInfoListener::JNIOnInfoListener(JNIEnv* env, jobject thiz, jobject weak_thiz) {
+ jclass clazz = env->GetObjectClass(thiz);
+
+ if (clazz == NULL) {
+ LOGE("Can't find android/drm/DrmManagerClient");
+ jniThrowException(env, "java/lang/Exception", NULL);
+ return;
+ }
+ mClass = (jclass)env->NewGlobalRef(clazz);
+ mObject = env->NewGlobalRef(weak_thiz);
+}
+
+JNIOnInfoListener::~JNIOnInfoListener() {
+ JNIEnv *env = AndroidRuntime::getJNIEnv();
+ env->DeleteGlobalRef(mObject);
+ env->DeleteGlobalRef(mClass);
+}
+
+void JNIOnInfoListener::onInfo(const DrmInfoEvent& event) {
+ jint uniqueId = event.getUniqueId();
+ jint type = event.getType();
+ JNIEnv *env = AndroidRuntime::getJNIEnv();
+ jstring message = env->NewStringUTF(event.getMessage().string());
+ LOGV("JNIOnInfoListener::onInfo => %d | %d | %s", uniqueId, type, event.getMessage().string());
+
+ env->CallStaticVoidMethod(
+ mClass,
+ env->GetStaticMethodID(mClass, "notify", "(Ljava/lang/Object;IILjava/lang/String;)V"),
+ mObject, uniqueId, type, message);
+}
+
+static Mutex sLock;
+
+static sp setDrmManagerClientImpl(
+ JNIEnv* env, jobject thiz, const sp& client) {
+ Mutex::Autolock l(sLock);
+ jclass clazz = env->FindClass("android/drm/DrmManagerClient");
+ jfieldID fieldId = env->GetFieldID(clazz, "mNativeContext", "I");
+
+ sp old = (DrmManagerClientImpl*)env->GetIntField(thiz, fieldId);
+ if (client.get()) {
+ client->incStrong(thiz);
+ }
+ if (old != 0) {
+ old->decStrong(thiz);
+ }
+ env->SetIntField(thiz, fieldId, (int)client.get());
+ return old;
+}
+
+static sp getDrmManagerClientImpl(JNIEnv* env, jobject thiz) {
+ Mutex::Autolock l(sLock);
+ jclass clazz = env->FindClass("android/drm/DrmManagerClient");
+ jfieldID fieldId = env->GetFieldID(clazz, "mNativeContext", "I");
+
+ DrmManagerClientImpl* const client = (DrmManagerClientImpl*)env->GetIntField(thiz, fieldId);
+ return sp(client);
+}
+
+static void android_drm_DrmManagerClient_loadPlugIns(
+ JNIEnv* env, jobject thiz, jint uniqueId, jobject weak_thiz) {
+ LOGV("load plugins - Enter");
+
+ sp drmManager = DrmManagerClientImpl::create(&uniqueId);
+
+ // Set the listener to DrmManager
+ sp listener = new JNIOnInfoListener(env, thiz, weak_thiz);
+ drmManager->setOnInfoListener(uniqueId, listener);
+
+ setDrmManagerClientImpl(env, thiz, drmManager);
+
+ getDrmManagerClientImpl(env, thiz)->loadPlugIns(uniqueId);
+ LOGV("load plugins - Exit");
+}
+
+static void android_drm_DrmManagerClient_unloadPlugIns(JNIEnv* env, jobject thiz, jint uniqueId) {
+ LOGV("unload plugins - Enter");
+ sp client = getDrmManagerClientImpl(env, thiz);
+ client->unloadPlugIns(uniqueId);
+ client->setOnInfoListener(uniqueId, NULL);
+ DrmManagerClientImpl::remove(uniqueId);
+
+ sp oldClient = setDrmManagerClientImpl(env, thiz, NULL);
+ if (oldClient != NULL) {
+ oldClient->setOnInfoListener(uniqueId, NULL);
+ }
+
+ LOGV("unload plugins - Exit");
+}
+
+static jobject android_drm_DrmManagerClient_getConstraintsFromContent(
+ JNIEnv* env, jobject thiz, jint uniqueId, jstring jpath, jint usage) {
+ LOGV("GetConstraints - Enter");
+
+ const String8 pathString = Utility::getStringValue(env, jpath);
+ DrmConstraints* pConstraints
+ = getDrmManagerClientImpl(env, thiz)->getConstraints(uniqueId, &pathString, usage);
+
+ jclass localRef = env->FindClass("android/content/ContentValues");
+ jobject constraints = NULL;
+
+ if (NULL != localRef && NULL != pConstraints) {
+ // Get the constructor id
+ jmethodID constructorId = env->GetMethodID(localRef, "", "()V");
+ // create the java DrmConstraints object
+ constraints = env->NewObject(localRef, constructorId);
+
+ DrmConstraints::KeyIterator keyIt = pConstraints->keyIterator();
+
+ while (keyIt.hasNext()) {
+ String8 key = keyIt.next();
+
+ // insert the entry to newly created java object
+ if (DrmConstraints::EXTENDED_METADATA == key) {
+ const char* value = pConstraints->getAsByteArray(&key);
+ if (NULL != value) {
+ jbyteArray dataArray = env->NewByteArray(strlen(value));
+ env->SetByteArrayRegion(dataArray, 0, strlen(value), (jbyte*)value);
+ env->CallVoidMethod(
+ constraints, env->GetMethodID(localRef, "put", "(Ljava/lang/String;[B)V"),
+ env->NewStringUTF(key.string()), dataArray);
+ }
+ } else {
+ String8 value = pConstraints->get(key);
+ env->CallVoidMethod(
+ constraints,
+ env->GetMethodID(localRef, "put", "(Ljava/lang/String;Ljava/lang/String;)V"),
+ env->NewStringUTF(key.string()), env->NewStringUTF(value.string()));
+ }
+ }
+ }
+
+ delete pConstraints; pConstraints = NULL;
+ LOGV("GetConstraints - Exit");
+ return constraints;
+}
+
+static jobjectArray android_drm_DrmManagerClient_getAllSupportInfo(
+ JNIEnv* env, jobject thiz, jint uniqueId) {
+ LOGV("GetAllSupportInfo - Enter");
+ DrmSupportInfo* drmSupportInfoArray = NULL;
+
+ int length = 0;
+ getDrmManagerClientImpl(env, thiz)->getAllSupportInfo(uniqueId, &length, &drmSupportInfoArray);
+
+ jclass clazz = env->FindClass("android/drm/DrmSupportInfo");
+
+ jobjectArray array = (jobjectArray)env->NewObjectArray(length, clazz, NULL);
+
+ for (int i = 0; i < length; i++) {
+ DrmSupportInfo info = drmSupportInfoArray[i];
+
+ jobject drmSupportInfo = env->NewObject(clazz, env->GetMethodID(clazz, "", "()V"));
+
+ jmethodID addMimeTypeId
+ = env->GetMethodID(clazz, "addMimeType", "(Ljava/lang/String;)V");
+ jmethodID addFileSuffixId
+ = env->GetMethodID(clazz, "addFileSuffix", "(Ljava/lang/String;)V");
+
+ env->CallVoidMethod(
+ drmSupportInfo, env->GetMethodID(clazz, "setDescription", "(Ljava/lang/String;)V"),
+ env->NewStringUTF(info.getDescription().string()));
+
+ DrmSupportInfo::MimeTypeIterator iterator = info.getMimeTypeIterator();
+ while (iterator.hasNext()) {
+ String8 value = iterator.next();
+ env->CallVoidMethod(drmSupportInfo, addMimeTypeId, env->NewStringUTF(value.string()));
+ }
+
+ DrmSupportInfo::FileSuffixIterator it = info.getFileSuffixIterator();
+ while (it.hasNext()) {
+ String8 value = it.next();
+ env->CallVoidMethod(
+ drmSupportInfo, addFileSuffixId, env->NewStringUTF(value.string()));
+ }
+
+ env->SetObjectArrayElement(array, i, drmSupportInfo);
+ }
+
+ delete [] drmSupportInfoArray; drmSupportInfoArray = NULL;
+ LOGV("GetAllSupportInfo - Exit");
+ return array;
+}
+
+static void android_drm_DrmManagerClient_installDrmEngine(
+ JNIEnv* env, jobject thiz, jint uniqueId, jstring engineFilePath) {
+ LOGV("installDrmEngine - Enter");
+ //getDrmManagerClient(env, thiz)
+ // ->installDrmEngine(uniqueId, Utility::getStringValue(env, engineFilePath));
+ LOGV("installDrmEngine - Exit");
+}
+
+static void android_drm_DrmManagerClient_saveRights(
+ JNIEnv* env, jobject thiz, jint uniqueId,
+ jobject drmRights, jstring rightsPath, jstring contentPath) {
+ LOGV("saveRights - Enter");
+ int dataLength = 0;
+ char* mData = Utility::getByteArrayValue(env, drmRights, "mData", &dataLength);
+
+ if (NULL != mData) {
+ DrmRights rights(DrmBuffer(mData, dataLength),
+ Utility::getStringValue(env, drmRights, "mMimeType"),
+ Utility::getStringValue(env, drmRights, "mAccountId"),
+ Utility::getStringValue(env, drmRights, "mSubscriptionId"));
+ getDrmManagerClientImpl(env, thiz)
+ ->saveRights(uniqueId, rights, Utility::getStringValue(env, rightsPath),
+ Utility::getStringValue(env, contentPath));
+ }
+
+ delete mData; mData = NULL;
+ LOGV("saveRights - Exit");
+}
+
+static jboolean android_drm_DrmManagerClient_canHandle(
+ JNIEnv* env, jobject thiz, jint uniqueId, jstring path, jstring mimeType) {
+ LOGV("canHandle - Enter");
+ jboolean result
+ = getDrmManagerClientImpl(env, thiz)
+ ->canHandle(uniqueId, Utility::getStringValue(env, path),
+ Utility::getStringValue(env, mimeType));
+ LOGV("canHandle - Exit");
+ return result;
+}
+
+static jobject android_drm_DrmManagerClient_processDrmInfo(
+ JNIEnv* env, jobject thiz, jint uniqueId, jobject drmInfoObject) {
+ LOGV("processDrmInfo - Enter");
+ int dataLength = 0;
+ const String8 mMimeType = Utility::getStringValue(env, drmInfoObject, "mMimeType");
+ char* mData = Utility::getByteArrayValue(env, drmInfoObject, "mData", &dataLength);
+ int mInfoType = Utility::getIntValue(env, drmInfoObject, "mInfoType");
+
+ const DrmBuffer buffer(mData, dataLength);
+ DrmInfo drmInfo(mInfoType, buffer, mMimeType);
+
+ jclass clazz = env->FindClass("android/drm/DrmInfo");
+ jobject keyIterator
+ = env->CallObjectMethod(drmInfoObject,
+ env->GetMethodID(clazz, "keyIterator", "()Ljava/util/Iterator;"));
+
+ jmethodID hasNextId = env->GetMethodID(env->FindClass("java/util/Iterator"), "hasNext", "()Z");
+
+ while (env->CallBooleanMethod(keyIterator, hasNextId)) {
+ jstring key = (jstring) env->CallObjectMethod(keyIterator,
+ env->GetMethodID(env->FindClass("java/util/Iterator"),
+ "next", "()Ljava/lang/Object;"));
+
+ jobject valueObject = env->CallObjectMethod(drmInfoObject,
+ env->GetMethodID(clazz, "get", "(Ljava/lang/String;)Ljava/lang/Object;"), key);
+
+ jstring valString = NULL;
+ if (NULL != valueObject) {
+ valString = (jstring) env->CallObjectMethod(valueObject,
+ env->GetMethodID(env->FindClass("java/lang/Object"),
+ "toString", "()Ljava/lang/String;"));
+ }
+
+ String8 keyString = Utility::getStringValue(env, key);
+ String8 valueString = Utility::getStringValue(env, valString);
+ LOGD("Key: %s | Value: %s", keyString.string(), valueString.string());
+
+ drmInfo.put(keyString, valueString);
+ }
+
+ DrmInfoStatus* pDrmInfoStatus
+ = getDrmManagerClientImpl(env, thiz)->processDrmInfo(uniqueId, &drmInfo);
+
+ jclass localRef = env->FindClass("android/drm/DrmInfoStatus");
+ jobject drmInfoStatus = NULL;
+
+ if (NULL != localRef && NULL != pDrmInfoStatus) {
+ int statusCode = pDrmInfoStatus->statusCode;
+
+ jbyteArray dataArray = NULL;
+ if (NULL != pDrmInfoStatus->drmBuffer) {
+ int length = pDrmInfoStatus->drmBuffer->length;
+ dataArray = env->NewByteArray(length);
+ env->SetByteArrayRegion(
+ dataArray, 0, length, (jbyte*) pDrmInfoStatus->drmBuffer->data);
+
+ delete [] pDrmInfoStatus->drmBuffer->data;
+ delete pDrmInfoStatus->drmBuffer; pDrmInfoStatus->drmBuffer = NULL;
+ }
+ jclass clazz = env->FindClass("android/drm/ProcessedData");
+ jmethodID constructorId
+ = env->GetMethodID(clazz, "", "([BLjava/lang/String;Ljava/lang/String;)V");
+ jobject processedData = env->NewObject(clazz, constructorId, dataArray,
+ env->NewStringUTF((drmInfo.get(DrmInfoRequest::ACCOUNT_ID)).string()),
+ env->NewStringUTF((drmInfo.get(DrmInfoRequest::SUBSCRIPTION_ID)).string()));
+
+ constructorId
+ = env->GetMethodID(localRef,
+ "", "(ILandroid/drm/ProcessedData;Ljava/lang/String;)V");
+
+ drmInfoStatus = env->NewObject(localRef, constructorId, statusCode, processedData,
+ env->NewStringUTF(pDrmInfoStatus->mimeType.string()));
+ }
+
+ delete mData; mData = NULL;
+ delete pDrmInfoStatus; pDrmInfoStatus = NULL;
+
+ LOGV("processDrmInfo - Exit");
+ return drmInfoStatus;
+}
+
+static jobject android_drm_DrmManagerClient_acquireDrmInfo(
+ JNIEnv* env, jobject thiz, jint uniqueId, jobject drmInfoRequest) {
+ LOGV("acquireDrmInfo Enter");
+ const String8 mMimeType = Utility::getStringValue(env, drmInfoRequest, "mMimeType");
+ int mInfoType = Utility::getIntValue(env, drmInfoRequest, "mInfoType");
+
+ DrmInfoRequest drmInfoReq(mInfoType, mMimeType);
+
+ jclass clazz = env->FindClass("android/drm/DrmInfoRequest");
+ jobject keyIterator
+ = env->CallObjectMethod(drmInfoRequest,
+ env->GetMethodID(clazz, "keyIterator", "()Ljava/util/Iterator;"));
+
+ jmethodID hasNextId = env->GetMethodID(env->FindClass("java/util/Iterator"), "hasNext", "()Z");
+
+ while (env->CallBooleanMethod(keyIterator, hasNextId)) {
+ jstring key
+ = (jstring) env->CallObjectMethod(keyIterator,
+ env->GetMethodID(env->FindClass("java/util/Iterator"),
+ "next", "()Ljava/lang/Object;"));
+
+ jstring value = (jstring) env->CallObjectMethod(drmInfoRequest,
+ env->GetMethodID(clazz, "get", "(Ljava/lang/String;)Ljava/lang/Object;"), key);
+
+ String8 keyString = Utility::getStringValue(env, key);
+ String8 valueString = Utility::getStringValue(env, value);
+ LOGD("Key: %s | Value: %s", keyString.string(), valueString.string());
+
+ drmInfoReq.put(keyString, valueString);
+ }
+
+ DrmInfo* pDrmInfo = getDrmManagerClientImpl(env, thiz)->acquireDrmInfo(uniqueId, &drmInfoReq);
+
+ jobject drmInfoObject = NULL;
+
+ if (NULL != pDrmInfo) {
+ jclass localRef = env->FindClass("android/drm/DrmInfo");
+
+ if (NULL != localRef) {
+ int length = pDrmInfo->getData().length;
+
+ jbyteArray dataArray = env->NewByteArray(length);
+ env->SetByteArrayRegion(dataArray, 0, length, (jbyte*)pDrmInfo->getData().data);
+
+ drmInfoObject
+ = env->NewObject(localRef,
+ env->GetMethodID(localRef, "", "(I[BLjava/lang/String;)V"),
+ mInfoType, dataArray, env->NewStringUTF(pDrmInfo->getMimeType().string()));
+
+ DrmInfo::KeyIterator it = pDrmInfo->keyIterator();
+ jmethodID putMethodId
+ = env->GetMethodID(localRef, "put", "(Ljava/lang/String;Ljava/lang/Object;)V");
+
+ while (it.hasNext()) {
+ String8 key = it.next();
+ String8 value = pDrmInfo->get(key);
+
+ env->CallVoidMethod(drmInfoObject, putMethodId,
+ env->NewStringUTF(key.string()), env->NewStringUTF(value.string()));
+ }
+ }
+ delete [] pDrmInfo->getData().data;
+ }
+
+ delete pDrmInfo; pDrmInfo = NULL;
+
+ LOGV("acquireDrmInfo Exit");
+ return drmInfoObject;
+}
+
+static jint android_drm_DrmManagerClient_getDrmObjectType(
+ JNIEnv* env, jobject thiz, jint uniqueId, jstring path, jstring mimeType) {
+ LOGV("getDrmObjectType Enter");
+ int drmObjectType
+ = getDrmManagerClientImpl(env, thiz)
+ ->getDrmObjectType(uniqueId, Utility::getStringValue(env, path),
+ Utility::getStringValue(env, mimeType));
+ LOGV("getDrmObjectType Exit");
+ return drmObjectType;
+}
+
+static jstring android_drm_DrmManagerClient_getOriginalMimeType(
+ JNIEnv* env, jobject thiz, jint uniqueId, jstring path) {
+ LOGV("getOriginalMimeType Enter");
+ String8 mimeType
+ = getDrmManagerClientImpl(env, thiz)
+ ->getOriginalMimeType(uniqueId, Utility::getStringValue(env, path));
+ LOGV("getOriginalMimeType Exit");
+ return env->NewStringUTF(mimeType.string());
+}
+
+static jint android_drm_DrmManagerClient_checkRightsStatus(
+ JNIEnv* env, jobject thiz, jint uniqueId, jstring path, int action) {
+ LOGV("getOriginalMimeType Enter");
+ int rightsStatus
+ = getDrmManagerClientImpl(env, thiz)
+ ->checkRightsStatus(uniqueId, Utility::getStringValue(env, path), action);
+ LOGV("getOriginalMimeType Exit");
+ return rightsStatus;
+}
+
+static void android_drm_DrmManagerClient_removeRights(
+ JNIEnv* env, jobject thiz, jint uniqueId, jstring path) {
+ LOGV("removeRights Enter");
+ getDrmManagerClientImpl(env, thiz)->removeRights(uniqueId, Utility::getStringValue(env, path));
+ LOGV("removeRights Exit");
+}
+
+static void android_drm_DrmManagerClient_removeAllRights(
+ JNIEnv* env, jobject thiz, jint uniqueId) {
+ LOGV("removeAllRights Enter");
+ getDrmManagerClientImpl(env, thiz)->removeAllRights(uniqueId);
+ LOGV("removeAllRights Exit");
+}
+
+static jint android_drm_DrmManagerClient_openConvertSession(
+ JNIEnv* env, jobject thiz, jint uniqueId, jstring mimeType) {
+ LOGV("openConvertSession Enter");
+ int convertId
+ = getDrmManagerClientImpl(env, thiz)
+ ->openConvertSession(uniqueId, Utility::getStringValue(env, mimeType));
+ LOGV("openConvertSession Exit");
+ return convertId;
+}
+
+static jobject android_drm_DrmManagerClient_convertData(
+ JNIEnv* env, jobject thiz, jint uniqueId, jint convertId, jbyteArray inputData) {
+ LOGV("convertData Enter");
+
+ int dataLength = 0;
+ char* mData = Utility::getByteArrayValue(env, inputData, &dataLength);
+ const DrmBuffer buffer(mData, dataLength);
+
+ DrmConvertedStatus* pDrmConvertedStatus
+ = getDrmManagerClientImpl(env, thiz)->convertData(uniqueId, convertId, &buffer);
+
+ jclass localRef = env->FindClass("android/drm/DrmConvertedStatus");
+
+ jobject drmConvertedStatus = NULL;
+
+ if (NULL != localRef && NULL != pDrmConvertedStatus) {
+ int statusCode = pDrmConvertedStatus->statusCode;
+
+ jbyteArray dataArray = NULL;
+ if (NULL != pDrmConvertedStatus->convertedData) {
+ int length = pDrmConvertedStatus->convertedData->length;
+ dataArray = env->NewByteArray(length);
+ env->SetByteArrayRegion(dataArray, 0, length,
+ (jbyte*) pDrmConvertedStatus->convertedData->data);
+
+ delete [] pDrmConvertedStatus->convertedData->data;
+ delete pDrmConvertedStatus->convertedData; pDrmConvertedStatus->convertedData = NULL;
+ }
+ jmethodID constructorId = env->GetMethodID(localRef, "", "(I[BI)V");
+ drmConvertedStatus
+ = env->NewObject(localRef, constructorId,
+ statusCode, dataArray, pDrmConvertedStatus->offset);
+ }
+
+ delete mData; mData = NULL;
+ delete pDrmConvertedStatus; pDrmConvertedStatus = NULL;
+
+ LOGV("convertData - Exit");
+ return drmConvertedStatus;
+}
+
+static jobject android_drm_DrmManagerClient_closeConvertSession(
+ JNIEnv* env, jobject thiz, int uniqueId, jint convertId) {
+
+ LOGV("closeConvertSession Enter");
+
+ DrmConvertedStatus* pDrmConvertedStatus
+ = getDrmManagerClientImpl(env, thiz)->closeConvertSession(uniqueId, convertId);
+
+ jclass localRef = env->FindClass("android/drm/DrmConvertedStatus");
+
+ jobject drmConvertedStatus = NULL;
+
+ if (NULL != localRef && NULL != pDrmConvertedStatus) {
+ int statusCode = pDrmConvertedStatus->statusCode;
+
+ jbyteArray dataArray = NULL;
+ if (NULL != pDrmConvertedStatus->convertedData) {
+ int length = pDrmConvertedStatus->convertedData->length;
+ dataArray = env->NewByteArray(length);
+ env->SetByteArrayRegion(
+ dataArray, 0, length, (jbyte*) pDrmConvertedStatus->convertedData->data);
+
+ delete [] pDrmConvertedStatus->convertedData->data;
+ delete pDrmConvertedStatus->convertedData; pDrmConvertedStatus->convertedData = NULL;
+ }
+ jmethodID constructorId = env->GetMethodID(localRef, "", "(I[BI)V");
+ drmConvertedStatus
+ = env->NewObject(localRef, constructorId,
+ statusCode, dataArray, pDrmConvertedStatus->offset);
+ }
+
+ delete pDrmConvertedStatus; pDrmConvertedStatus = NULL;
+
+ LOGV("closeConvertSession - Exit");
+ return drmConvertedStatus;
+}
+
+static JNINativeMethod nativeMethods[] = {
+
+ {"_loadPlugIns", "(ILjava/lang/Object;)V",
+ (void*)android_drm_DrmManagerClient_loadPlugIns},
+
+ {"_unloadPlugIns", "(I)V",
+ (void*)android_drm_DrmManagerClient_unloadPlugIns},
+
+ {"_getConstraints", "(ILjava/lang/String;I)Landroid/content/ContentValues;",
+ (void*)android_drm_DrmManagerClient_getConstraintsFromContent},
+
+ {"_getAllSupportInfo", "(I)[Landroid/drm/DrmSupportInfo;",
+ (void*)android_drm_DrmManagerClient_getAllSupportInfo},
+
+ {"_installDrmEngine", "(ILjava/lang/String;)V",
+ (void*)android_drm_DrmManagerClient_installDrmEngine},
+
+ {"_canHandle", "(ILjava/lang/String;Ljava/lang/String;)Z",
+ (void*)android_drm_DrmManagerClient_canHandle},
+
+ {"_processDrmInfo", "(ILandroid/drm/DrmInfo;)Landroid/drm/DrmInfoStatus;",
+ (void*)android_drm_DrmManagerClient_processDrmInfo},
+
+ {"_acquireDrmInfo", "(ILandroid/drm/DrmInfoRequest;)Landroid/drm/DrmInfo;",
+ (void*)android_drm_DrmManagerClient_acquireDrmInfo},
+
+ {"_saveRights", "(ILandroid/drm/DrmRights;Ljava/lang/String;Ljava/lang/String;)V",
+ (void*)android_drm_DrmManagerClient_saveRights},
+
+ {"_getDrmObjectType", "(ILjava/lang/String;Ljava/lang/String;)I",
+ (void*)android_drm_DrmManagerClient_getDrmObjectType},
+
+ {"_getOriginalMimeType", "(ILjava/lang/String;)Ljava/lang/String;",
+ (void*)android_drm_DrmManagerClient_getOriginalMimeType},
+
+ {"_checkRightsStatus", "(ILjava/lang/String;I)I",
+ (void*)android_drm_DrmManagerClient_checkRightsStatus},
+
+ {"_removeRights", "(ILjava/lang/String;)V",
+ (void*)android_drm_DrmManagerClient_removeRights},
+
+ {"_removeAllRights", "(I)V",
+ (void*)android_drm_DrmManagerClient_removeAllRights},
+
+ {"_openConvertSession", "(ILjava/lang/String;)I",
+ (void*)android_drm_DrmManagerClient_openConvertSession},
+
+ {"_convertData", "(II[B)Landroid/drm/DrmConvertedStatus;",
+ (void*)android_drm_DrmManagerClient_convertData},
+
+ {"_closeConvertSession", "(II)Landroid/drm/DrmConvertedStatus;",
+ (void*)android_drm_DrmManagerClient_closeConvertSession},
+};
+
+static int registerNativeMethods(JNIEnv* env) {
+ int result = -1;
+
+ /* look up the class */
+ jclass clazz = env->FindClass("android/drm/DrmManagerClient");
+
+ if (NULL != clazz) {
+ if (env->RegisterNatives(clazz, nativeMethods, sizeof(nativeMethods)
+ / sizeof(nativeMethods[0])) == JNI_OK) {
+ result = 0;
+ }
+ }
+ return result;
+}
+
+jint JNI_OnLoad(JavaVM* vm, void* reserved) {
+ JNIEnv* env = NULL;
+ jint result = -1;
+
+ if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) == JNI_OK) {
+ if (NULL != env && registerNativeMethods(env) == 0) {
+ result = JNI_VERSION_1_4;
+ }
+ }
+ return result;
+}
+
diff --git a/drm/libdrmframework/Android.mk b/drm/libdrmframework/Android.mk
new file mode 100644
index 0000000000000..c25d79bd931c3
--- /dev/null
+++ b/drm/libdrmframework/Android.mk
@@ -0,0 +1,42 @@
+#
+# Copyright (C) 2010 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= \
+ DrmManagerClientImpl.cpp \
+ DrmManagerClient.cpp
+
+LOCAL_MODULE:= libdrmframework
+
+LOCAL_SHARED_LIBRARIES := \
+ libutils \
+ libbinder \
+ libdl
+
+LOCAL_STATIC_LIBRARIES := \
+ libdrmframeworkcommon
+
+LOCAL_C_INCLUDES += \
+ $(TOP)/frameworks/base/drm/libdrmframework/include \
+ $(TOP)/frameworks/base/include
+
+LOCAL_PRELINK_MODULE := false
+
+include $(BUILD_SHARED_LIBRARY)
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/drm/libdrmframework/DrmManagerClient.cpp b/drm/libdrmframework/DrmManagerClient.cpp
new file mode 100644
index 0000000000000..06c7c50a214d1
--- /dev/null
+++ b/drm/libdrmframework/DrmManagerClient.cpp
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "DrmManagerClient(Native)"
+#include
+
+#include
+#include
+#include
+
+#include "DrmManagerClientImpl.h"
+
+using namespace android;
+
+DrmManagerClient::DrmManagerClient() {
+ int uniqueId = 0;
+ mDrmManagerClientImpl = NULL;
+
+ mDrmManagerClientImpl = DrmManagerClientImpl::create(&uniqueId);
+ mUniqueId = uniqueId;
+
+ loadPlugIns();
+}
+
+DrmManagerClient::~DrmManagerClient() {
+ unloadPlugIns();
+ DrmManagerClientImpl::remove(mUniqueId);
+
+ delete mDrmManagerClientImpl; mDrmManagerClientImpl = NULL;
+}
+
+status_t DrmManagerClient::loadPlugIns() {
+ return mDrmManagerClientImpl->loadPlugIns(mUniqueId);
+}
+
+status_t DrmManagerClient::setOnInfoListener(
+ const sp& infoListener) {
+ return mDrmManagerClientImpl->setOnInfoListener(mUniqueId, infoListener);
+}
+
+status_t DrmManagerClient::unloadPlugIns() {
+ return mDrmManagerClientImpl->unloadPlugIns(mUniqueId);
+}
+
+DrmConstraints* DrmManagerClient::getConstraints(const String8* path, const int action) {
+ return mDrmManagerClientImpl->getConstraints(mUniqueId, path, action);
+}
+
+bool DrmManagerClient::canHandle(const String8& path, const String8& mimeType) {
+ return mDrmManagerClientImpl->canHandle(mUniqueId, path, mimeType);
+}
+
+DrmInfoStatus* DrmManagerClient::processDrmInfo(const DrmInfo* drmInfo) {
+ return mDrmManagerClientImpl->processDrmInfo(mUniqueId, drmInfo);
+}
+
+DrmInfo* DrmManagerClient::acquireDrmInfo(const DrmInfoRequest* drmInfoRequest) {
+ return mDrmManagerClientImpl->acquireDrmInfo(mUniqueId, drmInfoRequest);
+}
+
+void DrmManagerClient::saveRights(
+ const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) {
+ return mDrmManagerClientImpl->saveRights(mUniqueId, drmRights, rightsPath, contentPath);
+}
+
+String8 DrmManagerClient::getOriginalMimeType(const String8& path) {
+ return mDrmManagerClientImpl->getOriginalMimeType(mUniqueId, path);
+}
+
+int DrmManagerClient::getDrmObjectType(const String8& path, const String8& mimeType) {
+ return mDrmManagerClientImpl->getDrmObjectType( mUniqueId, path, mimeType);
+}
+
+int DrmManagerClient::checkRightsStatus(const String8& path, int action) {
+ return mDrmManagerClientImpl->checkRightsStatus(mUniqueId, path, action);
+}
+
+void DrmManagerClient::consumeRights(DecryptHandle* decryptHandle, int action, bool reserve) {
+ mDrmManagerClientImpl->consumeRights(mUniqueId, decryptHandle, action, reserve);
+}
+
+void DrmManagerClient::setPlaybackStatus(
+ DecryptHandle* decryptHandle, int playbackStatus, int position) {
+ mDrmManagerClientImpl->setPlaybackStatus(mUniqueId, decryptHandle, playbackStatus, position);
+}
+
+bool DrmManagerClient::validateAction(
+ const String8& path, int action, const ActionDescription& description) {
+ return mDrmManagerClientImpl->validateAction(mUniqueId, path, action, description);
+}
+
+void DrmManagerClient::removeRights(const String8& path) {
+ mDrmManagerClientImpl->removeRights(mUniqueId, path);
+}
+
+void DrmManagerClient::removeAllRights() {
+ mDrmManagerClientImpl->removeAllRights(mUniqueId);
+}
+
+int DrmManagerClient::openConvertSession(const String8& mimeType) {
+ return mDrmManagerClientImpl->openConvertSession(mUniqueId, mimeType);
+}
+
+DrmConvertedStatus* DrmManagerClient::convertData(int convertId, const DrmBuffer* inputData) {
+ return mDrmManagerClientImpl->convertData(mUniqueId, convertId, inputData);
+}
+
+DrmConvertedStatus* DrmManagerClient::closeConvertSession(int convertId) {
+ return mDrmManagerClientImpl->closeConvertSession(mUniqueId, convertId);
+}
+
+status_t DrmManagerClient::getAllSupportInfo(int* length, DrmSupportInfo** drmSupportInfoArray) {
+ return mDrmManagerClientImpl->getAllSupportInfo(mUniqueId, length, drmSupportInfoArray);
+}
+
+DecryptHandle* DrmManagerClient::openDecryptSession(int fd, int offset, int length) {
+ return mDrmManagerClientImpl->openDecryptSession(mUniqueId, fd, offset, length);
+}
+
+void DrmManagerClient::closeDecryptSession(DecryptHandle* decryptHandle) {
+ mDrmManagerClientImpl->closeDecryptSession(mUniqueId, decryptHandle);
+}
+
+void DrmManagerClient::initializeDecryptUnit(
+ DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) {
+ mDrmManagerClientImpl->initializeDecryptUnit(
+ mUniqueId, decryptHandle, decryptUnitId, headerInfo);
+}
+
+status_t DrmManagerClient::decrypt(
+ DecryptHandle* decryptHandle, int decryptUnitId,
+ const DrmBuffer* encBuffer, DrmBuffer** decBuffer) {
+ return mDrmManagerClientImpl->decrypt(
+ mUniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer);
+}
+
+void DrmManagerClient::finalizeDecryptUnit(DecryptHandle* decryptHandle, int decryptUnitId) {
+ mDrmManagerClientImpl->finalizeDecryptUnit(mUniqueId, decryptHandle, decryptUnitId);
+}
+
+ssize_t DrmManagerClient::pread(
+ DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off_t offset) {
+ return mDrmManagerClientImpl->pread(mUniqueId, decryptHandle, buffer, numBytes, offset);
+}
+
diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp
new file mode 100644
index 0000000000000..7274b49d12bd8
--- /dev/null
+++ b/drm/libdrmframework/DrmManagerClientImpl.cpp
@@ -0,0 +1,319 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "DrmManagerClientImpl(Native)"
+#include
+
+#include
+#include
+#include
+
+#include "DrmManagerClientImpl.h"
+
+using namespace android;
+
+#define INVALID_VALUE -1
+
+Mutex DrmManagerClientImpl::mMutex;
+Vector DrmManagerClientImpl::mUniqueIdVector;
+sp DrmManagerClientImpl::mDrmManagerService;
+const String8 DrmManagerClientImpl::EMPTY_STRING("");
+
+DrmManagerClientImpl* DrmManagerClientImpl::create(int* pUniqueId) {
+ if (0 == *pUniqueId) {
+ int uniqueId = 0;
+ bool foundUniqueId = false;
+ srand(time(NULL));
+
+ while (!foundUniqueId) {
+ const int size = mUniqueIdVector.size();
+ uniqueId = rand() % 100;
+
+ int index = 0;
+ for (; index < size; ++index) {
+ if (mUniqueIdVector.itemAt(index) == uniqueId) {
+ foundUniqueId = false;
+ break;
+ }
+ }
+ if (index == size) {
+ foundUniqueId = true;
+ }
+ }
+ *pUniqueId = uniqueId;
+ }
+ mUniqueIdVector.push(*pUniqueId);
+ return new DrmManagerClientImpl();
+}
+
+void DrmManagerClientImpl::remove(int uniqueId) {
+ for (int i = 0; i < mUniqueIdVector.size(); i++) {
+ if (uniqueId == mUniqueIdVector.itemAt(i)) {
+ mUniqueIdVector.removeAt(i);
+ break;
+ }
+ }
+}
+
+DrmManagerClientImpl::DrmManagerClientImpl() {
+
+}
+
+DrmManagerClientImpl::~DrmManagerClientImpl() {
+
+}
+
+const sp& DrmManagerClientImpl::getDrmManagerService() {
+ mMutex.lock();
+ if (NULL == mDrmManagerService.get()) {
+ sp sm = defaultServiceManager();
+ sp binder;
+ do {
+ binder = sm->getService(String16("drm.drmManager"));
+ if (binder != 0) {
+ break;
+ }
+ LOGW("DrmManagerService not published, waiting...");
+ struct timespec reqt;
+ reqt.tv_sec = 0;
+ reqt.tv_nsec = 500000000; //0.5 sec
+ nanosleep(&reqt, NULL);
+ } while (true);
+
+ mDrmManagerService = interface_cast(binder);
+ }
+ mMutex.unlock();
+ return mDrmManagerService;
+}
+
+status_t DrmManagerClientImpl::loadPlugIns(int uniqueId) {
+ return getDrmManagerService()->loadPlugIns(uniqueId);
+}
+
+status_t DrmManagerClientImpl::loadPlugIns(int uniqueId, const String8& plugInDirPath) {
+ status_t status = DRM_ERROR_UNKNOWN;
+ if (EMPTY_STRING != plugInDirPath) {
+ status = getDrmManagerService()->loadPlugIns(uniqueId, plugInDirPath);
+ }
+ return status;
+}
+
+status_t DrmManagerClientImpl::setOnInfoListener(
+ int uniqueId, const sp& infoListener) {
+ Mutex::Autolock _l(mLock);
+ mOnInfoListener = infoListener;
+ return getDrmManagerService()->setDrmServiceListener(uniqueId, this);
+}
+
+status_t DrmManagerClientImpl::unloadPlugIns(int uniqueId) {
+ return getDrmManagerService()->unloadPlugIns(uniqueId);
+}
+
+status_t DrmManagerClientImpl::installDrmEngine(int uniqueId, const String8& drmEngineFile) {
+ status_t status = DRM_ERROR_UNKNOWN;
+ if (EMPTY_STRING != drmEngineFile) {
+ status = getDrmManagerService()->installDrmEngine(uniqueId, drmEngineFile);
+ }
+ return status;
+}
+
+DrmConstraints* DrmManagerClientImpl::getConstraints(
+ int uniqueId, const String8* path, const int action) {
+ DrmConstraints *drmConstraints = NULL;
+ if ((NULL != path) && (EMPTY_STRING != *path)) {
+ drmConstraints = getDrmManagerService()->getConstraints(uniqueId, path, action);
+ }
+ return drmConstraints;
+}
+
+bool DrmManagerClientImpl::canHandle(int uniqueId, const String8& path, const String8& mimeType) {
+ bool retCode = false;
+ if ((EMPTY_STRING != path) || (EMPTY_STRING != mimeType)) {
+ retCode = getDrmManagerService()->canHandle(uniqueId, path, mimeType);
+ }
+ return retCode;
+}
+
+DrmInfoStatus* DrmManagerClientImpl::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) {
+ DrmInfoStatus *drmInfoStatus = NULL;
+ if (NULL != drmInfo) {
+ drmInfoStatus = getDrmManagerService()->processDrmInfo(uniqueId, drmInfo);
+ }
+ return drmInfoStatus;
+}
+
+DrmInfo* DrmManagerClientImpl::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) {
+ DrmInfo* drmInfo = NULL;
+ if (NULL != drmInfoRequest) {
+ drmInfo = getDrmManagerService()->acquireDrmInfo(uniqueId, drmInfoRequest);
+ }
+ return drmInfo;
+}
+
+void DrmManagerClientImpl::saveRights(int uniqueId, const DrmRights& drmRights,
+ const String8& rightsPath, const String8& contentPath) {
+ if (EMPTY_STRING != contentPath) {
+ getDrmManagerService()->saveRights(uniqueId, drmRights, rightsPath, contentPath);
+ }
+}
+
+String8 DrmManagerClientImpl::getOriginalMimeType(int uniqueId, const String8& path) {
+ String8 mimeType = EMPTY_STRING;
+ if (EMPTY_STRING != path) {
+ mimeType = getDrmManagerService()->getOriginalMimeType(uniqueId, path);
+ }
+ return mimeType;
+}
+
+int DrmManagerClientImpl::getDrmObjectType(
+ int uniqueId, const String8& path, const String8& mimeType) {
+ int drmOjectType = DrmObjectType::UNKNOWN;
+ if ((EMPTY_STRING != path) || (EMPTY_STRING != mimeType)) {
+ drmOjectType = getDrmManagerService()->getDrmObjectType(uniqueId, path, mimeType);
+ }
+ return drmOjectType;
+}
+
+int DrmManagerClientImpl::checkRightsStatus(
+ int uniqueId, const String8& path, int action) {
+ int rightsStatus = RightsStatus::RIGHTS_INVALID;
+ if (EMPTY_STRING != path) {
+ rightsStatus = getDrmManagerService()->checkRightsStatus(uniqueId, path, action);
+ }
+ return rightsStatus;
+}
+
+void DrmManagerClientImpl::consumeRights(
+ int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) {
+ if (NULL != decryptHandle) {
+ getDrmManagerService()->consumeRights(uniqueId, decryptHandle, action, reserve);
+ }
+}
+
+void DrmManagerClientImpl::setPlaybackStatus(
+ int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) {
+ if (NULL != decryptHandle) {
+ getDrmManagerService()->setPlaybackStatus(
+ uniqueId, decryptHandle, playbackStatus, position);
+ }
+}
+
+bool DrmManagerClientImpl::validateAction(
+ int uniqueId, const String8& path, int action, const ActionDescription& description) {
+ bool retCode = false;
+ if (EMPTY_STRING != path) {
+ retCode = getDrmManagerService()->validateAction(uniqueId, path, action, description);
+ }
+ return retCode;
+}
+
+void DrmManagerClientImpl::removeRights(int uniqueId, const String8& path) {
+ if (EMPTY_STRING != path) {
+ getDrmManagerService()->removeRights(uniqueId, path);
+ }
+}
+
+void DrmManagerClientImpl::removeAllRights(int uniqueId) {
+ getDrmManagerService()->removeAllRights(uniqueId);
+}
+
+int DrmManagerClientImpl::openConvertSession(int uniqueId, const String8& mimeType) {
+ int retCode = INVALID_VALUE;
+ if (EMPTY_STRING != mimeType) {
+ retCode = getDrmManagerService()->openConvertSession(uniqueId, mimeType);
+ }
+ return retCode;
+}
+
+DrmConvertedStatus* DrmManagerClientImpl::convertData(
+ int uniqueId, int convertId, const DrmBuffer* inputData) {
+ DrmConvertedStatus* drmConvertedStatus = NULL;
+ if (NULL != inputData) {
+ drmConvertedStatus = getDrmManagerService()->convertData(uniqueId, convertId, inputData);
+ }
+ return drmConvertedStatus;
+}
+
+DrmConvertedStatus* DrmManagerClientImpl::closeConvertSession(int uniqueId, int convertId) {
+ return getDrmManagerService()->closeConvertSession(uniqueId, convertId);
+}
+
+status_t DrmManagerClientImpl::getAllSupportInfo(
+ int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) {
+ status_t status = DRM_ERROR_UNKNOWN;
+ if ((NULL != drmSupportInfoArray) && (NULL != length)) {
+ status = getDrmManagerService()->getAllSupportInfo(uniqueId, length, drmSupportInfoArray);
+ }
+ return status;
+}
+
+DecryptHandle* DrmManagerClientImpl::openDecryptSession(
+ int uniqueId, int fd, int offset, int length) {
+ LOGV("Entering DrmManagerClientImpl::openDecryptSession");
+ return getDrmManagerService()->openDecryptSession(uniqueId, fd, offset, length);
+}
+
+void DrmManagerClientImpl::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
+ if (NULL != decryptHandle) {
+ getDrmManagerService()->closeDecryptSession( uniqueId, decryptHandle);
+ }
+}
+
+void DrmManagerClientImpl::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* headerInfo) {
+ if ((NULL != decryptHandle) && (NULL != headerInfo)) {
+ getDrmManagerService()->initializeDecryptUnit(
+ uniqueId, decryptHandle, decryptUnitId, headerInfo);
+ }
+}
+
+status_t DrmManagerClientImpl::decrypt(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) {
+ status_t status = DRM_ERROR_UNKNOWN;
+ if ((NULL != decryptHandle) && (NULL != encBuffer)
+ && (NULL != decBuffer) && (NULL != *decBuffer)) {
+ status = getDrmManagerService()->decrypt(
+ uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer);
+ }
+ return status;
+}
+
+void DrmManagerClientImpl::finalizeDecryptUnit(
+ int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
+ if (NULL != decryptHandle) {
+ getDrmManagerService()->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
+ }
+}
+
+ssize_t DrmManagerClientImpl::pread(int uniqueId, DecryptHandle* decryptHandle,
+ void* buffer, ssize_t numBytes, off_t offset) {
+ ssize_t retCode = INVALID_VALUE;
+ if ((NULL != decryptHandle) && (NULL != buffer) && (0 < numBytes)) {
+ retCode = getDrmManagerService()->pread(uniqueId, decryptHandle, buffer, numBytes, offset);
+ }
+ return retCode;
+}
+
+status_t DrmManagerClientImpl::notify(const DrmInfoEvent& event) {
+ if (NULL != mOnInfoListener.get()) {
+ Mutex::Autolock _l(mLock);
+ sp listener = mOnInfoListener;
+ listener->onInfo(event);
+ }
+ return DRM_NO_ERROR;
+}
+
diff --git a/drm/libdrmframework/include/DrmIOService.h b/drm/libdrmframework/include/DrmIOService.h
new file mode 100644
index 0000000000000..244124e79124d
--- /dev/null
+++ b/drm/libdrmframework/include/DrmIOService.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __DRM_IO_SERVICE_H__
+#define __DRM_IO_SERVICE_H__
+
+#include "IDrmIOService.h"
+
+namespace android {
+
+/**
+ * This is the implementation class for DRM IO service.
+ *
+ * The instance of this class is created while starting the DRM IO service.
+ *
+ */
+class DrmIOService : public BnDrmIOService {
+public:
+ static void instantiate();
+
+private:
+ DrmIOService();
+ virtual ~DrmIOService();
+
+public:
+ void writeToFile(const String8& filePath, const String8& dataBuffer);
+ String8 readFromFile(const String8& filePath);
+};
+
+};
+
+#endif /* __DRM_IO_SERVICE_H__ */
+
diff --git a/drm/libdrmframework/include/DrmManager.h b/drm/libdrmframework/include/DrmManager.h
new file mode 100644
index 0000000000000..2ba9e995e790a
--- /dev/null
+++ b/drm/libdrmframework/include/DrmManager.h
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __DRM_MANAGER_H__
+#define __DRM_MANAGER_H__
+
+#include
+#include
+#include
+#include "IDrmEngine.h"
+#include "PlugInManager.h"
+#include "IDrmServiceListener.h"
+
+namespace android {
+
+class IDrmManager;
+class DrmRegistrationInfo;
+class DrmUnregistrationInfo;
+class DrmRightsAcquisitionInfo;
+class DrmContentIds;
+class DrmConstraints;
+class DrmRights;
+class DrmInfo;
+class DrmInfoStatus;
+class DrmConvertedStatus;
+class DrmInfoRequest;
+class DrmSupportInfo;
+class ActionDescription;
+
+/**
+ * This is implementation class for DRM Manager. This class delegates the
+ * functionality to corresponding DRM Engine.
+ *
+ * The DrmManagerService class creates an instance of this class.
+ *
+ */
+class DrmManager : public IDrmEngine::OnInfoListener {
+public:
+ DrmManager();
+ virtual ~DrmManager();
+
+public:
+
+ status_t loadPlugIns(int uniqueId);
+
+ status_t loadPlugIns(int uniqueId, const String8& plugInDirPath);
+
+ status_t setDrmServiceListener(
+ int uniqueId, const sp& drmServiceListener);
+
+ status_t unloadPlugIns(int uniqueId);
+
+ status_t installDrmEngine(int uniqueId, const String8& drmEngineFile);
+
+ DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action);
+
+ bool canHandle(int uniqueId, const String8& path, const String8& mimeType);
+
+ DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo);
+
+ DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest);
+
+ void saveRights(int uniqueId, const DrmRights& drmRights,
+ const String8& rightsPath, const String8& contentPath);
+
+ String8 getOriginalMimeType(int uniqueId, const String8& path);
+
+ int getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType);
+
+ int checkRightsStatus(int uniqueId, const String8& path, int action);
+
+ void consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve);
+
+ void setPlaybackStatus(
+ int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position);
+
+ bool validateAction(
+ int uniqueId, const String8& path, int action, const ActionDescription& description);
+
+ void removeRights(int uniqueId, const String8& path);
+
+ void removeAllRights(int uniqueId);
+
+ int openConvertSession(int uniqueId, const String8& mimeType);
+
+ DrmConvertedStatus* convertData(int uniqueId, int convertId, const DrmBuffer* inputData);
+
+ DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId);
+
+ status_t getAllSupportInfo(int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray);
+
+ DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length);
+
+ void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
+
+ void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* headerInfo);
+
+ status_t decrypt(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* encBuffer,DrmBuffer** decBuffer);
+
+ void finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId);
+
+ ssize_t pread(int uniqueId, DecryptHandle* decryptHandle,
+ void* buffer, ssize_t numBytes, off_t offset);
+
+ void onInfo(const DrmInfoEvent& event);
+
+private:
+ String8 getSupportedPlugInId(int uniqueId, const String8& path, const String8& mimeType);
+
+ String8 getSupportedPlugInId(const String8& mimeType);
+
+ String8 getSupportedPlugInIdFromPath(int uniqueId, const String8& path);
+
+ void populate(int uniqueId);
+
+ bool canHandle(int uniqueId, const String8& path);
+
+ void initializePlugIns(int uniqueId);
+
+private:
+ static const String8 EMPTY_STRING;
+
+ int mDecryptSessionId;
+ int mConvertId;
+ Mutex mLock;
+ Mutex mDecryptLock;
+ Mutex mConvertLock;
+ TPlugInManager mPlugInManager;
+ KeyedVector< DrmSupportInfo, String8 > mSupportInfoToPlugInIdMap;
+ KeyedVector< int, IDrmEngine*> mConvertSessionMap;
+ KeyedVector< int, sp > mServiceListeners;
+ KeyedVector< int, IDrmEngine*> mDecryptSessionMap;
+};
+
+};
+
+#endif /* __DRM_MANAGER_H__ */
+
diff --git a/drm/libdrmframework/include/DrmManagerClientImpl.h b/drm/libdrmframework/include/DrmManagerClientImpl.h
new file mode 100644
index 0000000000000..e70e6e118bd6d
--- /dev/null
+++ b/drm/libdrmframework/include/DrmManagerClientImpl.h
@@ -0,0 +1,400 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __DRM_MANAGER_CLIENT_IMPL_H__
+#define __DRM_MANAGER_CLIENT_IMPL_H__
+
+#include
+#include
+#include
+
+#include "IDrmManagerService.h"
+
+namespace android {
+
+class DrmInfoEvent;
+/**
+ * This is implementation class for DrmManagerClient class.
+ *
+ * Only the JNI layer creates an instance of this class to delegate
+ * functionality to Native later.
+ *
+ */
+class DrmManagerClientImpl : public BnDrmServiceListener {
+private:
+ DrmManagerClientImpl();
+
+public:
+ static DrmManagerClientImpl* create(int* pUniqueId);
+
+ static void remove(int uniqueId);
+
+ virtual ~DrmManagerClientImpl();
+
+public:
+ /**
+ * Initialize DRM Manager
+ * load available plug-ins from default plugInDirPath
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @return status_t
+ * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
+ */
+ status_t loadPlugIns(int uniqueId);
+
+ /**
+ * Finalize DRM Manager
+ * release resources associated with each plug-in
+ * unload all plug-ins and etc.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @return status_t
+ * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
+ */
+ status_t unloadPlugIns(int uniqueId);
+
+ /**
+ * Register a callback to be invoked when the caller required to
+ * receive necessary information
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] infoListener Listener
+ * @return status_t
+ * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
+ */
+ status_t setOnInfoListener(
+ int uniqueId, const sp& infoListener);
+
+ /**
+ * Get constraint information associated with input content
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path of the protected content
+ * @param[in] action Actions defined such as,
+ * Action::DEFAULT, Action::PLAY, etc
+ * @return DrmConstraints
+ * key-value pairs of constraint are embedded in it
+ * @note
+ * In case of error, return NULL
+ */
+ DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action);
+
+ /**
+ * Check whether the given mimetype or path can be handled
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path of the content needs to be handled
+ * @param[in] mimetype Mimetype of the content needs to be handled
+ * @return
+ * True if DrmManager can handle given path or mime type.
+ */
+ bool canHandle(int uniqueId, const String8& path, const String8& mimeType);
+
+ /**
+ * Executes given drm information based on its type
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] drmInfo Information needs to be processed
+ * @return DrmInfoStatus
+ * instance as a result of processing given input
+ */
+ DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo);
+
+ /**
+ * Retrieves necessary information for registration, unregistration or rights
+ * acquisition information.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] drmInfoRequest Request information to retrieve drmInfo
+ * @return DrmInfo
+ * instance as a result of processing given input
+ */
+ DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest);
+
+ /**
+ * Save DRM rights to specified rights path
+ * and make association with content path
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] drmRights DrmRights to be saved
+ * @param[in] rightsPath File path where rights to be saved
+ * @param[in] contentPath File path where content was saved
+ */
+ void saveRights(int uniqueId, const DrmRights& drmRights,
+ const String8& rightsPath, const String8& contentPath);
+
+ /**
+ * Retrieves the mime type embedded inside the original content
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path the path of the protected content
+ * @return String8
+ * Returns mime-type of the original content, such as "video/mpeg"
+ */
+ String8 getOriginalMimeType(int uniqueId, const String8& path);
+
+ /**
+ * Retrieves the type of the protected object (content, rights, etc..)
+ * using specified path or mimetype. At least one parameter should be non null
+ * to retrieve DRM object type
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path of the content or null.
+ * @param[in] mimeType Mime type of the content or null.
+ * @return type of the DRM content,
+ * such as DrmObjectType::CONTENT, DrmObjectType::RIGHTS_OBJECT
+ */
+ int getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType);
+
+ /**
+ * Check whether the given content has valid rights or not
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path of the protected content
+ * @param[in] action Action to perform (Action::DEFAULT, Action::PLAY, etc)
+ * @return the status of the rights for the protected content,
+ * such as RightsStatus::RIGHTS_VALID, RightsStatus::RIGHTS_EXPIRED, etc.
+ */
+ int checkRightsStatus(int uniqueId, const String8& path, int action);
+
+ /**
+ * Consumes the rights for a content.
+ * If the reserve parameter is true the rights is reserved until the same
+ * application calls this api again with the reserve parameter set to false.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the decryption session
+ * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc)
+ * @param[in] reserve True if the rights should be reserved.
+ */
+ void consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve);
+
+ /**
+ * Informs the DRM engine about the playback actions performed on the DRM files.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the decryption session
+ * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE)
+ * @param[in] position Position in the file (in milliseconds) where the start occurs.
+ * Only valid together with Playback::START.
+ */
+ void setPlaybackStatus(
+ int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position);
+
+ /**
+ * Validates whether an action on the DRM content is allowed or not.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path of the protected content
+ * @param[in] action Action to validate (Action::PLAY, Action::TRANSFER, etc)
+ * @param[in] description Detailed description of the action
+ * @return true if the action is allowed.
+ */
+ bool validateAction(
+ int uniqueId, const String8& path, int action, const ActionDescription& description);
+
+ /**
+ * Removes the rights associated with the given protected content
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path of the protected content
+ */
+ void removeRights(int uniqueId, const String8& path);
+
+ /**
+ * Removes all the rights information of each plug-in associated with
+ * DRM framework. Will be used in master reset
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ */
+ void removeAllRights(int uniqueId);
+
+ /**
+ * This API is for Forward Lock based DRM scheme.
+ * Each time the application tries to download a new DRM file
+ * which needs to be converted, then the application has to
+ * begin with calling this API.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] mimeType Description/MIME type of the input data packet
+ * @return Return handle for the convert session
+ */
+ int openConvertSession(int uniqueId, const String8& mimeType);
+
+ /**
+ * Accepts and converts the input data which is part of DRM file.
+ * The resultant converted data and the status is returned in the DrmConvertedInfo
+ * object. This method will be called each time there are new block
+ * of data received by the application.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] convertId Handle for the convert session
+ * @param[in] inputData Input Data which need to be converted
+ * @return Return object contains the status of the data conversion,
+ * the output converted data and offset. In this case the
+ * application will ignore the offset information.
+ */
+ DrmConvertedStatus* convertData(int uniqueId, int convertId, const DrmBuffer* inputData);
+
+ /**
+ * Informs the Drm Agent when there is no more data which need to be converted
+ * or when an error occurs. Upon successful conversion of the complete data,
+ * the agent will inform that where the header and body signature
+ * should be added. This signature appending is needed to integrity
+ * protect the converted file.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] convertId Handle for the convert session
+ * @return Return object contains the status of the data conversion,
+ * the header and body signature data. It also informs
+ * the application on which offset these signature data
+ * should be appended.
+ */
+ DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId);
+
+ /**
+ * Retrieves all DrmSupportInfo instance that native DRM framework can handle.
+ * This interface is meant to be used by JNI layer
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[out] length Number of elements in drmSupportInfoArray
+ * @param[out] drmSupportInfoArray Array contains all DrmSupportInfo
+ * that native DRM framework can handle
+ * @return status_t
+ * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
+ */
+ status_t getAllSupportInfo(int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray);
+
+ /**
+ * Open the decrypt session to decrypt the given protected content
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] fd File descriptor of the protected content to be decrypted
+ * @param[in] offset Start position of the content
+ * @param[in] length The length of the protected content
+ * @return
+ * Handle for the decryption session
+ */
+ DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length);
+
+ /**
+ * Close the decrypt session for the given handle
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the decryption session
+ */
+ void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
+
+ /**
+ * Initialize decryption for the given unit of the protected content
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the decryption session
+ * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
+ * @param[in] headerInfo Information for initializing decryption of this decrypUnit
+ */
+ void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* headerInfo);
+
+ /**
+ * Decrypt the protected content buffers for the given unit
+ * This method will be called any number of times, based on number of
+ * encrypted streams received from application.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the decryption session
+ * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
+ * @param[in] encBuffer Encrypted data block
+ * @param[out] decBuffer Decrypted data block
+ * @return status_t
+ * Returns the error code for this API
+ * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED
+ * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED,
+ * DRM_ERROR_DECRYPT for failure.
+ */
+ status_t decrypt(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer);
+
+ /**
+ * Finalize decryption for the given unit of the protected content
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the decryption session
+ * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
+ */
+ void finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId);
+
+ /**
+ * Reads the specified number of bytes from an open DRM file.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the decryption session
+ * @param[out] buffer Reference to the buffer that should receive the read data.
+ * @param[in] numBytes Number of bytes to read.
+ * @param[in] offset Offset with which to update the file position.
+ *
+ * @return Number of bytes read. Returns -1 for Failure.
+ */
+ ssize_t pread(int uniqueId, DecryptHandle* decryptHandle,
+ void* buffer, ssize_t numBytes, off_t offset);
+
+ /**
+ * Notify the event to the registered listener
+ *
+ * @param[in] event The event to be notified
+ * @return status_t
+ * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
+ */
+ status_t notify(const DrmInfoEvent& event);
+
+private:
+ /**
+ * Initialize DRM Manager
+ * load available plug-ins from plugInDirPath
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] plugInDirPath Directory from where to load plug-ins
+ * @return status_t
+ * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
+ */
+ status_t loadPlugIns(int uniqueId, const String8& plugInDirPath);
+
+ /**
+ * Install new DRM Engine Plug-in at the runtime
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] drmEngine Shared Object(so) File in which DRM Engine defined
+ * @return status_t
+ * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
+ */
+ status_t installDrmEngine(int uniqueId, const String8& drmEngineFile);
+
+private:
+ Mutex mLock;
+ sp mOnInfoListener;
+
+private:
+ static Mutex mMutex;
+ static Vector mUniqueIdVector;
+ static sp mDrmManagerService;
+ static const sp& getDrmManagerService();
+ static const String8 EMPTY_STRING;
+};
+
+};
+
+#endif /* __DRM_MANAGER_CLIENT_IMPL_H__ */
+
diff --git a/drm/libdrmframework/include/DrmManagerService.h b/drm/libdrmframework/include/DrmManagerService.h
new file mode 100644
index 0000000000000..fef121cd462eb
--- /dev/null
+++ b/drm/libdrmframework/include/DrmManagerService.h
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __DRM_MANAGER_SERVICE_H__
+#define __DRM_MANAGER_SERVICE_H__
+
+#include
+#include
+#include
+#include
+#include "IDrmManagerService.h"
+#include "IDrmServiceListener.h"
+
+namespace android {
+
+class DrmManager;
+class String8;
+class Mutex;
+
+/**
+ * This is the implementation class for DRM manager service. This delegates
+ * the responsibility to DrmManager.
+ *
+ * The instance of this class is created while starting the DRM manager service.
+ *
+ */
+class DrmManagerService : public BnDrmManagerService {
+public:
+ static void instantiate();
+
+private:
+ DrmManagerService();
+ virtual ~DrmManagerService();
+
+public:
+ status_t loadPlugIns(int uniqueId);
+
+ status_t loadPlugIns(int uniqueId, const String8& plugInDirPath);
+
+ status_t setDrmServiceListener(
+ int uniqueId, const sp& drmServiceListener);
+
+ status_t unloadPlugIns(int uniqueId);
+
+ status_t installDrmEngine(int uniqueId, const String8& drmEngineFile);
+
+ DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action);
+
+ bool canHandle(int uniqueId, const String8& path, const String8& mimeType);
+
+ DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo);
+
+ DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest);
+
+ void saveRights(int uniqueId, const DrmRights& drmRights,
+ const String8& rightsPath, const String8& contentPath);
+
+ String8 getOriginalMimeType(int uniqueId, const String8& path);
+
+ int getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType);
+
+ int checkRightsStatus(int uniqueId, const String8& path,int action);
+
+ void consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve);
+
+ void setPlaybackStatus(
+ int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position);
+
+ bool validateAction(int uniqueId, const String8& path,
+ int action, const ActionDescription& description);
+
+ void removeRights(int uniqueId, const String8& path);
+
+ void removeAllRights(int uniqueId);
+
+ int openConvertSession(int uniqueId, const String8& mimeType);
+
+ DrmConvertedStatus* convertData(int uniqueId, int convertId, const DrmBuffer* inputData);
+
+ DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId);
+
+ status_t getAllSupportInfo(int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray);
+
+ DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length);
+
+ void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
+
+ void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* headerInfo);
+
+ status_t decrypt(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer);
+
+ void finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId);
+
+ ssize_t pread(int uniqueId, DecryptHandle* decryptHandle,
+ void* buffer, ssize_t numBytes, off_t offset);
+
+private:
+ DrmManager* mDrmManager;
+};
+
+};
+
+#endif /* __DRM_MANAGER_SERVICE_H__ */
+
diff --git a/drm/libdrmframework/include/IDrmIOService.h b/drm/libdrmframework/include/IDrmIOService.h
new file mode 100644
index 0000000000000..5e0d907e67947
--- /dev/null
+++ b/drm/libdrmframework/include/IDrmIOService.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __IDRM_IO_SERVICE_H__
+#define __IDRM_IO_SERVICE_H__
+
+#include
+#include
+#include
+
+namespace android {
+
+/**
+ * This is the interface class for DRM IO service.
+ *
+ */
+class IDrmIOService : public IInterface
+{
+public:
+ enum {
+ WRITE_TO_FILE = IBinder::FIRST_CALL_TRANSACTION,
+ READ_FROM_FILE
+ };
+
+public:
+ DECLARE_META_INTERFACE(DrmIOService);
+
+public:
+ /**
+ * Writes the data into the file path provided
+ *
+ * @param[in] filePath Path of the file
+ * @param[in] dataBuffer Data to write
+ */
+ virtual void writeToFile(const String8& filePath, const String8& dataBuffer) = 0;
+
+ /**
+ * Reads the data from the file path provided
+ *
+ * @param[in] filePath Path of the file
+ * @return Data read from the file
+ */
+ virtual String8 readFromFile(const String8& filePath) = 0;
+};
+
+/**
+ * This is the Binder implementation class for DRM IO service.
+ */
+class BpDrmIOService: public BpInterface
+{
+public:
+ BpDrmIOService(const sp& impl)
+ : BpInterface(impl) {}
+
+ virtual void writeToFile(const String8& filePath, const String8& dataBuffer);
+
+ virtual String8 readFromFile(const String8& filePath);
+};
+
+/**
+ * This is the Binder implementation class for DRM IO service.
+ */
+class BnDrmIOService: public BnInterface
+{
+public:
+ virtual status_t onTransact(
+ uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0);
+};
+
+};
+
+#endif /* __IDRM_IO_SERVICE_H__ */
+
diff --git a/drm/libdrmframework/include/IDrmManagerService.h b/drm/libdrmframework/include/IDrmManagerService.h
new file mode 100644
index 0000000000000..a4d128af8f8ea
--- /dev/null
+++ b/drm/libdrmframework/include/IDrmManagerService.h
@@ -0,0 +1,242 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __IDRM_MANAGER_SERVICE_H__
+#define __IDRM_MANAGER_SERVICE_H__
+
+#include
+#include
+#include
+#include
+#include "IDrmServiceListener.h"
+
+namespace android {
+
+class DrmContentIds;
+class DrmConstraints;
+class DrmRights;
+class DrmInfo;
+class DrmInfoStatus;
+class DrmInfoRequest;
+class DrmSupportInfo;
+class DrmConvertedStatus;
+class String8;
+class ActionDescription;
+
+/**
+ * This is the interface class for DRM Manager service.
+ *
+ */
+class IDrmManagerService : public IInterface
+{
+public:
+ enum {
+ LOAD_PLUGINS = IBinder::FIRST_CALL_TRANSACTION,
+ LOAD_PLUGINS_FROM_PATH,
+ SET_DRM_SERVICE_LISTENER,
+ UNLOAD_PLUGINS,
+ INSTALL_DRM_ENGINE,
+ GET_CONSTRAINTS_FROM_CONTENT,
+ CAN_HANDLE,
+ PROCESS_DRM_INFO,
+ ACQUIRE_DRM_INFO,
+ SAVE_RIGHTS,
+ GET_ORIGINAL_MIMETYPE,
+ GET_DRM_OBJECT_TYPE,
+ CHECK_RIGHTS_STATUS,
+ CONSUME_RIGHTS,
+ SET_PLAYBACK_STATUS,
+ VALIDATE_ACTION,
+ REMOVE_RIGHTS,
+ REMOVE_ALL_RIGHTS,
+ OPEN_CONVERT_SESSION,
+ CONVERT_DATA,
+ CLOSE_CONVERT_SESSION,
+ GET_ALL_SUPPORT_INFO,
+ OPEN_DECRYPT_SESSION,
+ CLOSE_DECRYPT_SESSION,
+ INITIALIZE_DECRYPT_UNIT,
+ DECRYPT,
+ FINALIZE_DECRYPT_UNIT,
+ PREAD
+ };
+
+public:
+ DECLARE_META_INTERFACE(DrmManagerService);
+
+public:
+ virtual status_t loadPlugIns(int uniqueId) = 0;
+
+ virtual status_t loadPlugIns(int uniqueId, const String8& plugInDirPath) = 0;
+
+ virtual status_t setDrmServiceListener(
+ int uniqueId, const sp& infoListener) = 0;
+
+ virtual status_t unloadPlugIns(int uniqueId) = 0;
+
+ virtual status_t installDrmEngine(int uniqueId, const String8& drmEngineFile) = 0;
+
+ virtual DrmConstraints* getConstraints(
+ int uniqueId, const String8* path, const int action) = 0;
+
+ virtual bool canHandle(int uniqueId, const String8& path, const String8& mimeType) = 0;
+
+ virtual DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo) = 0;
+
+ virtual DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest) = 0;
+
+ virtual void saveRights(int uniqueId, const DrmRights& drmRights,
+ const String8& rightsPath, const String8& contentPath) = 0;
+
+ virtual String8 getOriginalMimeType(int uniqueId, const String8& path) = 0;
+
+ virtual int getDrmObjectType(
+ int uniqueId, const String8& path, const String8& mimeType) = 0;
+
+ virtual int checkRightsStatus(int uniqueId, const String8& path, int action) = 0;
+
+ virtual void consumeRights(
+ int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) = 0;
+
+ virtual void setPlaybackStatus(
+ int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) = 0;
+
+ virtual bool validateAction(
+ int uniqueId, const String8& path,
+ int action, const ActionDescription& description) = 0;
+
+ virtual void removeRights(int uniqueId, const String8& path) = 0;
+
+ virtual void removeAllRights(int uniqueId) = 0;
+
+ virtual int openConvertSession(int uniqueId, const String8& mimeType) = 0;
+
+ virtual DrmConvertedStatus* convertData(
+ int uniqueId, int convertId, const DrmBuffer* inputData) = 0;
+
+ virtual DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId) = 0;
+
+ virtual status_t getAllSupportInfo(
+ int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) = 0;
+
+ virtual DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length) = 0;
+
+ virtual void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0;
+
+ virtual void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* headerInfo) = 0;
+
+ virtual status_t decrypt(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) = 0;
+
+ virtual void finalizeDecryptUnit(
+ int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) = 0;
+
+ virtual ssize_t pread(int uniqueId, DecryptHandle* decryptHandle,
+ void* buffer, ssize_t numBytes,off_t offset) = 0;
+};
+
+/**
+ * This is the Binder implementation class for DRM Manager service.
+ */
+class BpDrmManagerService: public BpInterface
+{
+public:
+ BpDrmManagerService(const sp& impl)
+ : BpInterface(impl) {}
+
+ virtual status_t loadPlugIns(int uniqueId);
+
+ virtual status_t loadPlugIns(int uniqueId, const String8& plugInDirPath);
+
+ virtual status_t setDrmServiceListener(
+ int uniqueId, const sp& infoListener);
+
+ virtual status_t unloadPlugIns(int uniqueId);
+
+ virtual status_t installDrmEngine(int uniqueId, const String8& drmEngineFile);
+
+ virtual DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action);
+
+ virtual bool canHandle(int uniqueId, const String8& path, const String8& mimeType);
+
+ virtual DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo);
+
+ virtual DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest);
+
+ virtual void saveRights(int uniqueId, const DrmRights& drmRights,
+ const String8& rightsPath, const String8& contentPath);
+
+ virtual String8 getOriginalMimeType(int uniqueId, const String8& path);
+
+ virtual int getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType);
+
+ virtual int checkRightsStatus(int uniqueId, const String8& path, int action);
+
+ virtual void consumeRights(
+ int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve);
+
+ virtual void setPlaybackStatus(
+ int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position);
+
+ virtual bool validateAction(
+ int uniqueId, const String8& path, int action, const ActionDescription& description);
+
+ virtual void removeRights(int uniqueId, const String8& path);
+
+ virtual void removeAllRights(int uniqueId);
+
+ virtual int openConvertSession(int uniqueId, const String8& mimeType);
+
+ virtual DrmConvertedStatus* convertData(
+ int uniqueId, int convertId, const DrmBuffer* inputData);
+
+ virtual DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId);
+
+ virtual status_t getAllSupportInfo(
+ int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray);
+
+ virtual DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length);
+
+ virtual void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
+
+ virtual void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* headerInfo);
+
+ virtual status_t decrypt(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer);
+
+ virtual void finalizeDecryptUnit(
+ int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId);
+
+ virtual ssize_t pread(int uniqueId, DecryptHandle* decryptHandle,
+ void* buffer, ssize_t numBytes, off_t offset);
+};
+
+/**
+ * This is the Binder implementation class for DRM Manager service.
+ */
+class BnDrmManagerService: public BnInterface
+{
+public:
+ virtual status_t onTransact(
+ uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0);
+};
+
+};
+
+#endif /* __IDRM_MANAGER_SERVICE_H__ */
+
diff --git a/drm/libdrmframework/include/IDrmServiceListener.h b/drm/libdrmframework/include/IDrmServiceListener.h
new file mode 100644
index 0000000000000..7f7109f29b88a
--- /dev/null
+++ b/drm/libdrmframework/include/IDrmServiceListener.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __IDRM_SERVICE_LISTENER_H__
+#define __IDRM_SERVICE_LISTENER_H__
+
+#include
+#include
+#include
+
+namespace android {
+
+class DrmInfoEvent;
+
+/**
+ * This is the interface class for DRM service listener.
+ *
+ */
+class IDrmServiceListener : public IInterface
+{
+public:
+ enum {
+ NOTIFY = IBinder::FIRST_CALL_TRANSACTION,
+ };
+
+public:
+ DECLARE_META_INTERFACE(DrmServiceListener);
+
+public:
+ virtual status_t notify(const DrmInfoEvent& event) = 0;
+};
+
+/**
+ * This is the Binder implementation class for DRM service listener.
+ */
+class BpDrmServiceListener: public BpInterface
+{
+public:
+ BpDrmServiceListener(const sp& impl)
+ : BpInterface(impl) {}
+
+ virtual status_t notify(const DrmInfoEvent& event);
+};
+
+/**
+ * This is the Binder implementation class for DRM service listener.
+ */
+class BnDrmServiceListener: public BnInterface
+{
+public:
+ virtual status_t onTransact(
+ uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0);
+};
+
+};
+
+#endif /* __IDRM_SERVICE_LISTENER_H__ */
+
diff --git a/drm/libdrmframework/include/PlugInManager.h b/drm/libdrmframework/include/PlugInManager.h
new file mode 100644
index 0000000000000..9ad195fd80b07
--- /dev/null
+++ b/drm/libdrmframework/include/PlugInManager.h
@@ -0,0 +1,273 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PLUGIN_MANAGER_H__
+#define __PLUGIN_MANAGER_H__
+
+#include
+#include
+#include
+
+#include
+#include
+#include
+
+namespace android {
+
+const char* const PLUGIN_MANAGER_CREATE = "create";
+const char* const PLUGIN_MANAGER_DESTROY = "destroy";
+const char* const PLUGIN_EXTENSION = ".so";
+
+/**
+ * This is the template class for Plugin manager.
+ *
+ * The DrmManager uses this class to handle the plugins.
+ *
+ */
+template
+class TPlugInManager {
+private:
+ typedef void* HANDLE;
+ typedef Type* create_t(void);
+ typedef void destroy_t(Type*);
+ typedef create_t* FPCREATE;
+ typedef destroy_t* FPDESTORY;
+
+ typedef struct _PlugInContainer {
+ String8 sPath;
+ HANDLE hHandle;
+ FPCREATE fpCreate;
+ FPDESTORY fpDestory;
+ Type* pInstance;
+
+ _PlugInContainer():
+ sPath("")
+ ,hHandle(NULL)
+ ,fpCreate(NULL)
+ ,fpDestory(NULL)
+ ,pInstance(NULL)
+ {}
+ } PlugInContainer;
+
+ typedef KeyedVector PlugInMap;
+ PlugInMap m_plugInMap;
+
+ typedef Vector PlugInIdList;
+ PlugInIdList m_plugInIdList;
+
+public:
+ /**
+ * Load all the plug-ins in the specified directory
+ *
+ * @param[in] rsPlugInDirPath
+ * Directory path which plug-ins (dynamic library) are stored
+ * @note Plug-ins should be implemented according to the specification
+ */
+ void loadPlugIns(const String8& rsPlugInDirPath) {
+ Vector plugInFileList = getPlugInPathList(rsPlugInDirPath);
+
+ if (!plugInFileList.isEmpty()) {
+ for (unsigned int i = 0; i < plugInFileList.size(); ++i) {
+ loadPlugIn(plugInFileList[i]);
+ }
+ }
+ }
+
+ /**
+ * Unload all the plug-ins
+ *
+ */
+ void unloadPlugIns() {
+ for (unsigned int i = 0; i < m_plugInIdList.size(); ++i) {
+ unloadPlugIn(m_plugInIdList[i]);
+ }
+ m_plugInIdList.clear();
+ }
+
+ /**
+ * Get all the IDs of available plug-ins
+ *
+ * @return[in] plugInIdList
+ * String type Vector in which all plug-in IDs are stored
+ */
+ Vector getPlugInIdList() const {
+ return m_plugInIdList;
+ }
+
+ /**
+ * Get a plug-in reference of specified ID
+ *
+ * @param[in] rsPlugInId
+ * Plug-in ID to be used
+ * @return plugIn
+ * Reference of specified plug-in instance
+ */
+ Type& getPlugIn(const String8& rsPlugInId) {
+ if (!contains(rsPlugInId)) {
+ // This error case never happens
+ }
+ return *(m_plugInMap.valueFor(rsPlugInId)->pInstance);
+ }
+
+public:
+ /**
+ * Load a plug-in stored in the specified path
+ *
+ * @param[in] rsPlugInPath
+ * Plug-in (dynamic library) file path
+ * @note Plug-in should be implemented according to the specification
+ */
+ void loadPlugIn(const String8& rsPlugInPath) {
+ if (contains(rsPlugInPath)) {
+ return;
+ }
+
+ PlugInContainer* pPlugInContainer = new PlugInContainer();
+
+ pPlugInContainer->hHandle = dlopen(rsPlugInPath.string(), RTLD_LAZY);
+
+ if (NULL == pPlugInContainer->hHandle) {
+ delete pPlugInContainer;
+ pPlugInContainer = NULL;
+ return;
+ }
+
+ pPlugInContainer->sPath = rsPlugInPath;
+ pPlugInContainer->fpCreate
+ = (FPCREATE)dlsym(pPlugInContainer->hHandle, PLUGIN_MANAGER_CREATE);
+ pPlugInContainer->fpDestory
+ = (FPDESTORY)dlsym(pPlugInContainer->hHandle, PLUGIN_MANAGER_DESTROY);
+
+ if (NULL != pPlugInContainer->fpCreate && NULL != pPlugInContainer->fpDestory) {
+ pPlugInContainer->pInstance = (Type*)pPlugInContainer->fpCreate();
+ m_plugInIdList.add(rsPlugInPath);
+ m_plugInMap.add(rsPlugInPath, pPlugInContainer);
+ } else {
+ dlclose(pPlugInContainer->hHandle);
+ delete pPlugInContainer;
+ pPlugInContainer = NULL;
+ return;
+ }
+ }
+
+ /**
+ * Unload a plug-in stored in the specified path
+ *
+ * @param[in] rsPlugInPath
+ * Plug-in (dynamic library) file path
+ */
+ void unloadPlugIn(const String8& rsPlugInPath) {
+ if (!contains(rsPlugInPath)) {
+ return;
+ }
+
+ PlugInContainer* pPlugInContainer = m_plugInMap.valueFor(rsPlugInPath);
+ pPlugInContainer->fpDestory(pPlugInContainer->pInstance);
+ dlclose(pPlugInContainer->hHandle);
+
+ m_plugInMap.removeItem(rsPlugInPath);
+ delete pPlugInContainer;
+ pPlugInContainer = NULL;
+ }
+
+private:
+ /**
+ * True if TPlugInManager contains rsPlugInId
+ */
+ bool contains(const String8& rsPlugInId) {
+ return m_plugInMap.indexOfKey(rsPlugInId) != NAME_NOT_FOUND;
+ }
+
+ /**
+ * Return file path list of plug-ins stored in the specified directory
+ *
+ * @param[in] rsDirPath
+ * Directory path in which plug-ins are stored
+ * @return plugInFileList
+ * String type Vector in which file path of plug-ins are stored
+ */
+ Vector getPlugInPathList(const String8& rsDirPath) {
+ Vector fileList;
+ DIR* pDir = opendir(rsDirPath.string());
+ struct dirent* pEntry = new dirent();
+
+ while (NULL != pDir && NULL != (pEntry = readdir(pDir))) {
+ if (!isPlugIn(pEntry)) {
+ continue;
+ }
+ String8 plugInPath;
+ plugInPath += rsDirPath;
+ plugInPath += "/";
+ plugInPath += pEntry->d_name;
+
+ fileList.add(plugInPath);
+ }
+
+ if (NULL != pDir) {
+ closedir(pDir);
+ }
+ delete pEntry;
+ pEntry = NULL;
+
+ return fileList;
+ }
+
+ /**
+ * True if the input name denotes plug-in
+ */
+ bool isPlugIn(const struct dirent* pEntry) const {
+ String8 sName(pEntry->d_name);
+ int extentionPos = sName.size() - String8(PLUGIN_EXTENSION).size();
+ if (extentionPos < 0) {
+ return false;
+ }
+ return extentionPos == (int)sName.find(PLUGIN_EXTENSION);
+ }
+
+ /**
+ * True if the input entry is "." or ".."
+ */
+ bool isDotOrDDot(const struct dirent* pEntry) const {
+ String8 sName(pEntry->d_name);
+ return "." == sName || ".." == sName;
+ }
+
+ /**
+ * True if input entry is directory
+ */
+ bool isDirectory(const struct dirent* pEntry) const {
+ return DT_DIR == pEntry->d_type;
+ }
+
+ /**
+ * True if input entry is regular file
+ */
+ bool isRegularFile(const struct dirent* pEntry) const {
+ return DT_REG == pEntry->d_type;
+ }
+
+ /**
+ * True if input entry is link
+ */
+ bool isLink(const struct dirent* pEntry) const {
+ return DT_LNK == pEntry->d_type;
+ }
+};
+
+};
+
+#endif /* __PLUGIN_MANAGER_H__ */
+
diff --git a/drm/libdrmframework/include/ReadWriteUtils.h b/drm/libdrmframework/include/ReadWriteUtils.h
new file mode 100644
index 0000000000000..022149ee20f3c
--- /dev/null
+++ b/drm/libdrmframework/include/ReadWriteUtils.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __READ_WRITE_UTILS_H__
+#define __READ_WRITE_UTILS_H__
+
+#include
+#include
+
+namespace android {
+
+/**
+ * This is an utility class which performs IO operations.
+ *
+ */
+class ReadWriteUtils {
+public:
+ /**
+ * Constructor for ReadWriteUtils
+ */
+ ReadWriteUtils() {}
+
+ /**
+ * Destructor for ReadWriteUtils
+ */
+ virtual ~ReadWriteUtils();
+
+public:
+ /**
+ * Reads the data from the file path provided
+ *
+ * @param[in] filePath Path of the file
+ * @return Data read from the file
+ */
+ static String8 readBytes(const String8& filePath);
+ /**
+ * Writes the data into the file path provided
+ *
+ * @param[in] filePath Path of the file
+ * @param[in] dataBuffer Data to write
+ */
+ static void writeToFile(const String8& filePath, const String8& data);
+ /**
+ * Appends the data into the file path provided
+ *
+ * @param[in] filePath Path of the file
+ * @param[in] dataBuffer Data to append
+ */
+ static void appendToFile(const String8& filePath, const String8& data);
+
+private:
+ FileMap* mFileMap;
+};
+
+};
+
+#endif /* __READ_WRITE_UTILS_H__ */
+
diff --git a/drm/libdrmframework/include/StringTokenizer.h b/drm/libdrmframework/include/StringTokenizer.h
new file mode 100644
index 0000000000000..70e7558224035
--- /dev/null
+++ b/drm/libdrmframework/include/StringTokenizer.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __STRING_TOKENIZER_H__
+#define __STRING_TOKENIZER_H__
+
+#include
+
+namespace android {
+
+/**
+ * This is an utility class for String manipulation.
+ *
+ */
+class StringTokenizer {
+public:
+ /**
+ * Iterator for string tokens
+ */
+ class Iterator {
+ friend class StringTokenizer;
+ private:
+ Iterator(StringTokenizer* StringTokenizer)
+ : mStringTokenizer(StringTokenizer), mIndex(0) {}
+
+ public:
+ Iterator(const Iterator& iterator);
+ Iterator& operator=(const Iterator& iterator);
+ virtual ~Iterator() {}
+
+ public:
+ bool hasNext();
+ String8& next();
+
+ private:
+ StringTokenizer* mStringTokenizer;
+ unsigned int mIndex;
+ };
+
+public:
+ /**
+ * Constructor for StringTokenizer
+ *
+ * @param[in] string Complete string data
+ * @param[in] delimeter Delimeter used to split the string
+ */
+ StringTokenizer(const String8& string, const String8& delimeter);
+
+ /**
+ * Destructor for StringTokenizer
+ */
+ ~StringTokenizer() {}
+
+private:
+ /**
+ * Splits the string according to the delimeter
+ */
+ void splitString(const String8& string, const String8& delimeter);
+
+public:
+ /**
+ * Returns Iterator object to walk through the split string values
+ *
+ * @return Iterator object
+ */
+ Iterator iterator();
+
+private:
+ Vector mStringTokenizerVector;
+};
+
+};
+#endif /* __STRING_TOKENIZER_H__ */
+
diff --git a/drm/libdrmframework/plugins/Android.mk b/drm/libdrmframework/plugins/Android.mk
new file mode 100644
index 0000000000000..9ee79618c2037
--- /dev/null
+++ b/drm/libdrmframework/plugins/Android.mk
@@ -0,0 +1,16 @@
+#
+# Copyright (C) 2010 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+include $(call all-subdir-makefiles)
diff --git a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h
new file mode 100644
index 0000000000000..667958ae8b721
--- /dev/null
+++ b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h
@@ -0,0 +1,411 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __DRM_ENGINE_BASE_H__
+#define __DRM_ENGINE_BASE_H__
+
+#include
+#include "IDrmEngine.h"
+
+namespace android {
+
+/**
+ * This class is an interface for plug-in developers
+ *
+ * Responsibility of this class is control the sequence of actual plug-in.
+ * All each plug-in developer has to do is implement onXXX() type virtual interfaces.
+ */
+class DrmEngineBase : public IDrmEngine {
+public:
+ DrmEngineBase();
+ virtual ~DrmEngineBase();
+
+public:
+ DrmConstraints* getConstraints(int uniqueId, const String8* path, int action);
+
+ status_t initialize(int uniqueId);
+
+ status_t setOnInfoListener(int uniqueId, const IDrmEngine::OnInfoListener* infoListener);
+
+ status_t terminate(int uniqueId);
+
+ bool canHandle(int uniqueId, const String8& path);
+
+ DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo);
+
+ void saveRights(int uniqueId, const DrmRights& drmRights,
+ const String8& rightsPath, const String8& contentPath);
+
+ DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest);
+
+ String8 getOriginalMimeType(int uniqueId, const String8& path);
+
+ int getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType);
+
+ int checkRightsStatus(int uniqueId, const String8& path, int action);
+
+ void consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve);
+
+ void setPlaybackStatus(
+ int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position);
+
+ bool validateAction(
+ int uniqueId, const String8& path, int action, const ActionDescription& description);
+
+ void removeRights(int uniqueId, const String8& path);
+
+ void removeAllRights(int uniqueId);
+
+ void openConvertSession(int uniqueId, int convertId);
+
+ DrmConvertedStatus* convertData(int uniqueId, int convertId, const DrmBuffer* inputData);
+
+ DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId);
+
+ DrmSupportInfo* getSupportInfo(int uniqueId);
+
+ status_t openDecryptSession(
+ int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length);
+
+ void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
+
+ void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* headerInfo);
+
+ status_t decrypt(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer);
+
+ void finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId);
+
+ ssize_t pread(int uniqueId, DecryptHandle* decryptHandle,
+ void* buffer, ssize_t numBytes, off_t offset);
+
+protected:
+ /////////////////////////////////////////////////////
+ // Interface for plug-in developers //
+ // each plug-in has to implement following method //
+ /////////////////////////////////////////////////////
+ /**
+ * Get constraint information associated with input content
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path of the protected content
+ * @param[in] action Actions defined such as,
+ * Action::DEFAULT, Action::PLAY, etc
+ * @return DrmConstraints
+ * key-value pairs of constraint are embedded in it
+ * @note
+ * In case of error, return NULL
+ */
+ virtual DrmConstraints* onGetConstraints(
+ int uniqueId, const String8* path, int action) = 0;
+
+ /**
+ * Initialize plug-in
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @return status_t
+ * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
+ */
+ virtual status_t onInitialize(int uniqueId) = 0;
+
+ /**
+ * Register a callback to be invoked when the caller required to
+ * receive necessary information
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] infoListener Listener
+ * @return status_t
+ * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
+ */
+ virtual status_t onSetOnInfoListener(
+ int uniqueId, const IDrmEngine::OnInfoListener* infoListener) = 0;
+
+ /**
+ * Terminate the plug-in
+ * and release resource bound to plug-in
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @return status_t
+ * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
+ */
+ virtual status_t onTerminate(int uniqueId) = 0;
+
+ /**
+ * Get whether the given content can be handled by this plugin or not
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path the protected object
+ * @return bool
+ * Returns true if this plugin can handle , false in case of not able to handle
+ */
+ virtual bool onCanHandle(int uniqueId, const String8& path) = 0;
+
+ /**
+ * Executes given drm information based on its type
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] drmInfo Information needs to be processed
+ * @return DrmInfoStatus
+ * instance as a result of processing given input
+ */
+ virtual DrmInfoStatus* onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo) = 0;
+
+ /**
+ * Save DRM rights to specified rights path
+ * and make association with content path
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] drmRights DrmRights to be saved
+ * @param[in] rightsPath File path where rights to be saved
+ * @param[in] contentPath File path where content was saved
+ */
+ virtual void onSaveRights(int uniqueId, const DrmRights& drmRights,
+ const String8& rightspath, const String8& contentPath) = 0;
+
+ /**
+ * Retrieves necessary information for registration, unregistration or rights
+ * acquisition information.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] drmInfoRequest Request information to retrieve drmInfo
+ * @return DrmInfo
+ * instance as a result of processing given input
+ */
+ virtual DrmInfo* onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest) = 0;
+
+ /**
+ * Retrieves the mime type embedded inside the original content
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path of the protected content
+ * @return String8
+ * Returns mime-type of the original content, such as "video/mpeg"
+ */
+ virtual String8 onGetOriginalMimeType(int uniqueId, const String8& path) = 0;
+
+ /**
+ * Retrieves the type of the protected object (content, rights, etc..)
+ * using specified path or mimetype. At least one parameter should be non null
+ * to retrieve DRM object type
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path of the content or null.
+ * @param[in] mimeType Mime type of the content or null.
+ * @return type of the DRM content,
+ * such as DrmObjectType::CONTENT, DrmObjectType::RIGHTS_OBJECT
+ */
+ virtual int onGetDrmObjectType(
+ int uniqueId, const String8& path, const String8& mimeType) = 0;
+
+ /**
+ * Check whether the given content has valid rights or not
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path of the protected content
+ * @param[in] action Action to perform (Action::DEFAULT, Action::PLAY, etc)
+ * @return the status of the rights for the protected content,
+ * such as RightsStatus::RIGHTS_VALID, RightsStatus::RIGHTS_EXPIRED, etc.
+ */
+ virtual int onCheckRightsStatus(int uniqueId, const String8& path, int action) = 0;
+
+ /**
+ * Consumes the rights for a content.
+ * If the reserve parameter is true the rights is reserved until the same
+ * application calls this api again with the reserve parameter set to false.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the decryption session
+ * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc)
+ * @param[in] reserve True if the rights should be reserved.
+ */
+ virtual void onConsumeRights(int uniqueId, DecryptHandle* decryptHandle,
+ int action, bool reserve) = 0;
+
+ /**
+ * Informs the DRM Engine about the playback actions performed on the DRM files.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the decryption session
+ * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE)
+ * @param[in] position Position in the file (in milliseconds) where the start occurs.
+ * Only valid together with Playback::START.
+ */
+ virtual void onSetPlaybackStatus(
+ int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) = 0;
+
+ /**
+ * Validates whether an action on the DRM content is allowed or not.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path of the protected content
+ * @param[in] action Action to validate (Action::PLAY, Action::TRANSFER, etc)
+ * @param[in] description Detailed description of the action
+ * @return true if the action is allowed.
+ */
+ virtual bool onValidateAction(int uniqueId, const String8& path,
+ int action, const ActionDescription& description) = 0;
+
+ /**
+ * Removes the rights associated with the given protected content
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path of the protected content
+ */
+ virtual void onRemoveRights(int uniqueId, const String8& path) = 0;
+
+ /**
+ * Removes all the rights information of each plug-in associated with
+ * DRM framework. Will be used in master reset
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ */
+ virtual void onRemoveAllRights(int uniqueId) = 0;
+
+ /**
+ * This API is for Forward Lock based DRM scheme.
+ * Each time the application tries to download a new DRM file
+ * which needs to be converted, then the application has to
+ * begin with calling this API.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] convertId Handle for the convert session
+ */
+ virtual void onOpenConvertSession(int uniqueId, int convertId) = 0;
+
+ /**
+ * Accepts and converts the input data which is part of DRM file.
+ * The resultant converted data and the status is returned in the DrmConvertedInfo
+ * object. This method will be called each time there are new block
+ * of data received by the application.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] convertId Handle for the convert session
+ * @param[in] inputData Input Data which need to be converted
+ * @return Return object contains the status of the data conversion,
+ * the output converted data and offset. In this case the
+ * application will ignore the offset information.
+ */
+ virtual DrmConvertedStatus* onConvertData(
+ int uniqueId, int convertId, const DrmBuffer* inputData) = 0;
+
+ /**
+ * Informs the Drm Agent when there is no more data which need to be converted
+ * or when an error occurs. Upon successful conversion of the complete data,
+ * the agent will inform that where the header and body signature
+ * should be added. This signature appending is needed to integrity
+ * protect the converted file.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] convertId Handle for the convert session
+ * @return Return object contains the status of the data conversion,
+ * the header and body signature data. It also informs
+ * the application on which offset these signature data
+ * should be appended.
+ */
+ virtual DrmConvertedStatus* onCloseConvertSession(int uniqueId, int convertId) = 0;
+
+ /**
+ * Returns the information about the Drm Engine capabilities which includes
+ * supported MimeTypes and file suffixes.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @return DrmSupportInfo
+ * instance which holds the capabilities of a plug-in
+ */
+ virtual DrmSupportInfo* onGetSupportInfo(int uniqueId) = 0;
+
+ /**
+ * Open the decrypt session to decrypt the given protected content
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the current decryption session
+ * @param[in] fd File descriptor of the protected content to be decrypted
+ * @param[in] offset Start position of the content
+ * @param[in] length The length of the protected content
+ * @return
+ * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success
+ */
+ virtual status_t onOpenDecryptSession(
+ int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length) = 0;
+
+ /**
+ * Close the decrypt session for the given handle
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the decryption session
+ */
+ virtual void onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0;
+
+ /**
+ * Initialize decryption for the given unit of the protected content
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptId Handle for the decryption session
+ * @param[in] decryptUnitId ID Specifies decryption unit, such as track ID
+ * @param[in] headerInfo Information for initializing decryption of this decrypUnit
+ */
+ virtual void onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* headerInfo) = 0;
+
+ /**
+ * Decrypt the protected content buffers for the given unit
+ * This method will be called any number of times, based on number of
+ * encrypted streams received from application.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptId Handle for the decryption session
+ * @param[in] decryptUnitId ID Specifies decryption unit, such as track ID
+ * @param[in] encBuffer Encrypted data block
+ * @param[out] decBuffer Decrypted data block
+ * @return status_t
+ * Returns the error code for this API
+ * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED
+ * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED,
+ * DRM_ERROR_DECRYPT for failure.
+ */
+ virtual status_t onDecrypt(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) = 0;
+
+ /**
+ * Finalize decryption for the given unit of the protected content
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the decryption session
+ * @param[in] decryptUnitId ID Specifies decryption unit, such as track ID
+ */
+ virtual void onFinalizeDecryptUnit(
+ int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) = 0;
+
+ /**
+ * Reads the specified number of bytes from an open DRM file.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the decryption session
+ * @param[out] buffer Reference to the buffer that should receive the read data.
+ * @param[in] numBytes Number of bytes to read.
+ * @param[in] offset Offset with which to update the file position.
+ *
+ * @return Number of bytes read. Returns -1 for Failure.
+ */
+ virtual ssize_t onPread(int uniqueId, DecryptHandle* decryptHandle,
+ void* buffer, ssize_t numBytes, off_t offset) = 0;
+};
+
+};
+
+#endif /* __DRM_ENGINE_BASE_H__ */
+
diff --git a/drm/libdrmframework/plugins/common/include/IDrmEngine.h b/drm/libdrmframework/plugins/common/include/IDrmEngine.h
new file mode 100644
index 0000000000000..0d52f6650a6ea
--- /dev/null
+++ b/drm/libdrmframework/plugins/common/include/IDrmEngine.h
@@ -0,0 +1,371 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __IDRM_ENGINE_H__
+#define __IDRM_ENGINE_H__
+
+#include
+
+namespace android {
+
+class DrmContentIds;
+class DrmConstraints;
+class DrmRights;
+class DrmInfo;
+class DrmInfoStatus;
+class DrmConvertedStatus;
+class DrmInfoRequest;
+class DrmSupportInfo;
+class DrmInfoEvent;
+
+/**
+ * This class is an interface for plug-in user
+ *
+ * Responsibility of this class is provide generic interface to DRM Engine Manager.
+ * Each interface need to be as abstract as possible.
+ */
+class IDrmEngine {
+public:
+ virtual ~IDrmEngine() {
+ }
+
+public:
+ class OnInfoListener {
+
+ public:
+ virtual void onInfo(const DrmInfoEvent& event) = 0;
+
+ virtual ~OnInfoListener() { }
+ };
+
+public:
+
+ //////////////////////////////////
+ // Implementation of IDrmEngine //
+ //////////////////////////////////
+
+ /**
+ * Initialize plug-in
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @return status_t
+ * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
+ */
+ virtual status_t initialize(int uniqueId) = 0;
+
+ /**
+ * Register a callback to be invoked when the caller required to
+ * receive necessary information
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] infoListener Listener
+ * @return status_t
+ * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
+ */
+ virtual status_t setOnInfoListener(
+ int uniqueId, const IDrmEngine::OnInfoListener* infoListener) = 0;
+
+ /**
+ * Terminate the plug-in
+ * and release resource bound to plug-in
+ * e.g.) release native resource
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @return status_t
+ * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
+ */
+ virtual status_t terminate(int uniqueId) = 0;
+
+ /**
+ * Get constraint information associated with input content
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path of the protected content
+ * @param[in] action Actions defined such as,
+ * Action::DEFAULT, Action::PLAY, etc
+ * @return DrmConstraints
+ * key-value pairs of constraint are embedded in it
+ * @note
+ * In case of error, return NULL
+ */
+ virtual DrmConstraints* getConstraints(
+ int uniqueId, const String8* path, int action) = 0;
+
+ /**
+ * Get whether the given content can be handled by this plugin or not
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path the protected object
+ * @return bool
+ * true if this plugin can handle , false in case of not able to handle
+ */
+ virtual bool canHandle(int uniqueId, const String8& path) = 0;
+
+ /**
+ * Executes given drm information based on its type
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] drmInfo Information needs to be processed
+ * @return DrmInfoStatus
+ * instance as a result of processing given input
+ */
+ virtual DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo) = 0;
+
+ /**
+ * Retrieves necessary information for registration, unregistration or rights
+ * acquisition information.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] drmInfoRequest Request information to retrieve drmInfo
+ * @return DrmInfo
+ * instance as a result of processing given input
+ */
+ virtual DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) = 0;
+
+ /**
+ * Save DRM rights to specified rights path
+ * and make association with content path
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] drmRights DrmRights to be saved
+ * @param[in] rightsPath File path where rights to be saved
+ * @param[in] contentPath File path where content was saved
+ */
+ virtual void saveRights(int uniqueId, const DrmRights& drmRights,
+ const String8& rightsPath, const String8& contentPath) = 0;
+
+ /**
+ * Retrieves the mime type embedded inside the original content
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path of the protected content
+ * @return String8
+ * Returns mime-type of the original content, such as "video/mpeg"
+ */
+ virtual String8 getOriginalMimeType(int uniqueId, const String8& path) = 0;
+
+ /**
+ * Retrieves the type of the protected object (content, rights, etc..)
+ * using specified path or mimetype. At least one parameter should be non null
+ * to retrieve DRM object type
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path of the content or null.
+ * @param[in] mimeType Mime type of the content or null.
+ * @return type of the DRM content,
+ * such as DrmObjectType::CONTENT, DrmObjectType::RIGHTS_OBJECT
+ */
+ virtual int getDrmObjectType(
+ int uniqueId, const String8& path, const String8& mimeType) = 0;
+
+ /**
+ * Check whether the given content has valid rights or not
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path of the protected content
+ * @param[in] action Action to perform (Action::DEFAULT, Action::PLAY, etc)
+ * @return the status of the rights for the protected content,
+ * such as RightsStatus::RIGHTS_VALID, RightsStatus::RIGHTS_EXPIRED, etc.
+ */
+ virtual int checkRightsStatus(int uniqueId, const String8& path, int action) = 0;
+
+ /**
+ * Consumes the rights for a content.
+ * If the reserve parameter is true the rights is reserved until the same
+ * application calls this api again with the reserve parameter set to false.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the decryption session
+ * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc)
+ * @param[in] reserve True if the rights should be reserved.
+ */
+ virtual void consumeRights(
+ int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) = 0;
+
+ /**
+ * Informs the DRM Engine about the playback actions performed on the DRM files.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the decryption session
+ * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE)
+ * @param[in] position Position in the file (in milliseconds) where the start occurs.
+ * Only valid together with Playback::START.
+ */
+ virtual void setPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle,
+ int playbackStatus, int position) = 0;
+
+ /**
+ * Validates whether an action on the DRM content is allowed or not.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path of the protected content
+ * @param[in] action Action to validate (Action::PLAY, Action::TRANSFER, etc)
+ * @param[in] description Detailed description of the action
+ * @return true if the action is allowed.
+ */
+ virtual bool validateAction(int uniqueId, const String8& path,
+ int action, const ActionDescription& description) = 0;
+
+ /**
+ * Removes the rights associated with the given protected content
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] path Path of the protected content
+ */
+ virtual void removeRights(int uniqueId, const String8& path) = 0;
+
+ /**
+ * Removes all the rights information of each plug-in associated with
+ * DRM framework. Will be used in master reset
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ */
+ virtual void removeAllRights(int uniqueId) = 0;
+
+ /**
+ * This API is for Forward Lock based DRM scheme.
+ * Each time the application tries to download a new DRM file
+ * which needs to be converted, then the application has to
+ * begin with calling this API.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] convertId Handle for the convert session
+ */
+ virtual void openConvertSession(int uniqueId, int convertId) = 0;
+
+ /**
+ * Accepts and converts the input data which is part of DRM file.
+ * The resultant converted data and the status is returned in the DrmConvertedInfo
+ * object. This method will be called each time there are new block
+ * of data received by the application.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] convertId Handle for the convert session
+ * @param[in] inputData Input Data which need to be converted
+ * @return Return object contains the status of the data conversion,
+ * the output converted data and offset. In this case the
+ * application will ignore the offset information.
+ */
+ virtual DrmConvertedStatus* convertData(
+ int uniqueId, int convertId, const DrmBuffer* inputData) = 0;
+
+ /**
+ * Informs the Drm Agent when there is no more data which need to be converted
+ * or when an error occurs. Upon successful conversion of the complete data,
+ * the agent will inform that where the header and body signature
+ * should be added. This signature appending is needed to integrity
+ * protect the converted file.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] convertId Handle for the convert session
+ * @return Return object contains the status of the data conversion,
+ * the header and body signature data. It also informs
+ * the application on which offset these signature data
+ * should be appended.
+ */
+ virtual DrmConvertedStatus* closeConvertSession( int uniqueId, int convertId) = 0;
+
+ /**
+ * Returns the information about the Drm Engine capabilities which includes
+ * supported MimeTypes and file suffixes.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @return DrmSupportInfo
+ * instance which holds the capabilities of a plug-in
+ */
+ virtual DrmSupportInfo* getSupportInfo(int uniqueId) = 0;
+
+ /**
+ * Open the decrypt session to decrypt the given protected content
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the current decryption session
+ * @param[in] fd File descriptor of the protected content to be decrypted
+ * @param[in] offset Start position of the content
+ * @param[in] length The length of the protected content
+ * @return
+ * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success
+ */
+ virtual status_t openDecryptSession(
+ int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length) = 0;
+
+ /**
+ * Close the decrypt session for the given handle
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the decryption session
+ */
+ virtual void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0;
+
+ /**
+ * Initialize decryption for the given unit of the protected content
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the decryption session
+ * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
+ * @param[in] headerInfo Information for initializing decryption of this decrypUnit
+ */
+ virtual void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* headerInfo) = 0;
+
+ /**
+ * Decrypt the protected content buffers for the given unit
+ * This method will be called any number of times, based on number of
+ * encrypted streams received from application.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the decryption session
+ * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
+ * @param[in] encBuffer Encrypted data block
+ * @param[out] decBuffer Decrypted data block
+ * @return status_t
+ * Returns the error code for this API
+ * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED
+ * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED,
+ * DRM_ERROR_DECRYPT for failure.
+ */
+ virtual status_t decrypt(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) = 0;
+
+ /**
+ * Finalize decryption for the given unit of the protected content
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the decryption session
+ * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID
+ */
+ virtual void finalizeDecryptUnit(
+ int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) = 0;
+
+ /**
+ * Reads the specified number of bytes from an open DRM file.
+ *
+ * @param[in] uniqueId Unique identifier for a session
+ * @param[in] decryptHandle Handle for the decryption session
+ * @param[out] buffer Reference to the buffer that should receive the read data.
+ * @param[in] numBytes Number of bytes to read.
+ * @param[in] offset Offset with which to update the file position.
+ *
+ * @return Number of bytes read. Returns -1 for Failure.
+ */
+ virtual ssize_t pread(int uniqueId, DecryptHandle* decryptHandle,
+ void* buffer, ssize_t numBytes, off_t offset) = 0;
+};
+
+};
+
+#endif /* __IDRM_ENGINE_H__ */
+
diff --git a/drm/libdrmframework/plugins/passthru/Android.mk b/drm/libdrmframework/plugins/passthru/Android.mk
new file mode 100644
index 0000000000000..a7bbf2367229d
--- /dev/null
+++ b/drm/libdrmframework/plugins/passthru/Android.mk
@@ -0,0 +1,44 @@
+#
+# Copyright (C) 2010 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= \
+ src/DrmPassthruPlugIn.cpp
+
+LOCAL_MODULE := libdrmpassthruplugin
+
+LOCAL_STATIC_LIBRARIES := libdrmframeworkcommon
+
+LOCAL_SHARED_LIBRARIES := \
+ libutils \
+ libdl
+
+LOCAL_PRELINK_MODULE := false
+
+LOCAL_C_INCLUDES += \
+ $(TOP)/frameworks/base/drm/libdrmframework/include \
+ $(TOP)/frameworks/base/drm/libdrmframework/plugins/passthru/include \
+ $(TOP)/frameworks/base/drm/libdrmframework/plugins/common/include \
+ $(TOP)/frameworks/base/include
+
+# Set the following flag to enable the decryption passthru flow
+#LOCAL_CFLAGS += -DENABLE_PASSTHRU_DECRYPTION
+
+PRODUCT_COPY_FILES += \
+ $(TARGET_OUT_SHARED_LIBRARIES)/libdrmpassthruplugin.so:system/lib/drm/plugins/native/libdrmpassthruplugin.so
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h b/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h
new file mode 100644
index 0000000000000..d2c7852954100
--- /dev/null
+++ b/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __DRM_PASSTHRU_PLUGIN_H__
+#define __DRM_PASSTHRU_PLUGIN_H__
+
+#include
+
+namespace android {
+
+class DrmPassthruPlugIn : public DrmEngineBase {
+
+public:
+ DrmPassthruPlugIn();
+ virtual ~DrmPassthruPlugIn();
+
+protected:
+ DrmConstraints* onGetConstraints(int uniqueId, const String8* path, int action);
+
+ status_t onInitialize(int uniqueId);
+
+ status_t onSetOnInfoListener(int uniqueId, const IDrmEngine::OnInfoListener* infoListener);
+
+ status_t onTerminate(int uniqueId);
+
+ bool onCanHandle(int uniqueId, const String8& path);
+
+ DrmInfoStatus* onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo);
+
+ void onSaveRights(int uniqueId, const DrmRights& drmRights,
+ const String8& rightsPath, const String8& contentPath);
+
+ DrmInfo* onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest);
+
+ String8 onGetOriginalMimeType(int uniqueId, const String8& path);
+
+ int onGetDrmObjectType(int uniqueId, const String8& path, const String8& mimeType);
+
+ int onCheckRightsStatus(int uniqueId, const String8& path, int action);
+
+ void onConsumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve);
+
+ void onSetPlaybackStatus(
+ int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position);
+
+ bool onValidateAction(
+ int uniqueId, const String8& path, int action, const ActionDescription& description);
+
+ void onRemoveRights(int uniqueId, const String8& path);
+
+ void onRemoveAllRights(int uniqueId);
+
+ void onOpenConvertSession(int uniqueId, int convertId);
+
+ DrmConvertedStatus* onConvertData(int uniqueId, int convertId, const DrmBuffer* inputData);
+
+ DrmConvertedStatus* onCloseConvertSession(int uniqueId, int convertId);
+
+ DrmSupportInfo* onGetSupportInfo(int uniqueId);
+
+ status_t onOpenDecryptSession(
+ int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length);
+
+ void onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
+
+ void onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* headerInfo);
+
+ status_t onDecrypt(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer);
+
+ void onFinalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId);
+
+ ssize_t onPread(int uniqueId, DecryptHandle* decryptHandle,
+ void* buffer, ssize_t numBytes, off_t offset);
+
+private:
+ DecryptHandle* openDecryptSessionImpl();
+};
+
+};
+
+#endif /* __DRM_PASSTHRU_PLUGIN_H__ */
+
diff --git a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp
new file mode 100644
index 0000000000000..2655d0b4c351e
--- /dev/null
+++ b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp
@@ -0,0 +1,280 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "DrmPassthruPlugIn"
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace android;
+
+
+// This extern "C" is mandatory to be managed by TPlugInManager
+extern "C" IDrmEngine* create() {
+ return new DrmPassthruPlugIn();
+}
+
+// This extern "C" is mandatory to be managed by TPlugInManager
+extern "C" void destroy(IDrmEngine* pPlugIn) {
+ delete pPlugIn;
+ pPlugIn = NULL;
+}
+
+DrmPassthruPlugIn::DrmPassthruPlugIn()
+ : DrmEngineBase() {
+
+}
+
+DrmPassthruPlugIn::~DrmPassthruPlugIn() {
+
+}
+
+DrmConstraints* DrmPassthruPlugIn::onGetConstraints(
+ int uniqueId, const String8* path, int action) {
+ LOGD("DrmPassthruPlugIn::onGetConstraints From Path: %d", uniqueId);
+ DrmConstraints* drmConstraints = new DrmConstraints();
+
+ String8 value("dummy_available_time");
+ char* charValue = NULL;
+ charValue = new char[value.length() + 1];
+ strncpy(charValue, value.string(), value.length());
+
+ //Just add dummy available time for verification
+ drmConstraints->put(&(DrmConstraints::LICENSE_AVAILABLE_TIME), charValue);
+
+ return drmConstraints;
+}
+
+DrmInfoStatus* DrmPassthruPlugIn::onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo) {
+ LOGD("DrmPassthruPlugIn::onProcessDrmInfo - Enter : %d", uniqueId);
+ DrmInfoStatus* drmInfoStatus = NULL;
+ if (NULL != drmInfo) {
+ switch (drmInfo->getInfoType()) {
+ case DrmInfoRequest::TYPE_REGISTRATION_INFO: {
+ const DrmBuffer* emptyBuffer = new DrmBuffer();
+ drmInfoStatus
+ = new DrmInfoStatus(DrmInfoStatus::STATUS_OK, emptyBuffer, drmInfo->getMimeType());
+ break;
+ }
+ case DrmInfoRequest::TYPE_UNREGISTRATION_INFO: {
+ const DrmBuffer* emptyBuffer = new DrmBuffer();
+ drmInfoStatus
+ = new DrmInfoStatus(DrmInfoStatus::STATUS_OK, emptyBuffer, drmInfo->getMimeType());
+ break;
+ }
+ case DrmInfoRequest::TYPE_RIGHTS_ACQUISITION_INFO: {
+ String8 licenseString("dummy_license_string");
+ const int bufferSize = licenseString.size();
+ char* data = NULL;
+ data = new char[bufferSize];
+ memcpy(data, licenseString.string(), bufferSize);
+ const DrmBuffer* buffer = new DrmBuffer(data, bufferSize);
+ drmInfoStatus
+ = new DrmInfoStatus(DrmInfoStatus::STATUS_OK, buffer, drmInfo->getMimeType());
+ break;
+ }
+ }
+ }
+ LOGD("DrmPassthruPlugIn::onProcessDrmInfo - Exit");
+ return drmInfoStatus;
+}
+
+status_t DrmPassthruPlugIn::onSetOnInfoListener(
+ int uniqueId, const IDrmEngine::OnInfoListener* infoListener) {
+ LOGD("DrmPassthruPlugIn::onSetOnInfoListener : %d", uniqueId);
+ return DRM_NO_ERROR;
+}
+
+status_t DrmPassthruPlugIn::onInitialize(int uniqueId) {
+ LOGD("DrmPassthruPlugIn::onInitialize : %d", uniqueId);
+ return DRM_NO_ERROR;
+}
+
+status_t DrmPassthruPlugIn::onTerminate(int uniqueId) {
+ LOGD("DrmPassthruPlugIn::onTerminate : %d", uniqueId);
+ return DRM_NO_ERROR;
+}
+
+DrmSupportInfo* DrmPassthruPlugIn::onGetSupportInfo(int uniqueId) {
+ LOGD("DrmPassthruPlugIn::onGetSupportInfo : %d", uniqueId);
+ DrmSupportInfo* drmSupportInfo = new DrmSupportInfo();
+ // Add mimetype's
+ drmSupportInfo->addMimeType(String8("application/vnd.passthru.drm"));
+ // Add File Suffixes
+ drmSupportInfo->addFileSuffix(String8(".passthru"));
+ // Add plug-in description
+ drmSupportInfo->setDescription(String8("Passthru plug-in"));
+ return drmSupportInfo;
+}
+
+void DrmPassthruPlugIn::onSaveRights(int uniqueId, const DrmRights& drmRights,
+ const String8& rightsPath, const String8& contentPath) {
+ LOGD("DrmPassthruPlugIn::onSaveRights : %d", uniqueId);
+}
+
+DrmInfo* DrmPassthruPlugIn::onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) {
+ LOGD("DrmPassthruPlugIn::onAcquireDrmInfo : %d", uniqueId);
+ DrmInfo* drmInfo = NULL;
+
+ if (NULL != drmInfoRequest) {
+ String8 dataString("dummy_acquistion_string");
+ int length = dataString.length();
+ char* data = NULL;
+ data = new char[length];
+ memcpy(data, dataString.string(), length);
+ drmInfo = new DrmInfo(drmInfoRequest->getInfoType(),
+ DrmBuffer(data, length), drmInfoRequest->getMimeType());
+ }
+ return drmInfo;
+}
+
+bool DrmPassthruPlugIn::onCanHandle(int uniqueId, const String8& path) {
+ LOGD("DrmPassthruPlugIn::canHandle: %s ", path.string());
+ String8 extension = path.getPathExtension();
+ extension.toLower();
+ return (String8(".passthru") == extension);
+}
+
+String8 DrmPassthruPlugIn::onGetOriginalMimeType(int uniqueId, const String8& path) {
+ LOGD("DrmPassthruPlugIn::onGetOriginalMimeType() : %d", uniqueId);
+ return String8("video/passthru");
+}
+
+int DrmPassthruPlugIn::onGetDrmObjectType(
+ int uniqueId, const String8& path, const String8& mimeType) {
+ LOGD("DrmPassthruPlugIn::onGetDrmObjectType() : %d", uniqueId);
+ return DrmObjectType::UNKNOWN;
+}
+
+int DrmPassthruPlugIn::onCheckRightsStatus(int uniqueId, const String8& path, int action) {
+ LOGD("DrmPassthruPlugIn::onCheckRightsStatus() : %d", uniqueId);
+ int rightsStatus = RightsStatus::RIGHTS_VALID;
+ return rightsStatus;
+}
+
+void DrmPassthruPlugIn::onConsumeRights(int uniqueId, DecryptHandle* decryptHandle,
+ int action, bool reserve) {
+ LOGD("DrmPassthruPlugIn::onConsumeRights() : %d", uniqueId);
+}
+
+void DrmPassthruPlugIn::onSetPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle,
+ int playbackStatus, int position) {
+ LOGD("DrmPassthruPlugIn::onSetPlaybackStatus() : %d", uniqueId);
+}
+
+bool DrmPassthruPlugIn::onValidateAction(int uniqueId, const String8& path,
+ int action, const ActionDescription& description) {
+ LOGD("DrmPassthruPlugIn::onValidateAction() : %d", uniqueId);
+ return true;
+}
+
+void DrmPassthruPlugIn::onRemoveRights(int uniqueId, const String8& path) {
+ LOGD("DrmPassthruPlugIn::onRemoveRights() : %d", uniqueId);
+}
+
+void DrmPassthruPlugIn::onRemoveAllRights(int uniqueId) {
+ LOGD("DrmPassthruPlugIn::onRemoveAllRights() : %d", uniqueId);
+}
+
+void DrmPassthruPlugIn::onOpenConvertSession(int uniqueId, int convertId) {
+ LOGD("DrmPassthruPlugIn::onOpenConvertSession() : %d", uniqueId);
+}
+
+DrmConvertedStatus* DrmPassthruPlugIn::onConvertData(
+ int uniqueId, int convertId, const DrmBuffer* inputData) {
+ LOGD("DrmPassthruPlugIn::onConvertData() : %d", uniqueId);
+ DrmBuffer* convertedData = NULL;
+
+ if (NULL != inputData && 0 < inputData->length) {
+ int length = inputData->length;
+ char* data = NULL;
+ data = new char[length];
+ convertedData = new DrmBuffer(data, length);
+ memcpy(convertedData->data, inputData->data, length);
+ }
+ return new DrmConvertedStatus(DrmConvertedStatus::STATUS_OK, convertedData, 0 /*offset*/);
+}
+
+DrmConvertedStatus* DrmPassthruPlugIn::onCloseConvertSession(int uniqueId, int convertId) {
+ LOGD("DrmPassthruPlugIn::onCloseConvertSession() : %d", uniqueId);
+ return new DrmConvertedStatus(DrmConvertedStatus::STATUS_OK, NULL, 0 /*offset*/);
+}
+
+status_t DrmPassthruPlugIn::onOpenDecryptSession(
+ int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length) {
+ LOGD("DrmPassthruPlugIn::onOpenDecryptSession() : %d", uniqueId);
+
+#ifdef ENABLE_PASSTHRU_DECRYPTION
+ decryptHandle->mimeType = String8("video/passthru");
+ decryptHandle->decryptApiType = DecryptApiType::ELEMENTARY_STREAM_BASED;
+ decryptHandle->status = DRM_NO_ERROR;
+ decryptHandle->decryptInfo = NULL;
+ return DRM_NO_ERROR;
+#endif
+
+ return DRM_ERROR_CANNOT_HANDLE;
+}
+
+void DrmPassthruPlugIn::onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
+ LOGD("DrmPassthruPlugIn::onCloseDecryptSession() : %d", uniqueId);
+ if (NULL != decryptHandle) {
+ if (NULL != decryptHandle->decryptInfo) {
+ delete decryptHandle->decryptInfo; decryptHandle->decryptInfo = NULL;
+ }
+ delete decryptHandle; decryptHandle = NULL;
+ }
+}
+
+void DrmPassthruPlugIn::onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* headerInfo) {
+ LOGD("DrmPassthruPlugIn::onInitializeDecryptUnit() : %d", uniqueId);
+}
+
+status_t DrmPassthruPlugIn::onDecrypt(int uniqueId, DecryptHandle* decryptHandle,
+ int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) {
+ LOGD("DrmPassthruPlugIn::onDecrypt() : %d", uniqueId);
+ /**
+ * As a workaround implementation passthru would copy the given
+ * encrypted buffer as it is to decrypted buffer. Note, decBuffer
+ * memory has to be allocated by the caller.
+ */
+ if (NULL != (*decBuffer) && 0 < (*decBuffer)->length) {
+ memcpy((*decBuffer)->data, encBuffer->data, encBuffer->length);
+ (*decBuffer)->length = encBuffer->length;
+ }
+ return DRM_NO_ERROR;
+}
+
+void DrmPassthruPlugIn::onFinalizeDecryptUnit(
+ int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
+ LOGD("DrmPassthruPlugIn::onFinalizeDecryptUnit() : %d", uniqueId);
+}
+
+ssize_t DrmPassthruPlugIn::onPread(int uniqueId, DecryptHandle* decryptHandle,
+ void* buffer, ssize_t numBytes, off_t offset) {
+ LOGD("DrmPassthruPlugIn::onPread() : %d", uniqueId);
+ return 0;
+}
+
diff --git a/include/drm/DrmConstraints.h b/include/drm/DrmConstraints.h
new file mode 100644
index 0000000000000..a9ec94252f208
--- /dev/null
+++ b/include/drm/DrmConstraints.h
@@ -0,0 +1,183 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __DRM_CONSTRAINTS_H__
+#define __DRM_CONSTRAINTS_H__
+
+#include "drm_framework_common.h"
+
+namespace android {
+
+/**
+ * This is an utility class which contains the constraints information.
+ *
+ * As a result of DrmManagerClient::getConstraints(const String8*, const int)
+ * an instance of DrmConstraints would be returned.
+ *
+ */
+class DrmConstraints {
+public:
+ /**
+ * The following variables are replica of android.drm.DrmStore.ConstraintsColumns
+ * Any changes should also be incorporated with Java Layer as well
+ */
+ /**
+ * The max repeat count
+ */
+ static const String8 MAX_REPEAT_COUNT;
+ /**
+ * The remaining repeat count
+ */
+ static const String8 REMAINING_REPEAT_COUNT;
+
+ /**
+ * The time before which the protected file can not be played/viewed
+ */
+ static const String8 LICENSE_START_TIME;
+
+ /**
+ * The time after which the protected file can not be played/viewed
+ */
+ static const String8 LICENSE_EXPIRY_TIME;
+
+ /**
+ * The available time for license
+ */
+ static const String8 LICENSE_AVAILABLE_TIME;
+
+ /**
+ * The data stream for extended metadata
+ */
+ static const String8 EXTENDED_METADATA;
+
+public:
+ /**
+ * Iterator for key
+ */
+ class KeyIterator {
+ friend class DrmConstraints;
+ private:
+ KeyIterator(DrmConstraints* drmConstraints)
+ : mDrmConstraints(drmConstraints), mIndex(0) {}
+
+ public:
+ KeyIterator(const KeyIterator& keyIterator);
+ KeyIterator& operator=(const KeyIterator& keyIterator);
+ virtual ~KeyIterator() {}
+
+ public:
+ bool hasNext();
+ const String8& next();
+
+ private:
+ DrmConstraints* mDrmConstraints;
+ unsigned int mIndex;
+ };
+
+ /**
+ * Iterator for constraints
+ */
+ class Iterator {
+ friend class DrmConstraints;
+ private:
+ Iterator(DrmConstraints* drmConstraints)
+ : mDrmConstraints(drmConstraints), mIndex(0) {}
+
+ public:
+ Iterator(const Iterator& iterator);
+ Iterator& operator=(const Iterator& iterator);
+ virtual ~Iterator() {}
+
+ public:
+ bool hasNext();
+ String8 next();
+
+ private:
+ DrmConstraints* mDrmConstraints;
+ unsigned int mIndex;
+ };
+
+public:
+ DrmConstraints() {}
+ virtual ~DrmConstraints() {
+ DrmConstraints::KeyIterator keyIt = this->keyIterator();
+
+ while (keyIt.hasNext()) {
+ String8 key = keyIt.next();
+ const char* value = this->getAsByteArray(&key);
+ if (NULL != value) {
+ delete[] value;
+ value = NULL;
+ }
+ }
+ mConstraintMap.clear();
+ }
+public:
+ /**
+ * Returns the number of constraints contained in this instance
+ *
+ * @return Number of constraints
+ */
+ int getCount(void) const;
+
+ /**
+ * Adds constraint information as pair to this instance
+ *
+ * @param[in] key Key to add
+ * @param[in] value Value to add
+ * @return Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
+ */
+ status_t put(const String8* key, const char* value);
+
+ /**
+ * Retrieves the value of given key
+ *
+ * @param key Key whose value to be retrieved
+ * @return The value
+ */
+ String8 get(const String8& key) const;
+
+ /**
+ * Retrieves the value as byte array of given key
+ * @param key Key whose value to be retrieved as byte array
+ * @return The byte array value
+ */
+ const char* getAsByteArray(const String8* key) const;
+
+ /**
+ * Returns KeyIterator object to walk through the keys associated with this instance
+ *
+ * @return KeyIterator object
+ */
+ KeyIterator keyIterator();
+
+ /**
+ * Returns Iterator object to walk through the values associated with this instance
+ *
+ * @return Iterator object
+ */
+ Iterator iterator();
+private:
+ const char* getValue(const String8* key) const;
+private:
+ typedef KeyedVector DrmConstraintsMap;
+ DrmConstraintsMap mConstraintMap;
+};
+
+};
+
+#endif /* __DRM_CONSTRAINTS_H__ */
+
diff --git a/include/drm/DrmConvertedStatus.h b/include/drm/DrmConvertedStatus.h
new file mode 100644
index 0000000000000..679e48df99905
--- /dev/null
+++ b/include/drm/DrmConvertedStatus.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __DRM_CONVERTED_STATUS_H__
+#define __DRM_CONVERTED_STATUS_H__
+
+#include "drm_framework_common.h"
+
+namespace android {
+
+/**
+ * This is an utility class which wraps the status of the conversion, the converted
+ * data/checksum data and the offset. Offset is going to be used in the case of close
+ * session where the agent will inform where the header and body signature should be added
+ *
+ * As a result of DrmManagerClient::convertData(int, const DrmBuffer*) and
+ * DrmManagerClient::closeConvertSession(int) an instance of DrmConvertedStatus
+ * would be returned.
+ *
+ */
+class DrmConvertedStatus {
+public:
+ // Should be in sync with DrmConvertedStatus.java
+ static const int STATUS_OK = 1;
+ static const int STATUS_INPUTDATA_ERROR = 2;
+ static const int STATUS_ERROR = 3;
+
+public:
+ /**
+ * Constructor for DrmConvertedStatus
+ *
+ * @param[in] _statusCode Status of the conversion
+ * @param[in] _convertedData Converted data/checksum data
+ * @param[in] _offset Offset value
+ */
+ DrmConvertedStatus(int _statusCode, const DrmBuffer* _convertedData, int _offset);
+
+ /**
+ * Destructor for DrmConvertedStatus
+ */
+ virtual ~DrmConvertedStatus() {
+
+ }
+
+public:
+ int statusCode;
+ const DrmBuffer* convertedData;
+ int offset;
+};
+
+};
+
+#endif /* __DRM_CONVERTED_STATUS_H__ */
+
diff --git a/include/drm/DrmInfo.h b/include/drm/DrmInfo.h
new file mode 100644
index 0000000000000..7b4854187a575
--- /dev/null
+++ b/include/drm/DrmInfo.h
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __DRM_INFO_H__
+#define __DRM_INFO_H__
+
+#include "drm_framework_common.h"
+
+namespace android {
+
+/**
+ * This is an utility class in which necessary information required to transact
+ * between device and online DRM server is described. DRM Framework achieves
+ * server registration, license acquisition and any other server related transaction
+ * by passing an instance of this class to DrmManagerClient::processDrmInfo(const DrmInfo*).
+ *
+ * The Caller can retrieve the DrmInfo instance by using
+ * DrmManagerClient::acquireDrmInfo(const DrmInfoRequest*) by passing DrmInfoRequest instance.
+ *
+ */
+class DrmInfo {
+public:
+ /**
+ * Constructor for DrmInfo
+ *
+ * @param[in] infoType Type of information
+ * @param[in] drmBuffer Trigger data
+ * @param[in] mimeType MIME type
+ */
+ DrmInfo(int infoType, const DrmBuffer& drmBuffer, const String8& mimeType);
+
+ /**
+ * Destructor for DrmInfo
+ */
+ virtual ~DrmInfo() {}
+
+public:
+ /**
+ * Iterator for key
+ */
+ class KeyIterator {
+ friend class DrmInfo;
+
+ private:
+ KeyIterator(const DrmInfo* drmInfo)
+ : mDrmInfo(const_cast (drmInfo)), mIndex(0) {}
+
+ public:
+ KeyIterator(const KeyIterator& keyIterator);
+ KeyIterator& operator=(const KeyIterator& keyIterator);
+ virtual ~KeyIterator() {}
+
+ public:
+ bool hasNext();
+ const String8& next();
+
+ private:
+ DrmInfo* mDrmInfo;
+ unsigned int mIndex;
+ };
+
+ /**
+ * Iterator
+ */
+ class Iterator {
+ friend class DrmInfo;
+
+ private:
+ Iterator(const DrmInfo* drmInfo)
+ : mDrmInfo(const_cast (drmInfo)), mIndex(0) {}
+
+ public:
+ Iterator(const Iterator& iterator);
+ Iterator& operator=(const Iterator& iterator);
+ virtual ~Iterator() {}
+
+ public:
+ bool hasNext();
+ String8& next();
+
+ private:
+ DrmInfo* mDrmInfo;
+ unsigned int mIndex;
+ };
+
+public:
+ /**
+ * Returns information type associated with this instance
+ *
+ * @return Information type
+ */
+ int getInfoType(void) const;
+
+ /**
+ * Returns MIME type associated with this instance
+ *
+ * @return MIME type
+ */
+ String8 getMimeType(void) const;
+
+ /**
+ * Returns the trigger data associated with this instance
+ *
+ * @return Trigger data
+ */
+ const DrmBuffer& getData(void) const;
+
+ /**
+ * Returns the number of attributes contained in this instance
+ *
+ * @return Number of attributes
+ */
+ int getCount(void) const;
+
+ /**
+ * Adds optional information as pair to this instance
+ *
+ * @param[in] key Key to add
+ * @param[in] value Value to add
+ * @return Returns the error code
+ */
+ status_t put(const String8& key, const String8& value);
+
+ /**
+ * Retrieves the value of given key
+ *
+ * @param key Key whose value to be retrieved
+ * @return The value
+ */
+ String8 get(const String8& key) const;
+
+ /**
+ * Returns KeyIterator object to walk through the keys associated with this instance
+ *
+ * @return KeyIterator object
+ */
+ KeyIterator keyIterator() const;
+
+ /**
+ * Returns Iterator object to walk through the values associated with this instance
+ *
+ * @return Iterator object
+ */
+ Iterator iterator() const;
+
+ /**
+ * Returns index of the given key
+ *
+ * @return index
+ */
+ int indexOfKey(const String8& key) const;
+
+protected:
+ int mInfoType;
+ DrmBuffer mData;
+ String8 mMimeType;
+ KeyedVector mAttributes;
+};
+
+};
+
+#endif /* __DRM_INFO_H__ */
+
diff --git a/include/drm/DrmInfoEvent.h b/include/drm/DrmInfoEvent.h
new file mode 100644
index 0000000000000..5e8817c75542f
--- /dev/null
+++ b/include/drm/DrmInfoEvent.h
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __DRM_INFO_EVENT_H__
+#define __DRM_INFO_EVENT_H__
+
+namespace android {
+
+class String8;
+
+/**
+ * This is an entity class which would be passed to caller in
+ * DrmManagerClient::OnInfoListener::onInfo(const DrmInfoEvent&).
+ */
+class DrmInfoEvent {
+public:
+ //! TYPE_ALREADY_REGISTERED_BY_ANOTHER_ACCOUNT, when registration has been
+ //! already done by another account ID.
+ static const int TYPE_ALREADY_REGISTERED_BY_ANOTHER_ACCOUNT = 0x0000001;
+ //! TYPE_REMOVE_RIGHTS, when the rights needs to be removed completely.
+ static const int TYPE_REMOVE_RIGHTS = 0x0000002;
+ //! TYPE_RIGHTS_INSTALLED, when the rights are downloaded and installed ok.
+ static const int TYPE_RIGHTS_INSTALLED = 0x0000003;
+ //! TYPE_RIGHTS_NOT_INSTALLED, when something went wrong installing the rights
+ static const int TYPE_RIGHTS_NOT_INSTALLED = 0x0000004;
+ //! TYPE_RIGHTS_RENEWAL_NOT_ALLOWED, when the server rejects renewal of rights
+ static const int TYPE_RIGHTS_RENEWAL_NOT_ALLOWED = 0x0000005;
+ //! TYPE_NOT_SUPPORTED, when answer from server can not be handled by the native agent
+ static const int TYPE_NOT_SUPPORTED = 0x0000006;
+ //! TYPE_WAIT_FOR_RIGHTS, rights object is on it's way to phone,
+ //! wait before calling checkRights again
+ static const int TYPE_WAIT_FOR_RIGHTS = 0x0000007;
+ //! TYPE_OUT_OF_MEMORY, when memory allocation fail during renewal.
+ //! Can in the future perhaps be used to trigger garbage collector
+ static const int TYPE_OUT_OF_MEMORY = 0x0000008;
+ //! TYPE_NO_INTERNET_CONNECTION, when the Internet connection is missing and no attempt
+ //! can be made to renew rights
+ static const int TYPE_NO_INTERNET_CONNECTION = 0x0000009;
+
+public:
+ /**
+ * Constructor for DrmInfoEvent
+ *
+ * @param[in] uniqueId Unique session identifier
+ * @param[in] infoType Type of information
+ * @param[in] message Message description
+ */
+ DrmInfoEvent(int uniqueId, int infoType, const String8& message);
+
+ /**
+ * Destructor for DrmInfoEvent
+ */
+ virtual ~DrmInfoEvent() {}
+
+public:
+ /**
+ * Returns the Unique Id associated with this instance
+ *
+ * @return Unique Id
+ */
+ int getUniqueId() const;
+
+ /**
+ * Returns the Type of information associated with this object
+ *
+ * @return Type of information
+ */
+ int getType() const;
+
+ /**
+ * Returns the message description associated with this object
+ *
+ * @return Message description
+ */
+ const String8& getMessage() const;
+
+private:
+ int mUniqueId;
+ int mInfoType;
+ const String8& mMessage;
+};
+
+};
+
+#endif /* __DRM_INFO_EVENT_H__ */
+
diff --git a/include/drm/DrmInfoRequest.h b/include/drm/DrmInfoRequest.h
new file mode 100644
index 0000000000000..3e48ecc8599f9
--- /dev/null
+++ b/include/drm/DrmInfoRequest.h
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __DRM_INFO_REQUEST_H__
+#define __DRM_INFO_REQUEST_H__
+
+#include "drm_framework_common.h"
+
+namespace android {
+
+/**
+ * This is an utility class used to pass required parameters to get
+ * the necessary information to communicate with online DRM server
+ *
+ * An instance of this class is passed to
+ * DrmManagerClient::acquireDrmInfo(const DrmInfoRequest*) to get the
+ * instance of DrmInfo.
+ *
+ */
+class DrmInfoRequest {
+public:
+ // Changes in following constants should be in sync with DrmInfoRequest.java
+ static const int TYPE_REGISTRATION_INFO = 1;
+ static const int TYPE_UNREGISTRATION_INFO = 2;
+ static const int TYPE_RIGHTS_ACQUISITION_INFO = 3;
+ static const int TYPE_RIGHTS_ACQUISITION_PROGRESS_INFO = 4;
+
+ /**
+ * Key to pass the unique id for the account or the user
+ */
+ static const String8 ACCOUNT_ID;
+ /**
+ * Key to pass the subscription id
+ */
+ static const String8 SUBSCRIPTION_ID;
+
+public:
+ /**
+ * Constructor for DrmInfoRequest
+ *
+ * @param[in] infoType Type of information
+ * @param[in] mimeType MIME type
+ */
+ DrmInfoRequest(int infoType, const String8& mimeType);
+
+ /**
+ * Destructor for DrmInfoRequest
+ */
+ virtual ~DrmInfoRequest() {}
+
+public:
+ /**
+ * Iterator for key
+ */
+ class KeyIterator {
+ friend class DrmInfoRequest;
+
+ private:
+ KeyIterator(const DrmInfoRequest* drmInfoRequest)
+ : mDrmInfoRequest(const_cast (drmInfoRequest)), mIndex(0) {}
+
+ public:
+ KeyIterator(const KeyIterator& keyIterator);
+ KeyIterator& operator=(const KeyIterator& keyIterator);
+ virtual ~KeyIterator() {}
+
+ public:
+ bool hasNext();
+ const String8& next();
+
+ private:
+ DrmInfoRequest* mDrmInfoRequest;
+ unsigned int mIndex;
+ };
+
+ /**
+ * Iterator
+ */
+ class Iterator {
+ friend class DrmInfoRequest;
+
+ private:
+ Iterator(const DrmInfoRequest* drmInfoRequest)
+ : mDrmInfoRequest(const_cast (drmInfoRequest)), mIndex(0) {}
+
+ public:
+ Iterator(const Iterator& iterator);
+ Iterator& operator=(const Iterator& iterator);
+ virtual ~Iterator() {}
+
+ public:
+ bool hasNext();
+ String8& next();
+
+ private:
+ DrmInfoRequest* mDrmInfoRequest;
+ unsigned int mIndex;
+ };
+
+public:
+ /**
+ * Returns information type associated with this instance
+ *
+ * @return Information type
+ */
+ int getInfoType(void) const;
+
+ /**
+ * Returns MIME type associated with this instance
+ *
+ * @return MIME type
+ */
+ String8 getMimeType(void) const;
+
+ /**
+ * Returns the number of entries in DrmRequestInfoMap
+ *
+ * @return Number of entries
+ */
+ int getCount(void) const;
+
+ /**
+ * Adds optional information as