diff options
author | Mark Wagner <mxw@google.com> | 2009-06-19 09:09:02 -0700 |
---|---|---|
committer | Mark Wagner <mxw@google.com> | 2009-06-22 14:55:17 -0700 |
commit | f4f8a7fe467c2f7514bf528d0a3e8926c2813c0f (patch) | |
tree | 6a17ae2ad8acd44f93594eb91a86c037a1a104a9 /core/java/com/google | |
parent | 82bc988eb3e9d4f2e0b7352b1cc9bff9f2bc4aa7 (diff) | |
download | frameworks_base-f4f8a7fe467c2f7514bf528d0a3e8926c2813c0f.zip frameworks_base-f4f8a7fe467c2f7514bf528d0a3e8926c2813c0f.tar.gz frameworks_base-f4f8a7fe467c2f7514bf528d0a3e8926c2813c0f.tar.bz2 |
mods so that we can search mms messages
Diffstat (limited to 'core/java/com/google')
-rw-r--r-- | core/java/com/google/android/mms/pdu/PduPersister.java | 101 |
1 files changed, 62 insertions, 39 deletions
diff --git a/core/java/com/google/android/mms/pdu/PduPersister.java b/core/java/com/google/android/mms/pdu/PduPersister.java index d2a41f1..74af765 100644 --- a/core/java/com/google/android/mms/pdu/PduPersister.java +++ b/core/java/com/google/android/mms/pdu/PduPersister.java @@ -31,6 +31,7 @@ import android.content.Context; import android.database.Cursor; import android.database.DatabaseUtils; import android.net.Uri; +import android.provider.Telephony; import android.provider.Telephony.Mms; import android.provider.Telephony.MmsSms; import android.provider.Telephony.Threads; @@ -54,6 +55,8 @@ import java.util.Map; import java.util.Set; import java.util.Map.Entry; +import com.google.android.mms.pdu.EncodedStringValue; + /** * This class is the high-level manager of PDU storage. */ @@ -159,6 +162,7 @@ public class PduPersister { Part.CONTENT_TYPE, Part.FILENAME, Part.NAME, + Part.TEXT }; private static final int PART_COLUMN_ID = 0; @@ -169,6 +173,7 @@ public class PduPersister { private static final int PART_COLUMN_CONTENT_TYPE = 5; private static final int PART_COLUMN_FILENAME = 6; private static final int PART_COLUMN_NAME = 7; + private static final int PART_COLUMN_TEXT = 8; private static final HashMap<Uri, Integer> MESSAGE_BOX_MAP; // These map are used for convenience in persist() and load(). @@ -414,26 +419,36 @@ public class PduPersister { ByteArrayOutputStream baos = new ByteArrayOutputStream(); InputStream is = null; - try { - is = mContentResolver.openInputStream(partURI); - - byte[] buffer = new byte[256]; - int len = is.read(buffer); - while (len >= 0) { - baos.write(buffer, 0, len); - len = is.read(buffer); - } - } catch (IOException e) { - Log.e(TAG, "Failed to load part data", e); - c.close(); - throw new MmsException(e); - } finally { - if (is != null) { - try { - is.close(); - } catch (IOException e) { - Log.e(TAG, "Failed to close stream", e); - } // Ignore + // Store simple string values directly in the database instead of an + // external file. This makes the text searchable and retrieval slightly + // faster. + if ("text/plain".equals(type) || "application/smil".equals(type)) { + String text = c.getString(PART_COLUMN_TEXT); + byte [] blob = new EncodedStringValue(text).getTextString(); + baos.write(blob, 0, blob.length); + } else { + + try { + is = mContentResolver.openInputStream(partURI); + + byte[] buffer = new byte[256]; + int len = is.read(buffer); + while (len >= 0) { + baos.write(buffer, 0, len); + len = is.read(buffer); + } + } catch (IOException e) { + Log.e(TAG, "Failed to load part data", e); + c.close(); + throw new MmsException(e); + } finally { + if (is != null) { + try { + is.close(); + } catch (IOException e) { + Log.e(TAG, "Failed to close stream", e); + } // Ignore + } } } part.setData(baos.toByteArray()); @@ -719,29 +734,37 @@ public class PduPersister { InputStream is = null; try { - os = mContentResolver.openOutputStream(uri); byte[] data = part.getData(); - if (data == null) { - Uri dataUri = part.getDataUri(); - if ((dataUri == null) || (dataUri == uri)) { - Log.w(TAG, "Can't find data for this part."); - return; - } - is = mContentResolver.openInputStream(dataUri); - - if (LOCAL_LOGV) { - Log.v(TAG, "Saving data to: " + uri); - } - - byte[] buffer = new byte[256]; - for (int len = 0; (len = is.read(buffer)) != -1; ) { - os.write(buffer, 0, len); + if ("text/plain".equals(contentType) || "application/smil".equals(contentType)) { + ContentValues cv = new ContentValues(); + cv.put(Telephony.Mms.Part.TEXT, new EncodedStringValue(data).getString()); + if (mContentResolver.update(uri, cv, null, null) != 1) { + throw new MmsException("unable to update " + uri.toString()); } } else { - if (LOCAL_LOGV) { - Log.v(TAG, "Saving data to: " + uri); + os = mContentResolver.openOutputStream(uri); + if (data == null) { + Uri dataUri = part.getDataUri(); + if ((dataUri == null) || (dataUri == uri)) { + Log.w(TAG, "Can't find data for this part."); + return; + } + is = mContentResolver.openInputStream(dataUri); + + if (LOCAL_LOGV) { + Log.v(TAG, "Saving data to: " + uri); + } + + byte[] buffer = new byte[256]; + for (int len = 0; (len = is.read(buffer)) != -1; ) { + os.write(buffer, 0, len); + } + } else { + if (LOCAL_LOGV) { + Log.v(TAG, "Saving data to: " + uri); + } + os.write(data); } - os.write(data); } } catch (FileNotFoundException e) { Log.e(TAG, "Failed to open Input/Output stream.", e); |