2018-01-24 19:17:44 -08:00
|
|
|
/*
|
2011-12-20 10:20:44 -08:00
|
|
|
* Copyright (C) 2011 Whisper Systems
|
2012-09-30 19:56:29 -07:00
|
|
|
*
|
2011-12-20 10:20:44 -08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2012-09-30 19:56:29 -07:00
|
|
|
*
|
2011-12-20 10:20:44 -08:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms.database;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.database.Cursor;
|
2020-08-19 10:06:26 +10:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
2011-12-20 10:20:44 -08:00
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
import net.sqlcipher.database.SQLiteDatabase;
|
|
|
|
import net.sqlcipher.database.SQLiteQueryBuilder;
|
|
|
|
|
2016-02-19 17:07:41 -08:00
|
|
|
import org.thoughtcrime.securesms.database.MessagingDatabase.SyncMessageId;
|
2018-01-24 19:17:44 -08:00
|
|
|
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
2015-01-15 13:35:35 -08:00
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
2018-04-02 16:17:32 -07:00
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
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.
2013-04-20 12:22:04 -07:00
|
|
|
|
2012-09-30 19:56:29 -07:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
public class MmsSmsDatabase extends Database {
|
2012-09-30 19:56:29 -07:00
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
@SuppressWarnings("unused")
|
2015-10-21 15:32:19 -07:00
|
|
|
private static final String TAG = MmsSmsDatabase.class.getSimpleName();
|
|
|
|
|
2013-04-25 18:59:49 -07:00
|
|
|
public static final String TRANSPORT = "transport_type";
|
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.
2013-04-20 12:22:04 -07:00
|
|
|
public static final String MMS_TRANSPORT = "mms";
|
|
|
|
public static final String SMS_TRANSPORT = "sms";
|
2013-01-06 13:13:14 -08:00
|
|
|
|
2015-11-13 13:20:16 -08:00
|
|
|
private static final String[] PROJECTION = {MmsSmsColumns.ID, MmsSmsColumns.UNIQUE_ROW_ID,
|
|
|
|
SmsDatabase.BODY, SmsDatabase.TYPE,
|
2015-10-21 15:32:19 -07:00
|
|
|
MmsSmsColumns.THREAD_ID,
|
|
|
|
SmsDatabase.ADDRESS, SmsDatabase.ADDRESS_DEVICE_ID, SmsDatabase.SUBJECT,
|
|
|
|
MmsSmsColumns.NORMALIZED_DATE_SENT,
|
|
|
|
MmsSmsColumns.NORMALIZED_DATE_RECEIVED,
|
|
|
|
MmsDatabase.MESSAGE_TYPE, MmsDatabase.MESSAGE_BOX,
|
2018-05-22 02:13:10 -07:00
|
|
|
SmsDatabase.STATUS,
|
|
|
|
MmsSmsColumns.UNIDENTIFIED,
|
|
|
|
MmsDatabase.PART_COUNT,
|
2015-10-21 15:32:19 -07:00
|
|
|
MmsDatabase.CONTENT_LOCATION, MmsDatabase.TRANSACTION_ID,
|
|
|
|
MmsDatabase.MESSAGE_SIZE, MmsDatabase.EXPIRY,
|
2017-09-15 22:38:53 -07:00
|
|
|
MmsDatabase.STATUS,
|
|
|
|
MmsSmsColumns.DELIVERY_RECEIPT_COUNT,
|
|
|
|
MmsSmsColumns.READ_RECEIPT_COUNT,
|
2015-10-21 15:32:19 -07:00
|
|
|
MmsSmsColumns.MISMATCHED_IDENTITIES,
|
2016-02-05 16:10:33 -08:00
|
|
|
MmsDatabase.NETWORK_FAILURE,
|
2016-08-15 20:23:56 -07:00
|
|
|
MmsSmsColumns.SUBSCRIPTION_ID,
|
|
|
|
MmsSmsColumns.EXPIRES_IN,
|
2017-03-08 17:38:55 -08:00
|
|
|
MmsSmsColumns.EXPIRE_STARTED,
|
|
|
|
MmsSmsColumns.NOTIFIED,
|
|
|
|
TRANSPORT,
|
2018-02-07 14:01:37 -08:00
|
|
|
AttachmentDatabase.ATTACHMENT_JSON_ALIAS,
|
|
|
|
MmsDatabase.QUOTE_ID,
|
|
|
|
MmsDatabase.QUOTE_AUTHOR,
|
|
|
|
MmsDatabase.QUOTE_BODY,
|
2018-08-11 09:55:52 -04:00
|
|
|
MmsDatabase.QUOTE_MISSING,
|
2018-04-26 17:03:54 -07:00
|
|
|
MmsDatabase.QUOTE_ATTACHMENT,
|
2019-01-15 00:41:05 -08:00
|
|
|
MmsDatabase.SHARED_CONTACTS,
|
|
|
|
MmsDatabase.LINK_PREVIEWS};
|
2015-10-21 15:32:19 -07:00
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
public MmsSmsDatabase(Context context, SQLCipherOpenHelper databaseHelper) {
|
2011-12-20 10:20:44 -08:00
|
|
|
super(context, databaseHelper);
|
|
|
|
}
|
2012-09-30 19:56:29 -07:00
|
|
|
|
2018-04-24 11:09:54 -07:00
|
|
|
public @Nullable MessageRecord getMessageFor(long timestamp, Address author) {
|
|
|
|
MmsSmsDatabase db = DatabaseFactory.getMmsSmsDatabase(context);
|
|
|
|
|
|
|
|
try (Cursor cursor = queryTables(PROJECTION, MmsSmsColumns.NORMALIZED_DATE_SENT + " = " + timestamp, null, null)) {
|
|
|
|
MmsSmsDatabase.Reader reader = db.readerFor(cursor);
|
|
|
|
|
|
|
|
MessageRecord messageRecord;
|
|
|
|
|
|
|
|
while ((messageRecord = reader.getNext()) != null) {
|
|
|
|
if ((Util.isOwnNumber(context, author) && messageRecord.isOutgoing()) ||
|
|
|
|
(!Util.isOwnNumber(context, author) && messageRecord.getIndividualRecipient().getAddress().equals(author)))
|
|
|
|
{
|
|
|
|
return messageRecord;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2018-02-07 14:01:37 -08:00
|
|
|
}
|
|
|
|
|
2018-04-06 18:15:24 -07:00
|
|
|
public Cursor getConversation(long threadId, long offset, long limit) {
|
2015-10-21 15:32:19 -07:00
|
|
|
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " DESC";
|
2019-10-18 12:40:41 +11:00
|
|
|
String selection = MmsSmsColumns.THREAD_ID + " = " + threadId;
|
2018-04-06 18:15:24 -07:00
|
|
|
String limitStr = limit > 0 || offset > 0 ? offset + ", " + limit : null;
|
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.
2013-04-20 12:22:04 -07:00
|
|
|
|
2018-04-06 18:15:24 -07:00
|
|
|
Cursor cursor = queryTables(PROJECTION, selection, order, limitStr);
|
2015-01-15 13:35:35 -08:00
|
|
|
setNotifyConverationListeners(cursor, threadId);
|
|
|
|
|
|
|
|
return cursor;
|
|
|
|
}
|
|
|
|
|
2015-08-04 12:29:26 -07:00
|
|
|
public Cursor getConversation(long threadId) {
|
2018-04-06 18:15:24 -07:00
|
|
|
return getConversation(threadId, 0, 0);
|
2015-08-04 12:29:26 -07:00
|
|
|
}
|
|
|
|
|
2015-01-15 13:35:35 -08:00
|
|
|
public Cursor getIdentityConflictMessagesForThread(long threadId) {
|
|
|
|
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " ASC";
|
|
|
|
String selection = MmsSmsColumns.THREAD_ID + " = " + threadId + " AND " + MmsSmsColumns.MISMATCHED_IDENTITIES + " IS NOT NULL";
|
|
|
|
|
2015-10-21 15:32:19 -07:00
|
|
|
Cursor cursor = queryTables(PROJECTION, selection, order, null);
|
2011-12-20 10:20:44 -08:00
|
|
|
setNotifyConverationListeners(cursor, threadId);
|
|
|
|
|
|
|
|
return cursor;
|
|
|
|
}
|
2012-09-30 19:56:29 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
public Cursor getConversationSnippet(long threadId) {
|
2015-10-21 15:32:19 -07:00
|
|
|
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " DESC";
|
|
|
|
String selection = MmsSmsColumns.THREAD_ID + " = " + threadId;
|
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.
2013-04-20 12:22:04 -07:00
|
|
|
|
2015-10-21 15:32:19 -07:00
|
|
|
return queryTables(PROJECTION, selection, order, "1");
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
2012-09-30 19:56:29 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
public Cursor getUnread() {
|
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.
2013-04-20 12:22:04 -07:00
|
|
|
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " ASC";
|
2017-03-08 17:38:55 -08:00
|
|
|
String selection = MmsSmsColumns.READ + " = 0 AND " + MmsSmsColumns.NOTIFIED + " = 0";
|
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.
2013-04-20 12:22:04 -07:00
|
|
|
|
2015-10-21 15:32:19 -07:00
|
|
|
return queryTables(PROJECTION, selection, order, null);
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
2012-09-30 19:56:29 -07:00
|
|
|
|
2016-02-19 17:07:41 -08:00
|
|
|
public int getUnreadCount(long threadId) {
|
2017-03-08 17:38:55 -08:00
|
|
|
String selection = MmsSmsColumns.READ + " = 0 AND " + MmsSmsColumns.NOTIFIED + " = 0 AND " + MmsSmsColumns.THREAD_ID + " = " + threadId;
|
2016-02-19 17:07:41 -08:00
|
|
|
Cursor cursor = queryTables(PROJECTION, selection, null, null);
|
|
|
|
|
|
|
|
try {
|
|
|
|
return cursor != null ? cursor.getCount() : 0;
|
|
|
|
} finally {
|
|
|
|
if (cursor != null) cursor.close();;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
public int getConversationCount(long threadId) {
|
|
|
|
int count = DatabaseFactory.getSmsDatabase(context).getMessageCountForThread(threadId);
|
|
|
|
count += DatabaseFactory.getMmsDatabase(context).getMessageCountForThread(threadId);
|
2012-09-30 19:56:29 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2017-09-30 08:45:45 -07:00
|
|
|
public void incrementDeliveryReceiptCount(SyncMessageId syncMessageId, long timestamp) {
|
2017-09-15 22:38:53 -07:00
|
|
|
DatabaseFactory.getSmsDatabase(context).incrementReceiptCount(syncMessageId, true, false);
|
2017-09-30 08:45:45 -07:00
|
|
|
DatabaseFactory.getMmsDatabase(context).incrementReceiptCount(syncMessageId, timestamp, true, false);
|
2017-09-15 22:38:53 -07:00
|
|
|
}
|
|
|
|
|
2017-09-30 08:45:45 -07:00
|
|
|
public void incrementReadReceiptCount(SyncMessageId syncMessageId, long timestamp) {
|
2017-09-15 22:38:53 -07:00
|
|
|
DatabaseFactory.getSmsDatabase(context).incrementReceiptCount(syncMessageId, false, true);
|
2017-09-30 08:45:45 -07:00
|
|
|
DatabaseFactory.getMmsDatabase(context).incrementReceiptCount(syncMessageId, timestamp, false, true);
|
2014-07-25 15:14:29 -07:00
|
|
|
}
|
|
|
|
|
2018-08-11 09:55:52 -04:00
|
|
|
public int getQuotedMessagePosition(long threadId, long quoteId, @NonNull Address address) {
|
2018-04-02 16:17:32 -07:00
|
|
|
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " DESC";
|
|
|
|
String selection = MmsSmsColumns.THREAD_ID + " = " + threadId;
|
|
|
|
|
2018-08-11 09:55:52 -04:00
|
|
|
try (Cursor cursor = queryTables(new String[]{ MmsSmsColumns.NORMALIZED_DATE_SENT, MmsSmsColumns.ADDRESS }, selection, order, null)) {
|
2018-04-02 16:17:32 -07:00
|
|
|
String serializedAddress = address.serialize();
|
|
|
|
boolean isOwnNumber = Util.isOwnNumber(context, address);
|
|
|
|
|
|
|
|
while (cursor != null && cursor.moveToNext()) {
|
|
|
|
boolean quoteIdMatches = cursor.getLong(0) == quoteId;
|
|
|
|
boolean addressMatches = serializedAddress.equals(cursor.getString(1));
|
|
|
|
|
|
|
|
if (quoteIdMatches && (addressMatches || isOwnNumber)) {
|
|
|
|
return cursor.getPosition();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-02-01 09:06:59 -08:00
|
|
|
public int getMessagePositionInConversation(long threadId, long receivedTimestamp, @NonNull Address address) {
|
|
|
|
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " DESC";
|
|
|
|
String selection = MmsSmsColumns.THREAD_ID + " = " + threadId;
|
|
|
|
|
|
|
|
try (Cursor cursor = queryTables(new String[]{ MmsSmsColumns.NORMALIZED_DATE_RECEIVED, MmsSmsColumns.ADDRESS }, selection, order, null)) {
|
|
|
|
String serializedAddress = address.serialize();
|
|
|
|
boolean isOwnNumber = Util.isOwnNumber(context, address);
|
|
|
|
|
|
|
|
while (cursor != null && cursor.moveToNext()) {
|
|
|
|
boolean timestampMatches = cursor.getLong(0) == receivedTimestamp;
|
|
|
|
boolean addressMatches = serializedAddress.equals(cursor.getString(1));
|
|
|
|
|
|
|
|
if (timestampMatches && (addressMatches || isOwnNumber)) {
|
|
|
|
return cursor.getPosition();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-04-06 18:15:24 -07:00
|
|
|
/**
|
|
|
|
* Retrieves the position of the message with the provided timestamp in the query results you'd
|
|
|
|
* get from calling {@link #getConversation(long)}.
|
|
|
|
*
|
|
|
|
* Note: This could give back incorrect results in the situation where multiple messages have the
|
|
|
|
* same received timestamp. However, because this was designed to determine where to scroll to,
|
|
|
|
* you'll still wind up in about the right spot.
|
|
|
|
*/
|
|
|
|
public int getMessagePositionInConversation(long threadId, long receivedTimestamp) {
|
|
|
|
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " DESC";
|
|
|
|
String selection = MmsSmsColumns.THREAD_ID + " = " + threadId + " AND " + MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " > " + receivedTimestamp;
|
|
|
|
|
|
|
|
try (Cursor cursor = queryTables(new String[]{ "COUNT(*)" }, selection, order, null)) {
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
|
return cursor.getInt(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-10-21 15:32:19 -07:00
|
|
|
private Cursor queryTables(String[] projection, String selection, String order, String limit) {
|
2015-08-04 13:37:22 -07:00
|
|
|
String[] mmsProjection = {MmsDatabase.DATE_SENT + " AS " + MmsSmsColumns.NORMALIZED_DATE_SENT,
|
|
|
|
MmsDatabase.DATE_RECEIVED + " AS " + MmsSmsColumns.NORMALIZED_DATE_RECEIVED,
|
2015-10-21 15:32:19 -07:00
|
|
|
MmsDatabase.TABLE_NAME + "." + MmsDatabase.ID + " AS " + MmsSmsColumns.ID,
|
2017-02-17 11:57:51 -08:00
|
|
|
"'MMS::' || " + MmsDatabase.TABLE_NAME + "." + MmsDatabase.ID
|
|
|
|
+ " || '::' || " + MmsDatabase.DATE_SENT
|
2015-11-13 13:20:16 -08:00
|
|
|
+ " AS " + MmsSmsColumns.UNIQUE_ROW_ID,
|
2018-02-07 14:01:37 -08:00
|
|
|
"json_group_array(json_object(" +
|
|
|
|
"'" + AttachmentDatabase.ROW_ID + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.ROW_ID + ", " +
|
|
|
|
"'" + AttachmentDatabase.UNIQUE_ID + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.UNIQUE_ID + ", " +
|
|
|
|
"'" + AttachmentDatabase.MMS_ID + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.MMS_ID + "," +
|
|
|
|
"'" + AttachmentDatabase.SIZE + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.SIZE + ", " +
|
|
|
|
"'" + AttachmentDatabase.FILE_NAME + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.FILE_NAME + ", " +
|
|
|
|
"'" + AttachmentDatabase.DATA + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.DATA + ", " +
|
|
|
|
"'" + AttachmentDatabase.THUMBNAIL + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.THUMBNAIL + ", " +
|
|
|
|
"'" + AttachmentDatabase.CONTENT_TYPE + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.CONTENT_TYPE + ", " +
|
|
|
|
"'" + AttachmentDatabase.CONTENT_LOCATION + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.CONTENT_LOCATION + ", " +
|
|
|
|
"'" + AttachmentDatabase.FAST_PREFLIGHT_ID + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.FAST_PREFLIGHT_ID + ", " +
|
|
|
|
"'" + AttachmentDatabase.VOICE_NOTE + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.VOICE_NOTE + ", " +
|
|
|
|
"'" + AttachmentDatabase.WIDTH + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.WIDTH + ", " +
|
|
|
|
"'" + AttachmentDatabase.HEIGHT + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.HEIGHT + ", " +
|
|
|
|
"'" + AttachmentDatabase.QUOTE + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.QUOTE + ", " +
|
|
|
|
"'" + AttachmentDatabase.CONTENT_DISPOSITION + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.CONTENT_DISPOSITION + ", " +
|
|
|
|
"'" + AttachmentDatabase.NAME + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.NAME + ", " +
|
2018-11-08 23:33:37 -08:00
|
|
|
"'" + AttachmentDatabase.TRANSFER_STATE + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.TRANSFER_STATE + ", " +
|
2019-04-17 10:21:30 -04:00
|
|
|
"'" + AttachmentDatabase.CAPTION + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.CAPTION + ", " +
|
|
|
|
"'" + AttachmentDatabase.STICKER_PACK_ID + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.STICKER_PACK_ID + ", " +
|
|
|
|
"'" + AttachmentDatabase.STICKER_PACK_KEY + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.STICKER_PACK_KEY + ", " +
|
|
|
|
"'" + AttachmentDatabase.STICKER_ID + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.STICKER_ID +
|
2018-02-07 14:01:37 -08:00
|
|
|
")) AS " + AttachmentDatabase.ATTACHMENT_JSON_ALIAS,
|
2015-10-21 15:32:19 -07:00
|
|
|
SmsDatabase.BODY, MmsSmsColumns.READ, MmsSmsColumns.THREAD_ID,
|
2014-02-02 19:38:06 -08:00
|
|
|
SmsDatabase.TYPE, SmsDatabase.ADDRESS, SmsDatabase.ADDRESS_DEVICE_ID, SmsDatabase.SUBJECT, MmsDatabase.MESSAGE_TYPE,
|
2013-05-05 12:51:36 -07:00
|
|
|
MmsDatabase.MESSAGE_BOX, SmsDatabase.STATUS, MmsDatabase.PART_COUNT,
|
|
|
|
MmsDatabase.CONTENT_LOCATION, MmsDatabase.TRANSACTION_ID,
|
|
|
|
MmsDatabase.MESSAGE_SIZE, MmsDatabase.EXPIRY, MmsDatabase.STATUS,
|
2018-05-22 02:13:10 -07:00
|
|
|
MmsDatabase.UNIDENTIFIED,
|
2017-09-15 22:38:53 -07:00
|
|
|
MmsSmsColumns.DELIVERY_RECEIPT_COUNT, MmsSmsColumns.READ_RECEIPT_COUNT,
|
|
|
|
MmsSmsColumns.MISMATCHED_IDENTITIES,
|
2016-08-15 20:23:56 -07:00
|
|
|
MmsSmsColumns.SUBSCRIPTION_ID, MmsSmsColumns.EXPIRES_IN, MmsSmsColumns.EXPIRE_STARTED,
|
2017-03-08 17:38:55 -08:00
|
|
|
MmsSmsColumns.NOTIFIED,
|
2017-09-15 22:38:53 -07:00
|
|
|
MmsDatabase.NETWORK_FAILURE, TRANSPORT,
|
2018-02-07 14:01:37 -08:00
|
|
|
MmsDatabase.QUOTE_ID,
|
|
|
|
MmsDatabase.QUOTE_AUTHOR,
|
|
|
|
MmsDatabase.QUOTE_BODY,
|
2018-08-11 09:55:52 -04:00
|
|
|
MmsDatabase.QUOTE_MISSING,
|
2018-04-26 17:03:54 -07:00
|
|
|
MmsDatabase.QUOTE_ATTACHMENT,
|
2019-01-15 00:41:05 -08:00
|
|
|
MmsDatabase.SHARED_CONTACTS,
|
|
|
|
MmsDatabase.LINK_PREVIEWS};
|
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.
2013-04-20 12:22:04 -07:00
|
|
|
|
2015-08-04 13:37:22 -07:00
|
|
|
String[] smsProjection = {SmsDatabase.DATE_SENT + " AS " + MmsSmsColumns.NORMALIZED_DATE_SENT,
|
|
|
|
SmsDatabase.DATE_RECEIVED + " AS " + MmsSmsColumns.NORMALIZED_DATE_RECEIVED,
|
2015-11-13 13:20:16 -08:00
|
|
|
MmsSmsColumns.ID,
|
2017-02-17 11:57:51 -08:00
|
|
|
"'SMS::' || " + MmsSmsColumns.ID
|
|
|
|
+ " || '::' || " + SmsDatabase.DATE_SENT
|
2015-11-13 13:20:16 -08:00
|
|
|
+ " AS " + MmsSmsColumns.UNIQUE_ROW_ID,
|
2018-02-07 14:01:37 -08:00
|
|
|
"NULL AS " + AttachmentDatabase.ATTACHMENT_JSON_ALIAS,
|
2015-10-21 15:32:19 -07:00
|
|
|
SmsDatabase.BODY, MmsSmsColumns.READ, MmsSmsColumns.THREAD_ID,
|
2014-02-02 19:38:06 -08:00
|
|
|
SmsDatabase.TYPE, SmsDatabase.ADDRESS, SmsDatabase.ADDRESS_DEVICE_ID, SmsDatabase.SUBJECT, MmsDatabase.MESSAGE_TYPE,
|
2013-05-05 12:51:36 -07:00
|
|
|
MmsDatabase.MESSAGE_BOX, SmsDatabase.STATUS, MmsDatabase.PART_COUNT,
|
|
|
|
MmsDatabase.CONTENT_LOCATION, MmsDatabase.TRANSACTION_ID,
|
|
|
|
MmsDatabase.MESSAGE_SIZE, MmsDatabase.EXPIRY, MmsDatabase.STATUS,
|
2018-05-22 02:13:10 -07:00
|
|
|
MmsDatabase.UNIDENTIFIED,
|
2017-09-15 22:38:53 -07:00
|
|
|
MmsSmsColumns.DELIVERY_RECEIPT_COUNT, MmsSmsColumns.READ_RECEIPT_COUNT,
|
|
|
|
MmsSmsColumns.MISMATCHED_IDENTITIES,
|
2016-08-15 20:23:56 -07:00
|
|
|
MmsSmsColumns.SUBSCRIPTION_ID, MmsSmsColumns.EXPIRES_IN, MmsSmsColumns.EXPIRE_STARTED,
|
2017-03-08 17:38:55 -08:00
|
|
|
MmsSmsColumns.NOTIFIED,
|
2015-10-21 15:32:19 -07:00
|
|
|
MmsDatabase.NETWORK_FAILURE, TRANSPORT,
|
2018-02-07 14:01:37 -08:00
|
|
|
MmsDatabase.QUOTE_ID,
|
|
|
|
MmsDatabase.QUOTE_AUTHOR,
|
|
|
|
MmsDatabase.QUOTE_BODY,
|
2018-08-11 09:55:52 -04:00
|
|
|
MmsDatabase.QUOTE_MISSING,
|
2018-04-26 17:03:54 -07:00
|
|
|
MmsDatabase.QUOTE_ATTACHMENT,
|
2019-01-15 00:41:05 -08:00
|
|
|
MmsDatabase.SHARED_CONTACTS,
|
|
|
|
MmsDatabase.LINK_PREVIEWS};
|
2012-09-30 19:56:29 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
SQLiteQueryBuilder mmsQueryBuilder = new SQLiteQueryBuilder();
|
|
|
|
SQLiteQueryBuilder smsQueryBuilder = new SQLiteQueryBuilder();
|
|
|
|
|
|
|
|
mmsQueryBuilder.setDistinct(true);
|
|
|
|
smsQueryBuilder.setDistinct(true);
|
|
|
|
|
|
|
|
smsQueryBuilder.setTables(SmsDatabase.TABLE_NAME);
|
2015-10-24 17:51:17 -07:00
|
|
|
mmsQueryBuilder.setTables(MmsDatabase.TABLE_NAME + " LEFT OUTER JOIN " +
|
|
|
|
AttachmentDatabase.TABLE_NAME +
|
2018-02-07 14:01:37 -08:00
|
|
|
" ON " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.MMS_ID + " = " + MmsDatabase.TABLE_NAME + "." + MmsDatabase.ID);
|
2015-10-24 17:51:17 -07:00
|
|
|
|
2012-09-30 19:56:29 -07:00
|
|
|
|
2015-10-21 15:32:19 -07:00
|
|
|
Set<String> mmsColumnsPresent = new HashSet<>();
|
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.
2013-04-20 12:22:04 -07:00
|
|
|
mmsColumnsPresent.add(MmsSmsColumns.ID);
|
2013-05-05 12:51:36 -07:00
|
|
|
mmsColumnsPresent.add(MmsSmsColumns.READ);
|
|
|
|
mmsColumnsPresent.add(MmsSmsColumns.THREAD_ID);
|
|
|
|
mmsColumnsPresent.add(MmsSmsColumns.BODY);
|
|
|
|
mmsColumnsPresent.add(MmsSmsColumns.ADDRESS);
|
2014-02-02 19:38:06 -08:00
|
|
|
mmsColumnsPresent.add(MmsSmsColumns.ADDRESS_DEVICE_ID);
|
2017-09-15 22:38:53 -07:00
|
|
|
mmsColumnsPresent.add(MmsSmsColumns.DELIVERY_RECEIPT_COUNT);
|
|
|
|
mmsColumnsPresent.add(MmsSmsColumns.READ_RECEIPT_COUNT);
|
2015-01-15 13:35:35 -08:00
|
|
|
mmsColumnsPresent.add(MmsSmsColumns.MISMATCHED_IDENTITIES);
|
2016-02-05 16:10:33 -08:00
|
|
|
mmsColumnsPresent.add(MmsSmsColumns.SUBSCRIPTION_ID);
|
2016-08-15 20:23:56 -07:00
|
|
|
mmsColumnsPresent.add(MmsSmsColumns.EXPIRES_IN);
|
|
|
|
mmsColumnsPresent.add(MmsSmsColumns.EXPIRE_STARTED);
|
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.
2013-04-20 12:22:04 -07:00
|
|
|
mmsColumnsPresent.add(MmsDatabase.MESSAGE_TYPE);
|
|
|
|
mmsColumnsPresent.add(MmsDatabase.MESSAGE_BOX);
|
|
|
|
mmsColumnsPresent.add(MmsDatabase.DATE_SENT);
|
|
|
|
mmsColumnsPresent.add(MmsDatabase.DATE_RECEIVED);
|
2013-04-26 11:23:43 -07:00
|
|
|
mmsColumnsPresent.add(MmsDatabase.PART_COUNT);
|
2013-05-05 12:51:36 -07:00
|
|
|
mmsColumnsPresent.add(MmsDatabase.CONTENT_LOCATION);
|
|
|
|
mmsColumnsPresent.add(MmsDatabase.TRANSACTION_ID);
|
|
|
|
mmsColumnsPresent.add(MmsDatabase.MESSAGE_SIZE);
|
|
|
|
mmsColumnsPresent.add(MmsDatabase.EXPIRY);
|
2017-03-08 17:38:55 -08:00
|
|
|
mmsColumnsPresent.add(MmsDatabase.NOTIFIED);
|
2013-05-05 12:51:36 -07:00
|
|
|
mmsColumnsPresent.add(MmsDatabase.STATUS);
|
2018-05-22 02:13:10 -07:00
|
|
|
mmsColumnsPresent.add(MmsDatabase.UNIDENTIFIED);
|
2015-01-15 13:35:35 -08:00
|
|
|
mmsColumnsPresent.add(MmsDatabase.NETWORK_FAILURE);
|
2012-09-30 19:56:29 -07:00
|
|
|
|
2015-10-21 15:32:19 -07:00
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.ROW_ID);
|
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.UNIQUE_ID);
|
2016-12-11 13:37:27 -08:00
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.MMS_ID);
|
2015-10-21 15:32:19 -07:00
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.SIZE);
|
2017-03-28 12:05:30 -07:00
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.FILE_NAME);
|
2016-12-11 13:37:27 -08:00
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.DATA);
|
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.THUMBNAIL);
|
2015-10-21 15:32:19 -07:00
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.CONTENT_TYPE);
|
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.CONTENT_LOCATION);
|
2017-02-26 10:06:27 -08:00
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.DIGEST);
|
2017-04-22 16:29:26 -07:00
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.FAST_PREFLIGHT_ID);
|
2017-05-11 22:46:35 -07:00
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.VOICE_NOTE);
|
2018-03-18 16:04:33 -07:00
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.WIDTH);
|
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.HEIGHT);
|
2018-02-07 14:01:37 -08:00
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.QUOTE);
|
2019-04-17 10:21:30 -04:00
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.STICKER_PACK_ID);
|
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.STICKER_PACK_KEY);
|
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.STICKER_ID);
|
2018-11-08 23:33:37 -08:00
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.CAPTION);
|
2015-10-21 15:32:19 -07:00
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.CONTENT_DISPOSITION);
|
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.NAME);
|
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.TRANSFER_STATE);
|
2018-02-07 14:01:37 -08:00
|
|
|
mmsColumnsPresent.add(AttachmentDatabase.ATTACHMENT_JSON_ALIAS);
|
|
|
|
mmsColumnsPresent.add(MmsDatabase.QUOTE_ID);
|
|
|
|
mmsColumnsPresent.add(MmsDatabase.QUOTE_AUTHOR);
|
|
|
|
mmsColumnsPresent.add(MmsDatabase.QUOTE_BODY);
|
2018-08-11 09:55:52 -04:00
|
|
|
mmsColumnsPresent.add(MmsDatabase.QUOTE_MISSING);
|
2018-02-07 14:01:37 -08:00
|
|
|
mmsColumnsPresent.add(MmsDatabase.QUOTE_ATTACHMENT);
|
2018-04-26 17:03:54 -07:00
|
|
|
mmsColumnsPresent.add(MmsDatabase.SHARED_CONTACTS);
|
2019-01-15 00:41:05 -08:00
|
|
|
mmsColumnsPresent.add(MmsDatabase.LINK_PREVIEWS);
|
2015-10-21 15:32:19 -07:00
|
|
|
|
|
|
|
Set<String> smsColumnsPresent = new HashSet<>();
|
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.
2013-04-20 12:22:04 -07:00
|
|
|
smsColumnsPresent.add(MmsSmsColumns.ID);
|
2013-04-26 11:23:43 -07:00
|
|
|
smsColumnsPresent.add(MmsSmsColumns.BODY);
|
2013-05-05 12:51:36 -07:00
|
|
|
smsColumnsPresent.add(MmsSmsColumns.ADDRESS);
|
2014-02-02 19:38:06 -08:00
|
|
|
smsColumnsPresent.add(MmsSmsColumns.ADDRESS_DEVICE_ID);
|
2013-05-05 12:51:36 -07:00
|
|
|
smsColumnsPresent.add(MmsSmsColumns.READ);
|
|
|
|
smsColumnsPresent.add(MmsSmsColumns.THREAD_ID);
|
2017-09-15 22:38:53 -07:00
|
|
|
smsColumnsPresent.add(MmsSmsColumns.DELIVERY_RECEIPT_COUNT);
|
|
|
|
smsColumnsPresent.add(MmsSmsColumns.READ_RECEIPT_COUNT);
|
2015-01-15 13:35:35 -08:00
|
|
|
smsColumnsPresent.add(MmsSmsColumns.MISMATCHED_IDENTITIES);
|
2016-02-05 16:10:33 -08:00
|
|
|
smsColumnsPresent.add(MmsSmsColumns.SUBSCRIPTION_ID);
|
2016-08-15 20:23:56 -07:00
|
|
|
smsColumnsPresent.add(MmsSmsColumns.EXPIRES_IN);
|
|
|
|
smsColumnsPresent.add(MmsSmsColumns.EXPIRE_STARTED);
|
2017-03-08 17:38:55 -08:00
|
|
|
smsColumnsPresent.add(MmsSmsColumns.NOTIFIED);
|
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.
2013-04-20 12:22:04 -07:00
|
|
|
smsColumnsPresent.add(SmsDatabase.TYPE);
|
|
|
|
smsColumnsPresent.add(SmsDatabase.SUBJECT);
|
|
|
|
smsColumnsPresent.add(SmsDatabase.DATE_SENT);
|
|
|
|
smsColumnsPresent.add(SmsDatabase.DATE_RECEIVED);
|
|
|
|
smsColumnsPresent.add(SmsDatabase.STATUS);
|
2018-05-22 02:13:10 -07:00
|
|
|
smsColumnsPresent.add(SmsDatabase.UNIDENTIFIED);
|
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.
2013-04-20 12:22:04 -07:00
|
|
|
|
2015-11-13 13:20:16 -08:00
|
|
|
@SuppressWarnings("deprecation")
|
2018-02-07 14:01:37 -08:00
|
|
|
String mmsSubQuery = mmsQueryBuilder.buildUnionSubQuery(TRANSPORT, mmsProjection, mmsColumnsPresent, 4, MMS_TRANSPORT, selection, null, MmsDatabase.TABLE_NAME + "." + MmsDatabase.ID, null);
|
2015-11-13 13:20:16 -08:00
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
String smsSubQuery = smsQueryBuilder.buildUnionSubQuery(TRANSPORT, smsProjection, smsColumnsPresent, 4, SMS_TRANSPORT, selection, null, null, null);
|
2011-12-20 10:20:44 -08:00
|
|
|
|
2012-09-30 19:56:29 -07:00
|
|
|
SQLiteQueryBuilder unionQueryBuilder = new SQLiteQueryBuilder();
|
2015-10-21 15:32:19 -07:00
|
|
|
String unionQuery = unionQueryBuilder.buildUnionQuery(new String[] {smsSubQuery, mmsSubQuery}, order, limit);
|
2011-12-20 10:20:44 -08:00
|
|
|
|
|
|
|
SQLiteQueryBuilder outerQueryBuilder = new SQLiteQueryBuilder();
|
|
|
|
outerQueryBuilder.setTables("(" + unionQuery + ")");
|
2012-09-30 19:56:29 -07:00
|
|
|
|
2015-11-13 13:20:16 -08:00
|
|
|
@SuppressWarnings("deprecation")
|
2015-10-21 15:32:19 -07:00
|
|
|
String query = outerQueryBuilder.buildQuery(projection, null, null, null, null, null, null);
|
2012-09-30 19:56:29 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
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.
2013-04-20 12:22:04 -07:00
|
|
|
return db.rawQuery(query, null);
|
|
|
|
}
|
|
|
|
|
2015-07-20 15:05:56 -07:00
|
|
|
public Reader readerFor(@NonNull Cursor cursor) {
|
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.
2013-04-20 12:22:04 -07:00
|
|
|
return new Reader(cursor);
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
2012-09-30 19:56:29 -07:00
|
|
|
|
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.
2013-04-20 12:22:04 -07:00
|
|
|
public class Reader {
|
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
private final Cursor cursor;
|
|
|
|
private SmsDatabase.Reader smsReader;
|
|
|
|
private MmsDatabase.Reader mmsReader;
|
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.
2013-04-20 12:22:04 -07:00
|
|
|
|
|
|
|
public Reader(Cursor cursor) {
|
2018-01-24 19:17:44 -08:00
|
|
|
this.cursor = cursor;
|
2015-07-20 15:05:56 -07:00
|
|
|
}
|
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
private SmsDatabase.Reader getSmsReader() {
|
2015-07-20 15:05:56 -07:00
|
|
|
if (smsReader == null) {
|
2018-01-24 19:17:44 -08:00
|
|
|
smsReader = DatabaseFactory.getSmsDatabase(context).readerFor(cursor);
|
2015-07-20 15:05:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return smsReader;
|
|
|
|
}
|
|
|
|
|
|
|
|
private MmsDatabase.Reader getMmsReader() {
|
|
|
|
if (mmsReader == null) {
|
2018-01-24 19:17:44 -08:00
|
|
|
mmsReader = DatabaseFactory.getMmsDatabase(context).readerFor(cursor);
|
2015-07-20 15:05:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return mmsReader;
|
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.
2013-04-20 12:22:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public MessageRecord getNext() {
|
|
|
|
if (cursor == null || !cursor.moveToNext())
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return getCurrent();
|
|
|
|
}
|
|
|
|
|
|
|
|
public MessageRecord getCurrent() {
|
|
|
|
String type = cursor.getString(cursor.getColumnIndexOrThrow(TRANSPORT));
|
|
|
|
|
2015-10-21 15:32:19 -07:00
|
|
|
if (MmsSmsDatabase.MMS_TRANSPORT.equals(type)) return getMmsReader().getCurrent();
|
|
|
|
else if (MmsSmsDatabase.SMS_TRANSPORT.equals(type)) return getSmsReader().getCurrent();
|
|
|
|
else throw new AssertionError("Bad type: " + type);
|
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.
2013-04-20 12:22:04 -07:00
|
|
|
}
|
2013-04-26 11:23:43 -07:00
|
|
|
|
|
|
|
public void close() {
|
|
|
|
cursor.close();
|
|
|
|
}
|
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.
2013-04-20 12:22:04 -07:00
|
|
|
}
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|