use of org.thoughtcrime.securesms.database.model.SmsMessageRecord in project Signal-Android by WhisperSystems.
the class EncryptingSmsDatabase method getMessage.
public SmsMessageRecord getMessage(MasterSecret masterSecret, long messageId) throws NoSuchMessageException {
Cursor cursor = super.getMessage(messageId);
DecryptingReader reader = new DecryptingReader(masterSecret, cursor);
SmsMessageRecord record = reader.getNext();
reader.close();
if (record == null)
throw new NoSuchMessageException("No message for ID: " + messageId);
else
return record;
}
use of org.thoughtcrime.securesms.database.model.SmsMessageRecord in project Signal-Android by WhisperSystems.
the class SmsSentJob method handleSentResult.
private void handleSentResult(MasterSecret masterSecret, long messageId, int result) {
try {
EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
SmsMessageRecord record = database.getMessage(masterSecret, messageId);
switch(result) {
case Activity.RESULT_OK:
database.markAsSent(messageId, false);
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
case SmsManager.RESULT_ERROR_RADIO_OFF:
Log.w(TAG, "Service connectivity problem, requeuing...");
ApplicationContext.getInstance(context).getJobManager().add(new SmsSendJob(context, messageId, record.getIndividualRecipient().getNumber()));
break;
default:
database.markAsSentFailed(messageId);
MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipients(), record.getThreadId());
}
} catch (NoSuchMessageException e) {
Log.w(TAG, e);
}
}
use of org.thoughtcrime.securesms.database.model.SmsMessageRecord in project Signal-Android by WhisperSystems.
the class MasterSecretDecryptJob method onRun.
@Override
public void onRun(MasterSecret masterSecret) {
EncryptingSmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context);
SmsDatabase.Reader smsReader = smsDatabase.getDecryptInProgressMessages(masterSecret);
SmsMessageRecord smsRecord;
while ((smsRecord = smsReader.getNext()) != null) {
try {
String body = getAsymmetricDecryptedBody(masterSecret, smsRecord.getBody().getBody());
smsDatabase.updateMessageBody(new MasterSecretUnion(masterSecret), smsRecord.getId(), body);
} catch (InvalidMessageException e) {
Log.w(TAG, e);
}
}
MmsDatabase mmsDatabase = DatabaseFactory.getMmsDatabase(context);
MmsDatabase.Reader mmsReader = mmsDatabase.getDecryptInProgressMessages(masterSecret);
MessageRecord mmsRecord;
while ((mmsRecord = mmsReader.getNext()) != null) {
try {
String body = getAsymmetricDecryptedBody(masterSecret, mmsRecord.getBody().getBody());
mmsDatabase.updateMessageBody(new MasterSecretUnion(masterSecret), mmsRecord.getId(), body);
} catch (InvalidMessageException e) {
Log.w(TAG, e);
}
}
smsReader.close();
mmsReader.close();
MessageNotifier.updateNotification(context, masterSecret);
}
use of org.thoughtcrime.securesms.database.model.SmsMessageRecord in project Signal-Android by signalapp.
the class SmsDatabase method copyMessageInbox.
public Pair<Long, Long> copyMessageInbox(long messageId) {
try {
SmsMessageRecord record = getMessage(messageId);
ContentValues contentValues = new ContentValues();
contentValues.put(TYPE, (record.getType() & ~Types.BASE_TYPE_MASK) | Types.BASE_INBOX_TYPE);
contentValues.put(ADDRESS, record.getIndividualRecipient().getAddress().serialize());
contentValues.put(ADDRESS_DEVICE_ID, record.getRecipientDeviceId());
contentValues.put(DATE_RECEIVED, System.currentTimeMillis());
contentValues.put(DATE_SENT, record.getDateSent());
contentValues.put(PROTOCOL, 31337);
contentValues.put(READ, 0);
contentValues.put(BODY, record.getBody());
contentValues.put(THREAD_ID, record.getThreadId());
contentValues.put(EXPIRES_IN, record.getExpiresIn());
SQLiteDatabase db = databaseHelper.getWritableDatabase();
long newMessageId = db.insert(TABLE_NAME, null, contentValues);
DatabaseFactory.getThreadDatabase(context).update(record.getThreadId(), true);
notifyConversationListeners(record.getThreadId());
jobManager.add(new TrimThreadJob(context, record.getThreadId()));
return new Pair<>(newMessageId, record.getThreadId());
} catch (NoSuchMessageException e) {
throw new AssertionError(e);
}
}
use of org.thoughtcrime.securesms.database.model.SmsMessageRecord in project Signal-Android by signalapp.
the class PushTextSendJob method onPushSend.
@Override
public void onPushSend() throws NoSuchMessageException, RetryLaterException {
ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
SmsMessageRecord record = database.getMessage(messageId);
try {
Log.w(TAG, "Sending message: " + messageId);
deliver(record);
database.markAsSent(messageId, true);
if (record.getExpiresIn() > 0) {
database.markExpireStarted(messageId);
expirationManager.scheduleDeletion(record.getId(), record.isMms(), record.getExpiresIn());
}
} catch (InsecureFallbackApprovalException e) {
Log.w(TAG, e);
database.markAsPendingInsecureSmsFallback(record.getId());
MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId());
ApplicationContext.getInstance(context).getJobManager().add(new DirectoryRefreshJob(context, false));
} catch (UntrustedIdentityException e) {
Log.w(TAG, e);
database.addMismatchedIdentity(record.getId(), Address.fromSerialized(e.getE164Number()), e.getIdentityKey());
database.markAsSentFailed(record.getId());
database.markAsPush(record.getId());
}
}
Aggregations