am cba7b32d: Add a new API on DRM Framework for streaming

* commit 'cba7b32d8f2c47632313f54118ed3733b4b02cc8':
  Add a new API on DRM Framework for streaming
diff --git a/drm/common/DrmEngineBase.cpp b/drm/common/DrmEngineBase.cpp
index 1c345a2..a060f38 100644
--- a/drm/common/DrmEngineBase.cpp
+++ b/drm/common/DrmEngineBase.cpp
@@ -139,6 +139,11 @@
     return onOpenDecryptSession(uniqueId, decryptHandle, uri, mime);
 }
 
+status_t DrmEngineBase::openDecryptSession(int uniqueId, DecryptHandle* decryptHandle,
+        const DrmBuffer& buf, const String8& mimeType) {
+    return onOpenDecryptSession(uniqueId, decryptHandle, buf, mimeType);
+}
+
 status_t DrmEngineBase::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
     return onCloseDecryptSession(uniqueId, decryptHandle);
 }
diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp
index 43f64f2..ccff257 100644
--- a/drm/common/IDrmManagerService.cpp
+++ b/drm/common/IDrmManagerService.cpp
@@ -652,6 +652,33 @@
     return handle;
 }
 
+DecryptHandle* BpDrmManagerService::openDecryptSession(
+            int uniqueId, const DrmBuffer& buf, const String8& mimeType) {
+    ALOGV("Entering BpDrmManagerService::openDecryptSession");
+    Parcel data, reply;
+
+    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
+    data.writeInt32(uniqueId);
+    if (buf.data != NULL && buf.length > 0) {
+        data.writeInt32(buf.length);
+        data.write(buf.data, buf.length);
+    } else {
+        data.writeInt32(0);
+    }
+    data.writeString8(mimeType);
+
+    remote()->transact(OPEN_DECRYPT_SESSION_FOR_STREAMING, data, &reply);
+
+    DecryptHandle* handle = NULL;
+    if (0 != reply.dataAvail()) {
+        handle = new DecryptHandle();
+        readDecryptHandleFromParcelData(handle, reply);
+    } else {
+        ALOGV("no decryptHandle is generated in service side");
+    }
+    return handle;
+}
+
 status_t BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
     ALOGV("closeDecryptSession");
     Parcel data, reply;
@@ -1312,6 +1339,30 @@
         return DRM_NO_ERROR;
     }
 
+    case OPEN_DECRYPT_SESSION_FOR_STREAMING:
+    {
+        ALOGV("BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION_FOR_STREAMING");
+        CHECK_INTERFACE(IDrmManagerService, data, reply);
+
+        const int uniqueId = data.readInt32();
+        const int bufferSize = data.readInt32();
+        DrmBuffer buf((bufferSize > 0) ? (char *)data.readInplace(bufferSize) : NULL,
+                bufferSize);
+        const String8 mimeType(data.readString8());
+
+        DecryptHandle* handle = openDecryptSession(uniqueId, buf, mimeType);
+
+        if (handle != NULL) {
+            writeDecryptHandleToParcelData(handle, reply);
+            clearDecryptHandle(handle);
+            delete handle;
+            handle = NULL;
+        } else {
+            ALOGV("NULL decryptHandle is returned");
+        }
+        return DRM_NO_ERROR;
+    }
+
     case CLOSE_DECRYPT_SESSION:
     {
         ALOGV("BnDrmManagerService::onTransact :CLOSE_DECRYPT_SESSION");
diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp
index 999295a..737edab 100644
--- a/drm/drmserver/DrmManager.cpp
+++ b/drm/drmserver/DrmManager.cpp
@@ -484,6 +484,36 @@
     return handle;
 }
 
+DecryptHandle* DrmManager::openDecryptSession(
+        int uniqueId, const DrmBuffer& buf, const String8& mimeType) {
+    Mutex::Autolock _l(mDecryptLock);
+    status_t result = DRM_ERROR_CANNOT_HANDLE;
+    Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
+
+    DecryptHandle* handle = new DecryptHandle();
+    if (NULL != handle) {
+        handle->decryptId = mDecryptSessionId + 1;
+
+        for (size_t index = 0; index < plugInIdList.size(); index++) {
+            String8 plugInId = plugInIdList.itemAt(index);
+            IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
+            result = rDrmEngine.openDecryptSession(uniqueId, handle, buf, mimeType);
+
+            if (DRM_NO_ERROR == result) {
+                ++mDecryptSessionId;
+                mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine);
+                break;
+            }
+        }
+    }
+    if (DRM_NO_ERROR != result) {
+        delete handle;
+        handle = NULL;
+        ALOGV("DrmManager::openDecryptSession: no capable plug-in found");
+    }
+    return handle;
+}
+
 status_t DrmManager::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
     Mutex::Autolock _l(mDecryptLock);
     status_t result = DRM_ERROR_UNKNOWN;
diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp
index 746f506..25a4e7b 100644
--- a/drm/drmserver/DrmManagerService.cpp
+++ b/drm/drmserver/DrmManagerService.cpp
@@ -219,6 +219,16 @@
     return NULL;
 }
 
+DecryptHandle* DrmManagerService::openDecryptSession(
+            int uniqueId, const DrmBuffer& buf, const String8& mimeType) {
+    ALOGV("Entering DrmManagerService::openDecryptSession for streaming");
+    if (isProtectedCallAllowed()) {
+        return mDrmManager->openDecryptSession(uniqueId, buf, mimeType);
+    }
+
+    return NULL;
+}
+
 status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
     ALOGV("Entering closeDecryptSession");
     if (!isProtectedCallAllowed()) {
diff --git a/drm/libdrmframework/DrmManagerClient.cpp b/drm/libdrmframework/DrmManagerClient.cpp
index 8768c08..d4db461 100644
--- a/drm/libdrmframework/DrmManagerClient.cpp
+++ b/drm/libdrmframework/DrmManagerClient.cpp
@@ -130,6 +130,11 @@
                     mUniqueId, uri, mime);
 }
 
+sp<DecryptHandle> DrmManagerClient::openDecryptSession(
+            const DrmBuffer& buf, const String8& mimeType) {
+    return mDrmManagerClientImpl->openDecryptSession(mUniqueId, buf, mimeType);
+}
+
 status_t DrmManagerClient::closeDecryptSession(sp<DecryptHandle> &decryptHandle) {
     return mDrmManagerClientImpl->closeDecryptSession(mUniqueId, decryptHandle);
 }
diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp
index fb0439e..b1228d4 100644
--- a/drm/libdrmframework/DrmManagerClientImpl.cpp
+++ b/drm/libdrmframework/DrmManagerClientImpl.cpp
@@ -272,6 +272,11 @@
     return handle;
 }
 
+sp<DecryptHandle> DrmManagerClientImpl::openDecryptSession(
+            int uniqueId, const DrmBuffer& buf, const String8& mimeType) {
+    return getDrmManagerService()->openDecryptSession(uniqueId, buf, mimeType);
+}
+
 status_t DrmManagerClientImpl::closeDecryptSession(
         int uniqueId, sp<DecryptHandle> &decryptHandle) {
     status_t status = DRM_ERROR_UNKNOWN;
diff --git a/drm/libdrmframework/include/DrmManager.h b/drm/libdrmframework/include/DrmManager.h
index c9167d4..3942efe 100644
--- a/drm/libdrmframework/include/DrmManager.h
+++ b/drm/libdrmframework/include/DrmManager.h
@@ -116,6 +116,9 @@
 
     DecryptHandle* openDecryptSession(int uniqueId, const char* uri, const char* mime);
 
+    DecryptHandle* openDecryptSession(int uniqueId, const DrmBuffer& buf,
+            const String8& mimeType);
+
     status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
 
     status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
diff --git a/drm/libdrmframework/include/DrmManagerClientImpl.h b/drm/libdrmframework/include/DrmManagerClientImpl.h
index 2aa493f..f3d9315 100644
--- a/drm/libdrmframework/include/DrmManagerClientImpl.h
+++ b/drm/libdrmframework/include/DrmManagerClientImpl.h
@@ -320,6 +320,18 @@
             int uniqueId, const char* uri, const char* mime);
 
     /**
+     * Open the decrypt session to decrypt the given protected content
+     *
+     * @param[in] uniqueId Unique identifier for a session
+     * @param[in] buf Data to initiate decrypt session
+     * @param[in] mimeType Mime type of the protected content
+     * @return
+     *     Handle for the decryption session
+     */
+    sp<DecryptHandle> openDecryptSession(int uniqueId, const DrmBuffer& buf,
+            const String8& mimeType);
+
+    /**
      * Close the decrypt session for the given handle
      *
      * @param[in] uniqueId Unique identifier for a session
diff --git a/drm/libdrmframework/include/DrmManagerService.h b/drm/libdrmframework/include/DrmManagerService.h
index 1a8c2ae..066fe4a 100644
--- a/drm/libdrmframework/include/DrmManagerService.h
+++ b/drm/libdrmframework/include/DrmManagerService.h
@@ -104,6 +104,9 @@
     DecryptHandle* openDecryptSession(
         int uniqueId, const char* uri, const char* mime);
 
+    DecryptHandle* openDecryptSession(int uniqueId, const DrmBuffer& buf,
+            const String8& mimeType);
+
     status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
 
     status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
diff --git a/drm/libdrmframework/include/IDrmManagerService.h b/drm/libdrmframework/include/IDrmManagerService.h
index a7d21c5..5b89c91 100644
--- a/drm/libdrmframework/include/IDrmManagerService.h
+++ b/drm/libdrmframework/include/IDrmManagerService.h
@@ -70,6 +70,7 @@
         GET_ALL_SUPPORT_INFO,
         OPEN_DECRYPT_SESSION,
         OPEN_DECRYPT_SESSION_FROM_URI,
+        OPEN_DECRYPT_SESSION_FOR_STREAMING,
         CLOSE_DECRYPT_SESSION,
         INITIALIZE_DECRYPT_UNIT,
         DECRYPT,
@@ -146,6 +147,9 @@
     virtual DecryptHandle* openDecryptSession(
                 int uniqueId, const char* uri, const char* mime) = 0;
 
+    virtual DecryptHandle* openDecryptSession(
+            int uniqueId, const DrmBuffer& buf, const String8& mimeType) = 0;
+
     virtual status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0;
 
     virtual status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
@@ -232,6 +236,9 @@
     virtual DecryptHandle* openDecryptSession(
                 int uniqueId, const char* uri, const char* mime);
 
+    virtual DecryptHandle* openDecryptSession(
+            int uniqueId, const DrmBuffer& buf, const String8& mimeType);
+
     virtual status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
 
     virtual status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
diff --git a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h
index 08f6e6d..6cebb97 100644
--- a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h
+++ b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h
@@ -87,6 +87,9 @@
             int uniqueId, DecryptHandle* decryptHandle,
             const char* uri, const char* mime);
 
+    status_t openDecryptSession(int uniqueId, DecryptHandle* decryptHandle,
+            const DrmBuffer& buf, const String8& mimeType);
+
     status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
 
     status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
@@ -433,6 +436,21 @@
     }
 
     /**
+     * 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] buf Data to initiate decrypt session
+     * @param[in] mimeType Mime type 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,
+            const DrmBuffer& buf, const String8& mimeType) {
+        return DRM_ERROR_CANNOT_HANDLE;
+    }
+
+    /**
      * Close the decrypt session for the given handle
      *
      * @param[in] uniqueId Unique identifier for a session
diff --git a/drm/libdrmframework/plugins/common/include/IDrmEngine.h b/drm/libdrmframework/plugins/common/include/IDrmEngine.h
index dcf5977..60f4c1b 100644
--- a/drm/libdrmframework/plugins/common/include/IDrmEngine.h
+++ b/drm/libdrmframework/plugins/common/include/IDrmEngine.h
@@ -345,6 +345,19 @@
         const char* uri, const char* mime) = 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] buf Data to initiate decrypt session
+     * @param[in] mimeType Mime type 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,
+            const DrmBuffer& buf, const String8& mimeType) = 0;
+
+    /**
      * Close the decrypt session for the given handle
      *
      * @param[in] uniqueId Unique identifier for a session
diff --git a/include/drm/DrmManagerClient.h b/include/drm/DrmManagerClient.h
index c47bbfb..a5c6992 100644
--- a/include/drm/DrmManagerClient.h
+++ b/include/drm/DrmManagerClient.h
@@ -83,6 +83,16 @@
     sp<DecryptHandle> openDecryptSession(const char* uri, const char* mime);
 
     /**
+     * Open the decrypt session to decrypt the given protected content
+     *
+     * @param[in] buf Data to initiate decrypt session
+     * @param[in] mimeType Mime type of the protected content
+     * @return
+     *     Handle for the decryption session
+     */
+    sp<DecryptHandle> openDecryptSession(const DrmBuffer& buf, const String8& mimeType);
+
+    /**
      * Close the decrypt session for the given handle
      *
      * @param[in] decryptHandle Handle for the decryption session