mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 01:40:07 +01:00
Remove job-based decryption support and MCPv1.
This commit is contained in:
@@ -1,191 +0,0 @@
|
||||
package org.thoughtcrime.securesms.database;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.util.Base64;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.internal.util.Util;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class PushTable extends DatabaseTable {
|
||||
|
||||
private static final String TAG = Log.tag(PushTable.class);
|
||||
|
||||
private static final String TABLE_NAME = "push";
|
||||
public static final String ID = "_id";
|
||||
public static final String TYPE = "type";
|
||||
public static final String SOURCE_E164 = "source";
|
||||
public static final String SOURCE_UUID = "source_uuid";
|
||||
public static final String DEVICE_ID = "device_id";
|
||||
public static final String LEGACY_MSG = "body";
|
||||
public static final String CONTENT = "content";
|
||||
public static final String TIMESTAMP = "timestamp";
|
||||
public static final String SERVER_RECEIVED_TIMESTAMP = "server_timestamp";
|
||||
public static final String SERVER_DELIVERED_TIMESTAMP = "server_delivered_timestamp";
|
||||
public static final String SERVER_GUID = "server_guid";
|
||||
|
||||
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" + ID + " INTEGER PRIMARY KEY, " +
|
||||
TYPE + " INTEGER, " +
|
||||
SOURCE_E164 + " TEXT, " +
|
||||
SOURCE_UUID + " TEXT, " +
|
||||
DEVICE_ID + " INTEGER, " +
|
||||
LEGACY_MSG + " TEXT, " +
|
||||
CONTENT + " TEXT, " +
|
||||
TIMESTAMP + " INTEGER, " +
|
||||
SERVER_RECEIVED_TIMESTAMP + " INTEGER DEFAULT 0, " +
|
||||
SERVER_DELIVERED_TIMESTAMP + " INTEGER DEFAULT 0, " +
|
||||
SERVER_GUID + " TEXT DEFAULT NULL);";
|
||||
|
||||
public PushTable(Context context, SignalDatabase databaseHelper) {
|
||||
super(context, databaseHelper);
|
||||
}
|
||||
|
||||
public long insert(@NonNull SignalServiceEnvelope envelope) {
|
||||
Optional<Long> messageId = find(envelope);
|
||||
|
||||
if (messageId.isPresent()) {
|
||||
return -1;
|
||||
} else {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(TYPE, envelope.getType());
|
||||
values.put(SOURCE_UUID, envelope.getSourceServiceId().orElse(null));
|
||||
values.put(DEVICE_ID, envelope.getSourceDevice());
|
||||
values.put(CONTENT, envelope.hasContent() ? Base64.encodeBytes(envelope.getContent()) : "");
|
||||
values.put(TIMESTAMP, envelope.getTimestamp());
|
||||
values.put(SERVER_RECEIVED_TIMESTAMP, envelope.getServerReceivedTimestamp());
|
||||
values.put(SERVER_DELIVERED_TIMESTAMP, envelope.getServerDeliveredTimestamp());
|
||||
values.put(SERVER_GUID, envelope.getServerGuid());
|
||||
|
||||
return databaseHelper.getSignalWritableDatabase().insert(TABLE_NAME, null, values);
|
||||
}
|
||||
}
|
||||
|
||||
public SignalServiceEnvelope get(long id) throws NoSuchMessageException {
|
||||
Cursor cursor = null;
|
||||
|
||||
try {
|
||||
cursor = databaseHelper.getSignalReadableDatabase().query(TABLE_NAME, null, ID_WHERE,
|
||||
new String[] {String.valueOf(id)},
|
||||
null, null, null);
|
||||
|
||||
if (cursor != null && cursor.moveToNext()) {
|
||||
String legacyMessage = cursor.getString(cursor.getColumnIndexOrThrow(LEGACY_MSG));
|
||||
String content = cursor.getString(cursor.getColumnIndexOrThrow(CONTENT));
|
||||
String uuid = cursor.getString(cursor.getColumnIndexOrThrow(SOURCE_UUID));
|
||||
String e164 = cursor.getString(cursor.getColumnIndexOrThrow(SOURCE_E164));
|
||||
|
||||
return new SignalServiceEnvelope(cursor.getInt(cursor.getColumnIndexOrThrow(TYPE)),
|
||||
SignalServiceAddress.fromRaw(uuid, e164),
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow(DEVICE_ID)),
|
||||
cursor.getLong(cursor.getColumnIndexOrThrow(TIMESTAMP)),
|
||||
Util.isEmpty(content) ? null : Base64.decode(content),
|
||||
cursor.getLong(cursor.getColumnIndexOrThrow(SERVER_RECEIVED_TIMESTAMP)),
|
||||
cursor.getLong(cursor.getColumnIndexOrThrow(SERVER_DELIVERED_TIMESTAMP)),
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(SERVER_GUID)),
|
||||
"",
|
||||
true,
|
||||
false,
|
||||
null);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
throw new NoSuchMessageException(e);
|
||||
} finally {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
throw new NoSuchMessageException("Not found");
|
||||
}
|
||||
|
||||
public Cursor getPending() {
|
||||
return databaseHelper.getSignalReadableDatabase().query(TABLE_NAME, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public void delete(long id) {
|
||||
databaseHelper.getSignalWritableDatabase().delete(TABLE_NAME, ID_WHERE, new String[] {id+""});
|
||||
}
|
||||
|
||||
public Reader readerFor(Cursor cursor) {
|
||||
return new Reader(cursor);
|
||||
}
|
||||
|
||||
private Optional<Long> find(SignalServiceEnvelope envelope) {
|
||||
SQLiteDatabase database = databaseHelper.getSignalReadableDatabase();
|
||||
String query = TYPE + " = ? AND " +
|
||||
DEVICE_ID + " = ? AND " +
|
||||
LEGACY_MSG + " = ? AND " +
|
||||
CONTENT + " = ? AND " +
|
||||
TIMESTAMP + " = ? AND " +
|
||||
"(" + SOURCE_UUID + " NOT NULL AND " + SOURCE_UUID + " = ?)";
|
||||
|
||||
String[] args = new String[] { String.valueOf(envelope.getType()),
|
||||
String.valueOf(envelope.getSourceDevice()),
|
||||
envelope.hasContent() ? Base64.encodeBytes(envelope.getContent()) : "",
|
||||
String.valueOf(envelope.getTimestamp()),
|
||||
String.valueOf(envelope.getSourceServiceId().orElse(null)) };
|
||||
|
||||
|
||||
try (Cursor cursor = database.query(TABLE_NAME, null, query, args, null, null, null)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
return Optional.of(cursor.getLong(cursor.getColumnIndexOrThrow(ID)));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Reader implements Closeable {
|
||||
private final Cursor cursor;
|
||||
|
||||
public Reader(Cursor cursor) {
|
||||
this.cursor = cursor;
|
||||
}
|
||||
|
||||
public SignalServiceEnvelope getNext() {
|
||||
try {
|
||||
if (cursor == null || !cursor.moveToNext())
|
||||
return null;
|
||||
|
||||
int type = cursor.getInt(cursor.getColumnIndexOrThrow(TYPE));
|
||||
String sourceUuid = cursor.getString(cursor.getColumnIndexOrThrow(SOURCE_UUID));
|
||||
String sourceE164 = cursor.getString(cursor.getColumnIndexOrThrow(SOURCE_E164));
|
||||
int deviceId = cursor.getInt(cursor.getColumnIndexOrThrow(DEVICE_ID));
|
||||
String content = cursor.getString(cursor.getColumnIndexOrThrow(CONTENT));
|
||||
long timestamp = cursor.getLong(cursor.getColumnIndexOrThrow(TIMESTAMP));
|
||||
long serverReceivedTimestamp = cursor.getLong(cursor.getColumnIndexOrThrow(SERVER_RECEIVED_TIMESTAMP));
|
||||
long serverDeliveredTimestamp = cursor.getLong(cursor.getColumnIndexOrThrow(SERVER_DELIVERED_TIMESTAMP));
|
||||
String serverGuid = cursor.getString(cursor.getColumnIndexOrThrow(SERVER_GUID));
|
||||
|
||||
return new SignalServiceEnvelope(type,
|
||||
SignalServiceAddress.fromRaw(sourceUuid, sourceE164),
|
||||
deviceId,
|
||||
timestamp,
|
||||
content != null ? Base64.decode(content) : null,
|
||||
serverReceivedTimestamp,
|
||||
serverDeliveredTimestamp,
|
||||
serverGuid,
|
||||
"",
|
||||
true,
|
||||
false,
|
||||
null);
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
this.cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,6 @@ open class SignalDatabase(private val context: Application, databaseSecret: Data
|
||||
val threadTable: ThreadTable = ThreadTable(context, this)
|
||||
val identityTable: IdentityTable = IdentityTable(context, this)
|
||||
val draftTable: DraftTable = DraftTable(context, this)
|
||||
val pushTable: PushTable = PushTable(context, this)
|
||||
val groupTable: GroupTable = GroupTable(context, this)
|
||||
val recipientTable: RecipientTable = RecipientTable(context, this)
|
||||
val groupReceiptTable: GroupReceiptTable = GroupReceiptTable(context, this)
|
||||
@@ -86,7 +85,6 @@ open class SignalDatabase(private val context: Application, databaseSecret: Data
|
||||
db.execSQL(ThreadTable.CREATE_TABLE)
|
||||
db.execSQL(IdentityTable.CREATE_TABLE)
|
||||
db.execSQL(DraftTable.CREATE_TABLE)
|
||||
db.execSQL(PushTable.CREATE_TABLE)
|
||||
executeStatements(db, GroupTable.CREATE_TABLES)
|
||||
db.execSQL(RecipientTable.CREATE_TABLE)
|
||||
db.execSQL(GroupReceiptTable.CREATE_TABLE)
|
||||
@@ -467,12 +465,6 @@ open class SignalDatabase(private val context: Application, databaseSecret: Data
|
||||
val pendingPniSignatureMessages: PendingPniSignatureMessageTable
|
||||
get() = instance!!.pendingPniSignatureMessageTable
|
||||
|
||||
@get:Deprecated("This only exists to migrate from legacy storage. There shouldn't be any new usages.")
|
||||
@get:JvmStatic
|
||||
@get:JvmName("push")
|
||||
val push: PushTable
|
||||
get() = instance!!.pushTable
|
||||
|
||||
@get:JvmStatic
|
||||
@get:JvmName("recipients")
|
||||
val recipients: RecipientTable
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
import com.google.i18n.phonenumbers.Phonenumber;
|
||||
import com.google.i18n.phonenumbers.ShortNumberInfo;
|
||||
|
||||
import org.signal.core.util.Hex;
|
||||
import org.signal.core.util.StreamUtil;
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.signal.libsignal.protocol.IdentityKey;
|
||||
@@ -31,12 +32,11 @@ import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
||||
import org.thoughtcrime.securesms.database.AttachmentTable;
|
||||
import org.thoughtcrime.securesms.database.DraftTable;
|
||||
import org.thoughtcrime.securesms.database.GroupTable;
|
||||
import org.thoughtcrime.securesms.database.GroupReceiptTable;
|
||||
import org.thoughtcrime.securesms.database.GroupTable;
|
||||
import org.thoughtcrime.securesms.database.IdentityTable;
|
||||
import org.thoughtcrime.securesms.database.MessageTypes;
|
||||
import org.thoughtcrime.securesms.database.MessageTable;
|
||||
import org.thoughtcrime.securesms.database.PushTable;
|
||||
import org.thoughtcrime.securesms.database.MessageTypes;
|
||||
import org.thoughtcrime.securesms.database.RecipientTable;
|
||||
import org.thoughtcrime.securesms.database.ThreadTable;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
@@ -46,7 +46,6 @@ import org.thoughtcrime.securesms.permissions.Permissions;
|
||||
import org.thoughtcrime.securesms.phonenumbers.NumberUtil;
|
||||
import org.thoughtcrime.securesms.util.Base64;
|
||||
import org.thoughtcrime.securesms.util.DelimiterUtil;
|
||||
import org.signal.core.util.Hex;
|
||||
import org.thoughtcrime.securesms.util.JsonUtils;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
@@ -133,7 +132,6 @@ public class ClassicOpenHelper extends SQLiteOpenHelper {
|
||||
db.execSQL(ThreadTable.CREATE_TABLE);
|
||||
db.execSQL(IdentityTable.CREATE_TABLE);
|
||||
db.execSQL(DraftTable.CREATE_TABLE);
|
||||
db.execSQL(PushTable.CREATE_TABLE);
|
||||
db.execSQL(GroupTable.CREATE_TABLE);
|
||||
db.execSQL(RecipientTable.CREATE_TABLE);
|
||||
db.execSQL(GroupReceiptTable.CREATE_TABLE);
|
||||
|
||||
@@ -60,6 +60,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V201_RecipientTable
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V202_DropMessageTableThreadDateIndex
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V203_PreKeyStaleTimestamp
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V204_GroupForeignKeyMigration
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V205_DropPushTable
|
||||
|
||||
/**
|
||||
* Contains all of the database migrations for [SignalDatabase]. Broken into a separate file for cleanliness.
|
||||
@@ -68,7 +69,7 @@ object SignalDatabaseMigrations {
|
||||
|
||||
val TAG: String = Log.tag(SignalDatabaseMigrations.javaClass)
|
||||
|
||||
const val DATABASE_VERSION = 204
|
||||
const val DATABASE_VERSION = 205
|
||||
|
||||
@JvmStatic
|
||||
fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
@@ -295,6 +296,10 @@ object SignalDatabaseMigrations {
|
||||
if (oldVersion < 204) {
|
||||
V204_GroupForeignKeyMigration.migrate(context, db, oldVersion, newVersion)
|
||||
}
|
||||
|
||||
if (oldVersion < 205) {
|
||||
V205_DropPushTable.migrate(context, db, oldVersion, newVersion)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2023 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.thoughtcrime.securesms.database.helpers.migration
|
||||
|
||||
import android.app.Application
|
||||
import net.zetetic.database.sqlcipher.SQLiteDatabase
|
||||
|
||||
/**
|
||||
* Drop the no longer used push table.
|
||||
*/
|
||||
@Suppress("ClassName")
|
||||
object V205_DropPushTable : SignalDatabaseMigration {
|
||||
override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
db.execSQL("DROP TABLE IF EXISTS push")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user