add content uri support for opening a file descriptor for storing a temp picture.

Change-Id: I6b765e16540b9a6c5c091d74336852ffee3968af
diff --git a/src/com/android/providers/telephony/MmsProvider.java b/src/com/android/providers/telephony/MmsProvider.java
index 9c3a446..74c69f1 100644
--- a/src/com/android/providers/telephony/MmsProvider.java
+++ b/src/com/android/providers/telephony/MmsProvider.java
@@ -180,7 +180,7 @@
                 qb.setTables("pdu group by thread_id");
                 break;
             default:
-                Log.e(TAG, "Invalid request: " + uri);
+                Log.e(TAG, "query: invalid request: " + uri);
                 return null;
         }
 
@@ -307,7 +307,7 @@
                 table = TABLE_DRM;
                 break;
             default:
-                Log.e(TAG, "Invalid request: " + uri);
+                Log.e(TAG, "insert: invalid request: " + uri);
                 return null;
         }
 
@@ -685,10 +685,53 @@
         return count;
     }
 
+    private ParcelFileDescriptor getTempStoreFd() {
+        String fileName = Mms.ScrapSpace.SCRAP_FILE_PATH;
+        ParcelFileDescriptor pfd = null;
+
+        try {
+            File file = new File(fileName);
+
+            // make sure the path is valid and directories created for this file.
+            File parentFile = file.getParentFile();
+            if (!parentFile.exists() && !parentFile.mkdirs()) {
+                Log.e(TAG, "[MmsProvider] getTempStoreFd: " + parentFile.getPath() +
+                        "does not exist!");
+                return null;
+            }
+
+            pfd = ParcelFileDescriptor.open(file,
+                    ParcelFileDescriptor.MODE_READ_WRITE
+                            | android.os.ParcelFileDescriptor.MODE_CREATE);
+        } catch (Exception ex) {
+            Log.e(TAG, "getTempStoreFd: error creating pfd for " + fileName, ex);
+        }
+
+        return pfd;
+    }
+
     @Override
-    public ParcelFileDescriptor openFile(Uri uri, String mode)
-            throws FileNotFoundException {
-        return openFileHelper(uri, mode);
+    public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
+        // if the url is "content://mms/takePictureTempStore", then it means the requester
+        // wants a file descriptor to write image data to.
+
+        ParcelFileDescriptor fd;
+        int match = sURLMatcher.match(uri);
+
+        if (Log.isLoggable(TAG, Log.VERBOSE)) {
+            Log.d(TAG, "openFile: uri=" + uri + ", mode=" + mode);
+        }
+
+        switch (match) {
+            case MMS_SCRAP_SPACE:
+                fd = getTempStoreFd();
+                break;
+
+            default:
+                fd = openFileHelper(uri, mode);
+        }
+
+        return fd;
     }
 
     private void filterUnsupportedKeys(ContentValues values) {
@@ -768,6 +811,7 @@
     private static final int MMS_DRM_STORAGE              = 17;
     private static final int MMS_DRM_STORAGE_ID           = 18;
     private static final int MMS_THREADS                  = 19;
+    private static final int MMS_SCRAP_SPACE              = 20;
 
     private static final UriMatcher
             sURLMatcher = new UriMatcher(UriMatcher.NO_MATCH);
@@ -793,6 +837,7 @@
         sURLMatcher.addURI("mms", "drm",        MMS_DRM_STORAGE);
         sURLMatcher.addURI("mms", "drm/#",      MMS_DRM_STORAGE_ID);
         sURLMatcher.addURI("mms", "threads",    MMS_THREADS);
+        sURLMatcher.addURI("mms", "scrapSpace", MMS_SCRAP_SPACE);
     }
 
     private SQLiteOpenHelper mOpenHelper;