Major storage layer refactoring to set the stage for clean GCM.

1) We now try to hand out cursors at a minimum.  There has always been
   a fairly clean insertion layer that handles encrypting message bodies,
   but the process of decrypting message bodies has always been less than
   ideal.  Here we introduce a "Reader" interface that will decrypt message
   bodies when appropriate and return objects that encapsulate record state.

   No more MessageDisplayHelper.  The MmsSmsDatabase interface is also more
   sane.

2) We finally rid ourselves of the technical debt associated with TextSecure's
   initial usage of the default SMS DB.  In that world, we weren't able to use
   anything other than the default "Inbox, Outbox, Sent" types to describe a
   message, and had to overload the message content itself with a set of
   local "prefixes" to describe what it was (encrypted, asymetric encrypted,
   remote encrypted, a key exchange, procssed key exchange), and so on.

   This includes a major schema update that transforms the "type" field into
   a bitmask that describes everything that used to be encoded in a prefix,
   and prefixes have been completely eliminated from the system.

   No more Prefix.java

3) Refactoring of the MultipartMessageHandler code.  It's less of a mess, and
   hopefully more clear as to what's going on.

The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
This commit is contained in:
Moxie Marlinspike
2013-04-20 12:22:04 -07:00
parent 303d1acd45
commit 83e260436b
60 changed files with 2673 additions and 1760 deletions

View File

@@ -16,16 +16,15 @@
*/
package org.thoughtcrime.securesms.mms;
import android.content.Context;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import java.io.UnsupportedEncodingException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import android.content.Context;
import android.util.Log;
import ws.com.google.android.mms.ContentType;
import ws.com.google.android.mms.pdu.CharacterSets;
import ws.com.google.android.mms.pdu.PduBody;
@@ -33,25 +32,25 @@ import ws.com.google.android.mms.pdu.PduBody;
public class SlideDeck {
private final List<Slide> slides = new LinkedList<Slide>();
public SlideDeck(Context context, MasterSecret masterSecret, PduBody body) {
try {
for (int i=0;i<body.getPartsNum();i++) {
String contentType = new String(body.getPart(i).getContentType(), CharacterSets.MIMENAME_ISO_8859_1);
if (ContentType.isImageType(contentType))
slides.add(new ImageSlide(context, masterSecret, body.getPart(i)));
else if (ContentType.isVideoType(contentType))
slides.add(new VideoSlide(context, body.getPart(i)));
else if (ContentType.isAudioType(contentType))
slides.add(new AudioSlide(context, body.getPart(i)));
else if (ContentType.isTextType(contentType))
slides.add(new TextSlide(context, masterSecret, body.getPart(i)));
String contentType = new String(body.getPart(i).getContentType(), CharacterSets.MIMENAME_ISO_8859_1);
if (ContentType.isImageType(contentType))
slides.add(new ImageSlide(context, masterSecret, body.getPart(i)));
else if (ContentType.isVideoType(contentType))
slides.add(new VideoSlide(context, body.getPart(i)));
else if (ContentType.isAudioType(contentType))
slides.add(new AudioSlide(context, body.getPart(i)));
else if (ContentType.isTextType(contentType))
slides.add(new TextSlide(context, masterSecret, body.getPart(i)));
}
} catch (UnsupportedEncodingException uee) {
throw new AssertionError(uee);
}
}
public SlideDeck() {
}
@@ -61,10 +60,10 @@ public class SlideDeck {
public PduBody toPduBody() {
PduBody body = new PduBody();
Iterator<Slide> iterator = slides.iterator();
while (iterator.hasNext())
body.addPart(iterator.next().getPart());
for (Slide slide : slides) {
body.addPart(slide.getPart());
}
return body;
}