Update of DRM framework.

  - Change "void" type of return value to "int" for returning status.
  - Add some of overloaded Java APIs which accept database Uri as input.
  - Add asynchronous APIs
  - Add OnEventListener and OnErrorListener for asynchronous APIs
  - Disable debug log
  - Change decrypt() API to accept an optional buffer needed by some of DRM schemes

Changes are incorporated by Sony Corporation.

Change-Id: I414a165e22cc79be6ea7cd28041788aa2b6b8f7c
diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp
index 9d000e9..843dddb 100644
--- a/drm/drmserver/DrmManagerService.cpp
+++ b/drm/drmserver/DrmManagerService.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#define LOG_NDEBUG 0
+//#define LOG_NDEBUG 0
 #define LOG_TAG "DrmManagerService(Native)"
 #include <utils/Log.h>
 
@@ -29,20 +29,23 @@
 
 #define SUCCESS 0
 #define DRM_DIRECTORY_PERMISSION 0700
+#define DRM_PLUGINS_ROOT "/data/drm/plugins"
+#define DRM_PLUGINS_NATIVE "/data/drm/plugins/native"
+#define DRM_PLUGINS_NATIVE_DATABASES "/data/drm/plugins/native/databases"
 
 void DrmManagerService::instantiate() {
     LOGV("instantiate");
 
-    int res = mkdir("/data/drm/plugins", DRM_DIRECTORY_PERMISSION);

-    if (SUCCESS == res || EEXIST == errno) {

-        res = mkdir("/data/drm/plugins/native", DRM_DIRECTORY_PERMISSION);

-        if (SUCCESS == res || EEXIST == errno) {

-            res = mkdir("/data/drm/plugins/native/databases", DRM_DIRECTORY_PERMISSION);

-            if (SUCCESS == res || EEXIST == errno) {

-                defaultServiceManager()

-                    ->addService(String16("drm.drmManager"), new DrmManagerService());

-            }

-        }

+    int res = mkdir(DRM_PLUGINS_ROOT, DRM_DIRECTORY_PERMISSION);
+    if (SUCCESS == res || EEXIST == errno) {
+        res = mkdir(DRM_PLUGINS_NATIVE, DRM_DIRECTORY_PERMISSION);
+        if (SUCCESS == res || EEXIST == errno) {
+            res = mkdir(DRM_PLUGINS_NATIVE_DATABASES, DRM_DIRECTORY_PERMISSION);
+            if (SUCCESS == res || EEXIST == errno) {
+                defaultServiceManager()
+                    ->addService(String16("drm.drmManager"), new DrmManagerService());
+            }
+        }
     }
 }
 
@@ -57,6 +60,14 @@
     delete mDrmManager; mDrmManager = NULL;
 }
 
+int DrmManagerService::addUniqueId(int uniqueId) {
+    return mDrmManager->addUniqueId(uniqueId);
+}
+
+void DrmManagerService::removeUniqueId(int uniqueId) {
+    mDrmManager->removeUniqueId(uniqueId);
+}
+
 status_t DrmManagerService::loadPlugIns(int uniqueId) {
     LOGV("Entering load plugins");
     return mDrmManager->loadPlugIns(uniqueId);
@@ -105,7 +116,7 @@
     return mDrmManager->acquireDrmInfo(uniqueId, drmInfoRequest);
 }
 
-void DrmManagerService::saveRights(
+status_t DrmManagerService::saveRights(
             int uniqueId, const DrmRights& drmRights,
             const String8& rightsPath, const String8& contentPath) {
     LOGV("Entering saveRights");
@@ -129,16 +140,16 @@
     return mDrmManager->checkRightsStatus(uniqueId, path, action);
 }
 
-void DrmManagerService::consumeRights(
+status_t DrmManagerService::consumeRights(
             int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) {
     LOGV("Entering consumeRights");
-    mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve);
+    return mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve);
 }
 
-void DrmManagerService::setPlaybackStatus(
+status_t DrmManagerService::setPlaybackStatus(
             int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) {
     LOGV("Entering setPlaybackStatus");
-    mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position);
+    return mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position);
 }
 
 bool DrmManagerService::validateAction(
@@ -148,14 +159,14 @@
     return mDrmManager->validateAction(uniqueId, path, action, description);
 }
 
-void DrmManagerService::removeRights(int uniqueId, const String8& path) {
+status_t DrmManagerService::removeRights(int uniqueId, const String8& path) {
     LOGV("Entering removeRights");
-    mDrmManager->removeRights(uniqueId, path);
+    return mDrmManager->removeRights(uniqueId, path);
 }
 
-void DrmManagerService::removeAllRights(int uniqueId) {
+status_t DrmManagerService::removeAllRights(int uniqueId) {
     LOGV("Entering removeAllRights");
-    mDrmManager->removeAllRights(uniqueId);
+    return mDrmManager->removeAllRights(uniqueId);
 }
 
 int DrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) {
@@ -186,28 +197,28 @@
     return mDrmManager->openDecryptSession(uniqueId, fd, offset, length);
 }
 
-void DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
+status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
     LOGV("Entering closeDecryptSession");
-    mDrmManager->closeDecryptSession(uniqueId, decryptHandle);
+    return mDrmManager->closeDecryptSession(uniqueId, decryptHandle);
 }
 
-void DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
+status_t DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
             int decryptUnitId, const DrmBuffer* headerInfo) {
     LOGV("Entering initializeDecryptUnit");
-    mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo);
+    return mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo);
 }
 
 status_t DrmManagerService::decrypt(
-            int uniqueId, DecryptHandle* decryptHandle,
-            int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) {
+            int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
+            const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
     LOGV("Entering decrypt");
-    return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer);
+    return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV);
 }
 
-void DrmManagerService::finalizeDecryptUnit(
+status_t DrmManagerService::finalizeDecryptUnit(
             int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
     LOGV("Entering finalizeDecryptUnit");
-    mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
+    return mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
 }
 
 ssize_t DrmManagerService::pread(int uniqueId, DecryptHandle* decryptHandle,