Change the way notifications work for non-default KitKat.

Messages that are not "secure" (encrypted or key exchange) are
automatically marked as read if TextSecure isn't the default
KitKat SMS app.

This change in functionality allows people who aren't using
TextSecure as a default SMS app on KitKat to still receive
notifications when they get incoming encrypted messages.
This commit is contained in:
Moxie Marlinspike 2013-12-07 11:00:20 -08:00
parent 99d295abc5
commit 7489f3463a
3 changed files with 21 additions and 16 deletions

View File

@ -358,8 +358,9 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
String contentLocation, long threadId, long mailbox)
throws MmsException
{
PduHeaders headers = retrieved.getPduHeaders();
PduHeaders headers = retrieved.getPduHeaders();
ContentValues contentValues = getContentValuesFromHeader(headers);
boolean unread = Util.isDefaultSmsProvider(context) || ((mailbox & Types.SECURE_MESSAGE_BIT) != 0);
if (!Util.isEmpty(retrieved.getCc())) {
try {
@ -374,13 +375,17 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
contentValues.put(CONTENT_LOCATION, contentLocation);
contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED);
contentValues.put(DATE_RECEIVED, System.currentTimeMillis() / 1000);
contentValues.put(READ, unread ? 0 : 1);
if (!contentValues.containsKey(DATE_SENT))
contentValues.put(DATE_SENT, contentValues.getAsLong(DATE_RECEIVED));
long messageId = insertMediaMessage(masterSecret, retrieved, contentValues);
DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
if (unread) {
DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
}
DatabaseFactory.getThreadDatabase(context).update(threadId);
notifyConversationListeners(threadId);
Trimmer.trimThread(context, threadId);
@ -427,6 +432,7 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
contentValues.put(THREAD_ID, threadId);
contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED);
contentValues.put(DATE_RECEIVED, System.currentTimeMillis() / 1000);
contentValues.put(READ, Util.isDefaultSmsProvider(context) ? 0 : 1);
if (!contentValues.containsKey(DATE_SENT))
contentValues.put(DATE_SENT, contentValues.getAsLong(DATE_RECEIVED));
@ -449,7 +455,11 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
public void markIncomingNotificationReceived(long threadId) {
notifyConversationListeners(threadId);
DatabaseFactory.getThreadDatabase(context).update(threadId);
DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
if (Util.isDefaultSmsProvider(context)) {
DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
}
Trimmer.trimThread(context, threadId);
}

View File

@ -242,16 +242,17 @@ public class SmsDatabase extends Database implements MmsSmsColumns {
type |= Types.ENCRYPTION_REMOTE_BIT;
}
Recipient recipient = new Recipient(null, message.getSender(), null, null);
Recipient recipient = new Recipient(null, message.getSender(), null, null);
Recipients recipients = new Recipients(recipient);
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
boolean unread = Util.isDefaultSmsProvider(context) || message.isSecureMessage() || message.isKeyExchange();
ContentValues values = new ContentValues(6);
values.put(ADDRESS, message.getSender());
values.put(DATE_RECEIVED, System.currentTimeMillis());
values.put(DATE_SENT, message.getSentTimestampMillis());
values.put(PROTOCOL, message.getProtocol());
values.put(READ, 0);
values.put(READ, unread ? 0 : 1);
if (!Util.isEmpty(message.getPseudoSubject()))
values.put(SUBJECT, message.getPseudoSubject());
@ -265,7 +266,10 @@ public class SmsDatabase extends Database implements MmsSmsColumns {
SQLiteDatabase db = databaseHelper.getWritableDatabase();
long messageId = db.insert(TABLE_NAME, null, values);
DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
if (unread) {
DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
}
DatabaseFactory.getThreadDatabase(context).update(threadId);
notifyConversationListeners(threadId);
Trimmer.trimThread(context, threadId);

View File

@ -48,7 +48,6 @@ import org.thoughtcrime.securesms.database.MmsSmsDatabase;
import org.thoughtcrime.securesms.database.model.MessageRecord;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.util.Util;
import java.io.IOException;
import java.util.List;
@ -104,10 +103,6 @@ public class MessageNotifier {
return;
}
if (!Util.isDefaultSmsProvider(context)) {
return;
}
updateNotification(context, masterSecret, false);
}
@ -118,10 +113,6 @@ public class MessageNotifier {
return;
}
if (!Util.isDefaultSmsProvider(context)) {
return;
}
if (visibleThread == threadId) {
DatabaseFactory.getThreadDatabase(context).setRead(threadId);
sendInThreadNotification(context);