--- /dev/null
+package org.openintents.safe;\r
+\r
+import java.io.File;\r
+import java.io.FileNotFoundException;\r
+\r
+import android.content.ContentProvider;\r
+import android.content.ContentValues;\r
+import android.database.Cursor;\r
+import android.database.MatrixCursor;\r
+import android.net.Uri;\r
+import android.os.ParcelFileDescriptor;\r
+import android.provider.MediaStore.Images;\r
+\r
+public class CryptoContentProvider extends ContentProvider {\r
+\r
+ private static final String MIME_TYPE_PREFIX = "content://org.openintents.safe/decrypted/";\r
+ private static final String TAG = "CryptoContentProvider";\r
+ public static final String AUTHORITY = "org.openintents.safe";\r
+\r
+ @Override\r
+ public boolean onCreate() {\r
+ return true;\r
+ }\r
+\r
+ @Override\r
+ public int delete(Uri uri, String s, String[] as) {\r
+ // not supported\r
+ return 0;\r
+ }\r
+\r
+ @Override\r
+ public String getType(Uri uri) {\r
+ // return file extension (uri.lastIndexOf("."))\r
+ return null; //mMimeTypes.getMimeType(uri.toString());\r
+ }\r
+\r
+ @Override\r
+ public Uri insert(Uri uri, ContentValues contentvalues) {\r
+ // not supported\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public Cursor query(Uri uri, String[] as, String s, String[] as1, String s1) {\r
+ /*\r
+ if (uri.toString().startsWith(\r
+ MIME_TYPE_PREFIX)) {\r
+ MatrixCursor c = new MatrixCursor(new String[] { Images.Media.DATA,\r
+ Images.Media.MIME_TYPE });\r
+ // data = absolute path = uri - content://authority/mimetype\r
+ String data = uri.toString().substring(20 + AUTHORITY.length());\r
+ String mimeType = mMimeTypes.getMimeType(data);\r
+ c.addRow(new String[] { data, mimeType });\r
+ return c;\r
+ } else {\r
+ throw new RuntimeException("Unsupported uri");\r
+ }\r
+ */\r
+ return null;\r
+ }\r
+ \r
+ @Override\r
+ public ParcelFileDescriptor openFile(Uri uri, String mode)\r
+ throws FileNotFoundException {\r
+ if (uri.toString().startsWith(\r
+ MIME_TYPE_PREFIX)) {\r
+ int m = ParcelFileDescriptor.MODE_READ_ONLY;\r
+ if (mode.equalsIgnoreCase("rw"))\r
+ m = ParcelFileDescriptor.MODE_READ_WRITE;\r
+ \r
+ File f = new File(uri.toString().substring(20 + AUTHORITY.length()));\r
+ ParcelFileDescriptor pfd = ParcelFileDescriptor.open(f, m);\r
+ return pfd;\r
+ } else {\r
+ throw new RuntimeException("Unsupported uri");\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public int update(Uri uri, ContentValues contentvalues, String s,\r
+ String[] as) {\r
+ // not supported\r
+ return 0;\r
+ }\r
+\r
+}\r