use of org.whispersystems.signalservice.api.util.InvalidNumberException in project Signal-Android by WhisperSystems.
the class ContactsDatabase method getSignalRawContacts.
@NonNull
private Map<String, SignalContact> getSignalRawContacts(@NonNull Account account, @NonNull String localNumber) {
Uri currentContactsUri = RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name).appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type).build();
Map<String, SignalContact> signalContacts = new HashMap<>();
Cursor cursor = null;
try {
String[] projection;
if (Build.VERSION.SDK_INT >= 11) {
projection = new String[] { BaseColumns._ID, RawContacts.SYNC1, RawContacts.SYNC4, RawContacts.CONTACT_ID, RawContacts.DISPLAY_NAME_PRIMARY, RawContacts.DISPLAY_NAME_SOURCE };
} else {
projection = new String[] { BaseColumns._ID, RawContacts.SYNC1, RawContacts.SYNC4, RawContacts.CONTACT_ID };
}
cursor = context.getContentResolver().query(currentContactsUri, projection, null, null, null);
while (cursor != null && cursor.moveToNext()) {
String currentNumber;
try {
currentNumber = PhoneNumberFormatter.formatNumber(cursor.getString(1), localNumber);
} catch (InvalidNumberException e) {
Log.w(TAG, e);
currentNumber = cursor.getString(1);
}
long rawContactId = cursor.getLong(0);
long contactId = cursor.getLong(3);
String supportsVoice = cursor.getString(2);
String rawContactDisplayName = null;
String aggregateDisplayName = null;
int rawContactDisplayNameSource = 0;
if (Build.VERSION.SDK_INT >= 11) {
rawContactDisplayName = cursor.getString(4);
rawContactDisplayNameSource = cursor.getInt(5);
aggregateDisplayName = getDisplayName(contactId);
}
signalContacts.put(currentNumber, new SignalContact(rawContactId, supportsVoice, rawContactDisplayName, aggregateDisplayName, rawContactDisplayNameSource));
}
} finally {
if (cursor != null)
cursor.close();
}
return signalContacts;
}
use of org.whispersystems.signalservice.api.util.InvalidNumberException in project Signal-Android by WhisperSystems.
the class MmsDatabase method incrementDeliveryReceiptCount.
public void incrementDeliveryReceiptCount(SyncMessageId messageId) {
MmsAddressDatabase addressDatabase = DatabaseFactory.getMmsAddressDatabase(context);
SQLiteDatabase database = databaseHelper.getWritableDatabase();
Cursor cursor = null;
boolean found = false;
try {
cursor = database.query(TABLE_NAME, new String[] { ID, THREAD_ID, MESSAGE_BOX }, DATE_SENT + " = ?", new String[] { String.valueOf(messageId.getTimetamp()) }, null, null, null, null);
while (cursor.moveToNext()) {
if (Types.isOutgoingMessageType(cursor.getLong(cursor.getColumnIndexOrThrow(MESSAGE_BOX)))) {
List<String> addresses = addressDatabase.getAddressesListForId(cursor.getLong(cursor.getColumnIndexOrThrow(ID)));
for (String storedAddress : addresses) {
try {
String ourAddress = canonicalizeNumber(context, messageId.getAddress());
String theirAddress = canonicalizeNumberOrGroup(context, storedAddress);
if (ourAddress.equals(theirAddress) || GroupUtil.isEncodedGroup(theirAddress)) {
long id = cursor.getLong(cursor.getColumnIndexOrThrow(ID));
long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(THREAD_ID));
found = true;
database.execSQL("UPDATE " + TABLE_NAME + " SET " + RECEIPT_COUNT + " = " + RECEIPT_COUNT + " + 1 WHERE " + ID + " = ?", new String[] { String.valueOf(id) });
DatabaseFactory.getThreadDatabase(context).update(threadId, false);
notifyConversationListeners(threadId);
}
} catch (InvalidNumberException e) {
Log.w("MmsDatabase", e);
}
}
}
}
if (!found) {
try {
earlyReceiptCache.increment(messageId.getTimetamp(), canonicalizeNumber(context, messageId.getAddress()));
} catch (InvalidNumberException e) {
Log.w(TAG, e);
}
}
} finally {
if (cursor != null)
cursor.close();
}
}
use of org.whispersystems.signalservice.api.util.InvalidNumberException in project Signal-Android by WhisperSystems.
the class SmsDatabase method insertMessageOutbox.
protected long insertMessageOutbox(long threadId, OutgoingTextMessage message, long type, boolean forceSms, long date) {
if (message.isKeyExchange())
type |= Types.KEY_EXCHANGE_BIT;
else if (message.isSecureMessage())
type |= (Types.SECURE_MESSAGE_BIT | Types.PUSH_MESSAGE_BIT);
else if (message.isEndSession())
type |= Types.END_SESSION_BIT;
if (forceSms)
type |= Types.MESSAGE_FORCE_SMS_BIT;
String address = message.getRecipients().getPrimaryRecipient().getNumber();
ContentValues contentValues = new ContentValues(6);
contentValues.put(ADDRESS, PhoneNumberUtils.formatNumber(address));
contentValues.put(THREAD_ID, threadId);
contentValues.put(BODY, message.getMessageBody());
contentValues.put(DATE_RECEIVED, System.currentTimeMillis());
contentValues.put(DATE_SENT, date);
contentValues.put(READ, 1);
contentValues.put(TYPE, type);
contentValues.put(SUBSCRIPTION_ID, message.getSubscriptionId());
contentValues.put(EXPIRES_IN, message.getExpiresIn());
try {
contentValues.put(RECEIPT_COUNT, earlyReceiptCache.remove(date, canonicalizeNumber(context, address)));
} catch (InvalidNumberException e) {
Log.w(TAG, e);
}
SQLiteDatabase db = databaseHelper.getWritableDatabase();
long messageId = db.insert(TABLE_NAME, ADDRESS, contentValues);
DatabaseFactory.getThreadDatabase(context).update(threadId, true);
DatabaseFactory.getThreadDatabase(context).setLastSeen(threadId);
notifyConversationListeners(threadId);
jobManager.add(new TrimThreadJob(context, threadId));
return messageId;
}
use of org.whispersystems.signalservice.api.util.InvalidNumberException in project Signal-Android by WhisperSystems.
the class SmsDatabase method incrementDeliveryReceiptCount.
public void incrementDeliveryReceiptCount(SyncMessageId messageId) {
SQLiteDatabase database = databaseHelper.getWritableDatabase();
Cursor cursor = null;
boolean foundMessage = false;
try {
cursor = database.query(TABLE_NAME, new String[] { ID, THREAD_ID, ADDRESS, TYPE }, DATE_SENT + " = ?", new String[] { String.valueOf(messageId.getTimetamp()) }, null, null, null, null);
while (cursor.moveToNext()) {
if (Types.isOutgoingMessageType(cursor.getLong(cursor.getColumnIndexOrThrow(TYPE)))) {
try {
String theirAddress = canonicalizeNumber(context, messageId.getAddress());
String ourAddress = canonicalizeNumber(context, cursor.getString(cursor.getColumnIndexOrThrow(ADDRESS)));
if (ourAddress.equals(theirAddress)) {
long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(THREAD_ID));
database.execSQL("UPDATE " + TABLE_NAME + " SET " + RECEIPT_COUNT + " = " + RECEIPT_COUNT + " + 1 WHERE " + ID + " = ?", new String[] { String.valueOf(cursor.getLong(cursor.getColumnIndexOrThrow(ID))) });
DatabaseFactory.getThreadDatabase(context).update(threadId, false);
notifyConversationListeners(threadId);
foundMessage = true;
}
} catch (InvalidNumberException e) {
Log.w(TAG, e);
}
}
}
if (!foundMessage) {
try {
earlyReceiptCache.increment(messageId.getTimetamp(), canonicalizeNumber(context, messageId.getAddress()));
} catch (InvalidNumberException e) {
Log.w(TAG, e);
}
}
} finally {
if (cursor != null)
cursor.close();
}
}
use of org.whispersystems.signalservice.api.util.InvalidNumberException in project Signal-Android by WhisperSystems.
the class MultiDeviceBlockedUpdateJob method onRun.
@Override
public void onRun(MasterSecret masterSecret) throws IOException, UntrustedIdentityException {
RecipientPreferenceDatabase database = DatabaseFactory.getRecipientPreferenceDatabase(context);
SignalServiceMessageSender messageSender = messageSenderFactory.create();
BlockedReader reader = database.readerForBlocked(database.getBlocked());
List<String> blocked = new LinkedList<>();
Recipients recipients;
while ((recipients = reader.getNext()) != null) {
if (recipients.isSingleRecipient()) {
try {
blocked.add(Util.canonicalizeNumber(context, recipients.getPrimaryRecipient().getNumber()));
} catch (InvalidNumberException e) {
Log.w(TAG, e);
}
}
}
messageSender.sendMessage(SignalServiceSyncMessage.forBlocked(new BlockedListMessage(blocked)));
}
Aggregations