Unable to playback the captured video in Messaging app, displays "Can't play this video"

Bug 9193742

The TempFileProvider's getTempStoreFd needs to respect the file mode.
Before this change, the file was always truncated when opened. When the
user tried to playback the freshly captured video in the video camera, the
video player would go through the provider to open the file to playback.
However, the file was truncated so nothing could be played back. With this
change, the file isn't truncated when opened for just reading.

Change-Id: Ifcfe8d586c345271186856c61d5f6e4fa32d130e
diff --git a/src/com/android/mms/TempFileProvider.java b/src/com/android/mms/TempFileProvider.java
index 4e73a6a..016c55d 100644
--- a/src/com/android/mms/TempFileProvider.java
+++ b/src/com/android/mms/TempFileProvider.java
@@ -60,7 +60,7 @@
         return 0;
     }
 
-    private ParcelFileDescriptor getTempStoreFd() {
+    private ParcelFileDescriptor getTempStoreFd(String mode) {
         String fileName = getScrapPath(getContext());
         ParcelFileDescriptor pfd = null;
 
@@ -75,10 +75,15 @@
                 return null;
             }
 
-            pfd = ParcelFileDescriptor.open(file,
-                    ParcelFileDescriptor.MODE_READ_WRITE
-                            | android.os.ParcelFileDescriptor.MODE_CREATE |
-                              ParcelFileDescriptor.MODE_TRUNCATE);
+            int modeFlags;
+            if (mode.equals("r")) {
+                modeFlags = ParcelFileDescriptor.MODE_READ_ONLY;
+            } else {
+                modeFlags = ParcelFileDescriptor.MODE_READ_WRITE
+                            | ParcelFileDescriptor.MODE_CREATE
+                            | ParcelFileDescriptor.MODE_TRUNCATE;
+            }
+            pfd = ParcelFileDescriptor.open(file, modeFlags);
         } catch (Exception ex) {
             Log.e(TAG, "getTempStoreFd: error creating pfd for " + fileName, ex);
         }
@@ -105,7 +110,7 @@
 
         switch (match) {
             case MMS_SCRAP_SPACE:
-                fd = getTempStoreFd();
+                fd = getTempStoreFd(mode);
                 break;
         }