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/common/ReadWriteUtils.cpp b/drm/common/ReadWriteUtils.cpp
index 4319c1c..7ec4fa2 100644
--- a/drm/common/ReadWriteUtils.cpp
+++ b/drm/common/ReadWriteUtils.cpp
@@ -14,6 +14,10 @@
  * limitations under the License.
  */
 
+//#define LOG_NDEBUG 0
+#define LOG_TAG "ReadWriteUtils"
+#include <utils/Log.h>
+
 #include <ReadWriteUtils.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
@@ -22,7 +26,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <utils/FileMap.h>
 #include <utils/String8.h>
 
 using namespace android;
@@ -39,18 +42,39 @@
         struct stat sb;
 
         if (fstat(fd, &sb) == 0 && sb.st_size > 0) {
-            FileMap* fileMap = new FileMap();
-            if (fileMap->create(filePath.string(), fd, 0, sb.st_size, true)) {
-                char* addr = (char*)fileMap->getDataPtr();
-                string.append(addr, sb.st_size);
-                fileMap->release();
+            int length = sb.st_size;
+            char* bytes = new char[length];
+            if (length == read(fd, (void*) bytes, length)) {
+                string.append(bytes, length);
             }
+            delete bytes;
         }
         fclose(file);
     }
     return string;
 }
 
+int ReadWriteUtils::readBytes(const String8& filePath, char** buffer) {
+    FILE* file = NULL;
+    file = fopen(filePath.string(), "r");
+    int length = 0;
+
+    if (NULL != file) {
+        int fd = fileno(file);
+        struct stat sb;
+
+        if (fstat(fd, &sb) == 0 && sb.st_size > 0) {
+            length = sb.st_size;
+            *buffer = new char[length];
+            if (length != read(fd, (void*) *buffer, length)) {
+                length = FAILURE;
+            }
+        }
+        fclose(file);
+    }
+    return length;
+}
+
 void ReadWriteUtils::writeToFile(const String8& filePath, const String8& data) {
     FILE* file = NULL;
     file = fopen(filePath.string(), "w+");
@@ -60,12 +84,8 @@
 
         int size = data.size();
         if (FAILURE != ftruncate(fd, size)) {
-            FileMap* fileMap = NULL;
-            fileMap = new FileMap();
-            if (fileMap->create(filePath.string(), fd, 0, size, false)) {
-                char* addr = (char*)fileMap->getDataPtr();
-                memcpy(addr, data.string(), size);
-                fileMap->release();
+            if (size != write(fd, data.string(), size)) {
+                LOGE("Failed to write the data to: %s", filePath.string());
             }
         }
         fclose(file);
@@ -79,20 +99,9 @@
     if (NULL != file) {
         int fd = fileno(file);
 
-        int offset = lseek(fd, 0, SEEK_END);
-        if (FAILURE != offset) {
-            int newEntrySize = data.size();
-            int fileSize = offset + newEntrySize;
-
-            if (FAILURE != ftruncate(fd, fileSize)) {
-                FileMap* fileMap = NULL;
-                fileMap = new FileMap();
-                if (fileMap->create(filePath.string(), fd, offset, fileSize, false)) {
-                    char* addr = (char*)fileMap->getDataPtr();
-                    memcpy(addr, data.string(), data.size());
-                    fileMap->release();
-                }
-            }
+        int size = data.size();
+        if (size != write(fd, data.string(), size)) {
+            LOGE("Failed to write the data to: %s", filePath.string());
         }
         fclose(file);
     }