Make 'push' status a type bit on both incoming and outgoing msgs.

This commit is contained in:
Moxie Marlinspike 2014-02-20 23:00:38 -08:00
parent 2026330f8a
commit ccd1691b22
12 changed files with 55 additions and 49 deletions

View File

@ -136,10 +136,15 @@ public class ConversationFragment extends SherlockListFragment
private void handleDisplayDetails(MessageRecord message) { private void handleDisplayDetails(MessageRecord message) {
String sender = message.getIndividualRecipient().getNumber(); String sender = message.getIndividualRecipient().getNumber();
String transport = message.isMms() ? "mms" : "sms";
long dateReceived = message.getDateReceived(); long dateReceived = message.getDateReceived();
long dateSent = message.getDateSent(); long dateSent = message.getDateSent();
String transport;
if (message.isPush()) transport = "push";
else if (message.isMms()) transport = "mms";
else transport = "sms";
SimpleDateFormat dateFormatter = new SimpleDateFormat("EEE MMM d, yyyy 'at' hh:mm:ss a zzz"); SimpleDateFormat dateFormatter = new SimpleDateFormat("EEE MMM d, yyyy 'at' hh:mm:ss a zzz");
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

View File

@ -175,7 +175,7 @@ public class ConversationItem extends LinearLayout {
private void setBodyText(MessageRecord messageRecord) { private void setBodyText(MessageRecord messageRecord) {
// TODO jake is going to fix this up // TODO jake is going to fix this up
if (messageRecord.isPushSent()) { if (messageRecord.isPush() && messageRecord.isOutgoing()) {
bodyText.setText("PUSH " + messageRecord.getDisplayBody()); bodyText.setText("PUSH " + messageRecord.getDisplayBody());
return; return;
} }

View File

@ -308,6 +308,10 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
updateMailboxBitmask(messageId, 0, Types.SECURE_MESSAGE_BIT); updateMailboxBitmask(messageId, 0, Types.SECURE_MESSAGE_BIT);
} }
public void markAsPush(long messageId) {
updateMailboxBitmask(messageId, 0, Types.PUSH_MESSAGE_BIT);
}
public void markAsDecryptFailed(long messageId, long threadId) { public void markAsDecryptFailed(long messageId, long threadId) {
updateMailboxBitmask(messageId, Types.ENCRYPTION_MASK, Types.ENCRYPTION_REMOTE_FAILED_BIT); updateMailboxBitmask(messageId, Types.ENCRYPTION_MASK, Types.ENCRYPTION_REMOTE_FAILED_BIT);
notifyConversationListeners(threadId); notifyConversationListeners(threadId);
@ -448,7 +452,8 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
throws MmsException throws MmsException
{ {
return insertMessageInbox(masterSecret, retrieved, contentLocation, threadId, return insertMessageInbox(masterSecret, retrieved, contentLocation, threadId,
Types.BASE_INBOX_TYPE | Types.ENCRYPTION_SYMMETRIC_BIT); Types.BASE_INBOX_TYPE | Types.ENCRYPTION_SYMMETRIC_BIT |
(retrieved.isPushMessage() ? Types.PUSH_MESSAGE_BIT : 0));
} }
public Pair<Long, Long> insertSecureMessageInbox(MasterSecret masterSecret, public Pair<Long, Long> insertSecureMessageInbox(MasterSecret masterSecret,
@ -457,7 +462,8 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
throws MmsException throws MmsException
{ {
return insertMessageInbox(masterSecret, retrieved, contentLocation, threadId, return insertMessageInbox(masterSecret, retrieved, contentLocation, threadId,
Types.BASE_INBOX_TYPE | Types.SECURE_MESSAGE_BIT | Types.ENCRYPTION_REMOTE_BIT); Types.BASE_INBOX_TYPE | Types.SECURE_MESSAGE_BIT |
Types.ENCRYPTION_REMOTE_BIT);
} }
public Pair<Long, Long> insertSecureDecryptedMessageInbox(MasterSecret masterSecret, public Pair<Long, Long> insertSecureDecryptedMessageInbox(MasterSecret masterSecret,
@ -466,7 +472,9 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
throws MmsException throws MmsException
{ {
return insertMessageInbox(masterSecret, retrieved, "", threadId, return insertMessageInbox(masterSecret, retrieved, "", threadId,
Types.BASE_INBOX_TYPE | Types.SECURE_MESSAGE_BIT | Types.ENCRYPTION_SYMMETRIC_BIT); Types.BASE_INBOX_TYPE | Types.SECURE_MESSAGE_BIT |
Types.ENCRYPTION_SYMMETRIC_BIT |
(retrieved.isPushMessage() ? Types.PUSH_MESSAGE_BIT : 0));
} }
public Pair<Long, Long> insertMessageInbox(NotificationInd notification) { public Pair<Long, Long> insertMessageInbox(NotificationInd notification) {
@ -870,7 +878,6 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.THREAD_ID)); long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.THREAD_ID));
String address = cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.ADDRESS)); String address = cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.ADDRESS));
int addressDeviceId = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.ADDRESS_DEVICE_ID)); int addressDeviceId = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.ADDRESS_DEVICE_ID));
int status = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.STATUS));
DisplayRecord.Body body = getBody(cursor); DisplayRecord.Body body = getBody(cursor);
int partCount = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.PART_COUNT)); int partCount = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.PART_COUNT));
Recipients recipients = getRecipientsFor(address); Recipients recipients = getRecipientsFor(address);
@ -879,7 +886,7 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
return new MediaMmsMessageRecord(context, id, recipients, recipients.getPrimaryRecipient(), return new MediaMmsMessageRecord(context, id, recipients, recipients.getPrimaryRecipient(),
addressDeviceId, dateSent, dateReceived, threadId, body, addressDeviceId, dateSent, dateReceived, threadId, body,
slideDeck, partCount, status, box); slideDeck, partCount, box);
} }
private Recipients getRecipientsFor(String address) { private Recipients getRecipientsFor(String address) {

View File

@ -38,6 +38,7 @@ public interface MmsSmsColumns {
// Secure Message Information // Secure Message Information
protected static final long SECURE_MESSAGE_BIT = 0x800000; protected static final long SECURE_MESSAGE_BIT = 0x800000;
protected static final long END_SESSION_BIT = 0x400000; protected static final long END_SESSION_BIT = 0x400000;
protected static final long PUSH_MESSAGE_BIT = 0x200000;
// Group Message Information // Group Message Information
protected static final long GROUP_ADD_MEMBERS_BIT = 0x10000; protected static final long GROUP_ADD_MEMBERS_BIT = 0x10000;
@ -79,6 +80,10 @@ public interface MmsSmsColumns {
return (type & SECURE_MESSAGE_BIT) != 0; return (type & SECURE_MESSAGE_BIT) != 0;
} }
public static boolean isPushType(long type) {
return (type & PUSH_MESSAGE_BIT) != 0;
}
public static boolean isEndSessionType(long type) { public static boolean isEndSessionType(long type) {
return (type & END_SESSION_BIT) != 0; return (type & END_SESSION_BIT) != 0;
} }

View File

@ -174,6 +174,10 @@ public class SmsDatabase extends Database implements MmsSmsColumns {
updateTypeBitmask(id, 0, Types.SECURE_MESSAGE_BIT); updateTypeBitmask(id, 0, Types.SECURE_MESSAGE_BIT);
} }
public void markAsPush(long id) {
updateTypeBitmask(id, 0, Types.PUSH_MESSAGE_BIT);
}
public void markAsDecryptFailed(long id) { public void markAsDecryptFailed(long id) {
updateTypeBitmask(id, Types.ENCRYPTION_MASK, Types.ENCRYPTION_REMOTE_FAILED_BIT); updateTypeBitmask(id, Types.ENCRYPTION_MASK, Types.ENCRYPTION_REMOTE_FAILED_BIT);
} }
@ -267,6 +271,8 @@ public class SmsDatabase extends Database implements MmsSmsColumns {
type |= Types.ENCRYPTION_REMOTE_BIT; type |= Types.ENCRYPTION_REMOTE_BIT;
} }
if (message.isPush()) type |= Types.PUSH_MESSAGE_BIT;
Recipients recipients; Recipients recipients;
try { try {
@ -470,7 +476,6 @@ public class SmsDatabase extends Database implements MmsSmsColumns {
public static final int STATUS_COMPLETE = 0; public static final int STATUS_COMPLETE = 0;
public static final int STATUS_PENDING = 0x20; public static final int STATUS_PENDING = 0x20;
public static final int STATUS_FAILED = 0x40; public static final int STATUS_FAILED = 0x40;
public static final int STATUS_SENT_PUSH = 0x8000;
} }
public Reader readerFor(Cursor cursor) { public Reader readerFor(Cursor cursor) {

View File

@ -45,10 +45,10 @@ public class MediaMmsMessageRecord extends MessageRecord {
Recipient individualRecipient, int recipientDeviceId, Recipient individualRecipient, int recipientDeviceId,
long dateSent, long dateReceived, long threadId, Body body, long dateSent, long dateReceived, long threadId, Body body,
ListenableFutureTask<SlideDeck> slideDeck, ListenableFutureTask<SlideDeck> slideDeck,
int partCount, int deliveryStatus, long mailbox) int partCount, long mailbox)
{ {
super(context, id, body, recipients, individualRecipient, recipientDeviceId, super(context, id, body, recipients, individualRecipient, recipientDeviceId,
dateSent, dateReceived, threadId, getGenericDeliveryStatus(deliveryStatus), mailbox); dateSent, dateReceived, threadId, DELIVERY_STATUS_NONE, mailbox);
this.context = context.getApplicationContext(); this.context = context.getApplicationContext();
this.partCount = partCount; this.partCount = partCount;
@ -82,8 +82,4 @@ public class MediaMmsMessageRecord extends MessageRecord {
return super.getDisplayBody(); return super.getDisplayBody();
} }
private static int getGenericDeliveryStatus(int status) {
return status == SmsDatabase.Status.STATUS_SENT_PUSH ? DELVIERY_STATUS_PUSH : DELIVERY_STATUS_NONE;
}
} }

View File

@ -44,7 +44,6 @@ public abstract class MessageRecord extends DisplayRecord {
public static final int DELIVERY_STATUS_RECEIVED = 1; public static final int DELIVERY_STATUS_RECEIVED = 1;
public static final int DELIVERY_STATUS_PENDING = 2; public static final int DELIVERY_STATUS_PENDING = 2;
public static final int DELIVERY_STATUS_FAILED = 3; public static final int DELIVERY_STATUS_FAILED = 3;
public static final int DELVIERY_STATUS_PUSH = 4;
private final Recipient individualRecipient; private final Recipient individualRecipient;
private final int recipientDeviceId; private final int recipientDeviceId;
@ -108,8 +107,8 @@ public abstract class MessageRecord extends DisplayRecord {
return getDeliveryStatus() == DELIVERY_STATUS_RECEIVED; return getDeliveryStatus() == DELIVERY_STATUS_RECEIVED;
} }
public boolean isPushSent() { public boolean isPush() {
return getDeliveryStatus() == DELVIERY_STATUS_PUSH; return SmsDatabase.Types.isPushType(type);
} }
public boolean isStaleKeyExchange() { public boolean isStaleKeyExchange() {

View File

@ -97,8 +97,6 @@ public class SmsMessageRecord extends MessageRecord {
private static int getGenericDeliveryStatus(int status) { private static int getGenericDeliveryStatus(int status) {
if (status == SmsDatabase.Status.STATUS_NONE) { if (status == SmsDatabase.Status.STATUS_NONE) {
return MessageRecord.DELIVERY_STATUS_NONE; return MessageRecord.DELIVERY_STATUS_NONE;
} else if (status >= SmsDatabase.Status.STATUS_SENT_PUSH) {
return MessageRecord.DELVIERY_STATUS_PUSH;
} else if (status >= SmsDatabase.Status.STATUS_FAILED) { } else if (status >= SmsDatabase.Status.STATUS_FAILED) {
return MessageRecord.DELIVERY_STATUS_FAILED; return MessageRecord.DELIVERY_STATUS_FAILED;
} else if (status >= SmsDatabase.Status.STATUS_PENDING) { } else if (status >= SmsDatabase.Status.STATUS_PENDING) {

View File

@ -20,11 +20,13 @@ public class IncomingMediaMessage {
private final PduHeaders headers; private final PduHeaders headers;
private final PduBody body; private final PduBody body;
private final String groupId; private final String groupId;
private final boolean push;
public IncomingMediaMessage(RetrieveConf retreived) { public IncomingMediaMessage(RetrieveConf retreived) {
this.headers = retreived.getPduHeaders(); this.headers = retreived.getPduHeaders();
this.body = retreived.getBody(); this.body = retreived.getBody();
this.groupId = null; this.groupId = null;
this.push = false;
} }
public IncomingMediaMessage(MasterSecret masterSecret, String localNumber, public IncomingMediaMessage(MasterSecret masterSecret, String localNumber,
@ -33,6 +35,7 @@ public class IncomingMediaMessage {
{ {
this.headers = new PduHeaders(); this.headers = new PduHeaders();
this.body = new PduBody(); this.body = new PduBody();
this.push = true;
if (messageContent.hasGroup()) { if (messageContent.hasGroup()) {
this.groupId = GroupUtil.getEncodedId(messageContent.getGroup().getId().toByteArray()); this.groupId = GroupUtil.getEncodedId(messageContent.getGroup().getId().toByteArray());
@ -84,6 +87,10 @@ public class IncomingMediaMessage {
return groupId; return groupId;
} }
public boolean isPushMessage() {
return push;
}
public boolean isGroupMessage() { public boolean isGroupMessage() {
return groupId != null || return groupId != null ||
!Util.isEmpty(headers.getEncodedStringValues(PduHeaders.CC)) || !Util.isEmpty(headers.getEncodedStringValues(PduHeaders.CC)) ||

View File

@ -79,8 +79,7 @@ public class MmsSender {
MmsSendResult result = transport.deliver(message, threadId); MmsSendResult result = transport.deliver(message, threadId);
if (result.isUpgradedSecure()) database.markAsSecure(message.getDatabaseMessageId()); if (result.isUpgradedSecure()) database.markAsSecure(message.getDatabaseMessageId());
if (result.isPush()) database.markDeliveryStatus(message.getDatabaseMessageId(), if (result.isPush()) database.markAsPush(message.getDatabaseMessageId());
Status.STATUS_SENT_PUSH);
database.markAsSent(message.getDatabaseMessageId(), result.getMessageId(), database.markAsSent(message.getDatabaseMessageId(), result.getMessageId(),
result.getResponseStatus()); result.getResponseStatus());

View File

@ -121,7 +121,7 @@ public class SmsSender {
database.markAsSent(messageId); database.markAsSent(messageId);
if (upgraded) database.markAsSecure(messageId); if (upgraded) database.markAsSecure(messageId);
if (push) database.markStatus(messageId, SmsDatabase.Status.STATUS_SENT_PUSH); if (push) database.markAsPush(messageId);
SmsMessageRecord record = reader.getNext(); SmsMessageRecord record = reader.getNext();

View File

@ -4,15 +4,12 @@ import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.telephony.SmsMessage; import android.telephony.SmsMessage;
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
import org.thoughtcrime.securesms.util.GroupUtil; import org.thoughtcrime.securesms.util.GroupUtil;
import org.whispersystems.textsecure.push.IncomingPushMessage; import org.whispersystems.textsecure.push.IncomingPushMessage;
import org.whispersystems.textsecure.storage.RecipientDevice; import org.whispersystems.textsecure.storage.RecipientDevice;
import java.util.List; import java.util.List;
import ws.com.google.android.mms.pdu.SendReq;
import static org.whispersystems.textsecure.push.PushMessageProtos.PushMessageContent.GroupContext; import static org.whispersystems.textsecure.push.PushMessageProtos.PushMessageContent.GroupContext;
public class IncomingTextMessage implements Parcelable { public class IncomingTextMessage implements Parcelable {
@ -38,6 +35,7 @@ public class IncomingTextMessage implements Parcelable {
private final String pseudoSubject; private final String pseudoSubject;
private final long sentTimestampMillis; private final long sentTimestampMillis;
private final String groupId; private final String groupId;
private final boolean push;
public IncomingTextMessage(SmsMessage message) { public IncomingTextMessage(SmsMessage message) {
this.message = message.getDisplayMessageBody(); this.message = message.getDisplayMessageBody();
@ -49,6 +47,7 @@ public class IncomingTextMessage implements Parcelable {
this.pseudoSubject = message.getPseudoSubject(); this.pseudoSubject = message.getPseudoSubject();
this.sentTimestampMillis = message.getTimestampMillis(); this.sentTimestampMillis = message.getTimestampMillis();
this.groupId = null; this.groupId = null;
this.push = false;
} }
public IncomingTextMessage(IncomingPushMessage message, String encodedBody, GroupContext group) { public IncomingTextMessage(IncomingPushMessage message, String encodedBody, GroupContext group) {
@ -60,6 +59,7 @@ public class IncomingTextMessage implements Parcelable {
this.replyPathPresent = true; this.replyPathPresent = true;
this.pseudoSubject = ""; this.pseudoSubject = "";
this.sentTimestampMillis = message.getTimestampMillis(); this.sentTimestampMillis = message.getTimestampMillis();
this.push = true;
if (group != null && group.hasId()) { if (group != null && group.hasId()) {
this.groupId = GroupUtil.getEncodedId(group.getId().toByteArray()); this.groupId = GroupUtil.getEncodedId(group.getId().toByteArray());
@ -78,6 +78,7 @@ public class IncomingTextMessage implements Parcelable {
this.pseudoSubject = in.readString(); this.pseudoSubject = in.readString();
this.sentTimestampMillis = in.readLong(); this.sentTimestampMillis = in.readLong();
this.groupId = in.readString(); this.groupId = in.readString();
this.push = (in.readInt() == 1);
} }
public IncomingTextMessage(IncomingTextMessage base, String newBody) { public IncomingTextMessage(IncomingTextMessage base, String newBody) {
@ -90,6 +91,7 @@ public class IncomingTextMessage implements Parcelable {
this.pseudoSubject = base.getPseudoSubject(); this.pseudoSubject = base.getPseudoSubject();
this.sentTimestampMillis = base.getSentTimestampMillis(); this.sentTimestampMillis = base.getSentTimestampMillis();
this.groupId = base.getGroupId(); this.groupId = base.getGroupId();
this.push = base.isPush();
} }
public IncomingTextMessage(List<IncomingTextMessage> fragments) { public IncomingTextMessage(List<IncomingTextMessage> fragments) {
@ -108,30 +110,7 @@ public class IncomingTextMessage implements Parcelable {
this.pseudoSubject = fragments.get(0).getPseudoSubject(); this.pseudoSubject = fragments.get(0).getPseudoSubject();
this.sentTimestampMillis = fragments.get(0).getSentTimestampMillis(); this.sentTimestampMillis = fragments.get(0).getSentTimestampMillis();
this.groupId = fragments.get(0).getGroupId(); this.groupId = fragments.get(0).getGroupId();
} this.push = fragments.get(0).isPush();
public IncomingTextMessage(SendReq record) {
this.message = "";
this.sender = record.getTo()[0].getString();
this.senderDeviceId = RecipientDevice.DEFAULT_DEVICE_ID;
this.protocol = 31338;
this.serviceCenterAddress = "Outgoing";
this.replyPathPresent = true;
this.pseudoSubject = "";
this.sentTimestampMillis = System.currentTimeMillis();
this.groupId = null;
}
public IncomingTextMessage(SmsMessageRecord record) {
this.message = record.getBody().getBody();
this.sender = record.getIndividualRecipient().getNumber();
this.senderDeviceId = RecipientDevice.DEFAULT_DEVICE_ID;
this.protocol = 31338;
this.serviceCenterAddress = "Outgoing";
this.replyPathPresent = true;
this.pseudoSubject = "";
this.sentTimestampMillis = System.currentTimeMillis();
this.groupId = null;
} }
protected IncomingTextMessage(String sender, String groupId) protected IncomingTextMessage(String sender, String groupId)
@ -145,6 +124,7 @@ public class IncomingTextMessage implements Parcelable {
this.pseudoSubject = ""; this.pseudoSubject = "";
this.sentTimestampMillis = System.currentTimeMillis(); this.sentTimestampMillis = System.currentTimeMillis();
this.groupId = groupId; this.groupId = groupId;
this.push = true;
} }
public long getSentTimestampMillis() { public long getSentTimestampMillis() {
@ -203,6 +183,10 @@ public class IncomingTextMessage implements Parcelable {
return false; return false;
} }
public boolean isPush() {
return push;
}
public String getGroupId() { public String getGroupId() {
return groupId; return groupId;
} }
@ -227,5 +211,6 @@ public class IncomingTextMessage implements Parcelable {
out.writeString(pseudoSubject); out.writeString(pseudoSubject);
out.writeLong(sentTimestampMillis); out.writeLong(sentTimestampMillis);
out.writeString(groupId); out.writeString(groupId);
out.writeInt(push ? 1 : 0);
} }
} }