Make mediascanner use filedescriptors instead of paths

Media scanner needs to open the files now, because media server doesn't
have the required permission.

b/6330061

Change-Id: I2364d93dcc0530c15676664fc4a8c306351dde08
diff --git a/media/libstagefright/StagefrightMediaScanner.cpp b/media/libstagefright/StagefrightMediaScanner.cpp
index 711a8cd..b7cf96e 100644
--- a/media/libstagefright/StagefrightMediaScanner.cpp
+++ b/media/libstagefright/StagefrightMediaScanner.cpp
@@ -18,6 +18,10 @@
 #define LOG_TAG "StagefrightMediaScanner"
 #include <utils/Log.h>
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
 #include <media/stagefright/StagefrightMediaScanner.h>
 
 #include <media/mediametadataretriever.h>
@@ -139,7 +143,16 @@
 
     sp<MediaMetadataRetriever> mRetriever(new MediaMetadataRetriever);
 
-    status_t status = mRetriever->setDataSource(path);
+    int fd = open(path, O_RDONLY | O_LARGEFILE);
+    status_t status;
+    if (fd < 0) {
+        // couldn't open it locally, maybe the media server can?
+        status = mRetriever->setDataSource(path);
+    } else {
+        status = mRetriever->setDataSource(fd, 0, 0x7ffffffffffffffL);
+        close(fd);
+    }
+
     if (status) {
         return MEDIA_SCAN_RESULT_ERROR;
     }