mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 08:39:22 +01:00
Add Small Group Ringing support.
This commit is contained in:
committed by
Alex Hart
parent
5787a5f68a
commit
db7272730e
@@ -72,6 +72,7 @@ public class DatabaseFactory {
|
||||
private final EmojiSearchDatabase emojiSearchDatabase;
|
||||
private final MessageSendLogDatabase messageSendLogDatabase;
|
||||
private final AvatarPickerDatabase avatarPickerDatabase;
|
||||
private final GroupCallRingDatabase groupCallRingDatabase;
|
||||
|
||||
public static DatabaseFactory getInstance(Context context) {
|
||||
if (instance == null) {
|
||||
@@ -206,6 +207,10 @@ public class DatabaseFactory {
|
||||
return getInstance(context).avatarPickerDatabase;
|
||||
}
|
||||
|
||||
public static GroupCallRingDatabase getGroupCallRingDatabase(Context context) {
|
||||
return getInstance(context).groupCallRingDatabase;
|
||||
}
|
||||
|
||||
public static net.zetetic.database.sqlcipher.SQLiteDatabase getBackupDatabase(Context context) {
|
||||
return getInstance(context).databaseHelper.getRawReadableDatabase();
|
||||
}
|
||||
@@ -268,6 +273,7 @@ public class DatabaseFactory {
|
||||
this.emojiSearchDatabase = new EmojiSearchDatabase(context, databaseHelper);
|
||||
this.messageSendLogDatabase = new MessageSendLogDatabase(context, databaseHelper);
|
||||
this.avatarPickerDatabase = new AvatarPickerDatabase(context, databaseHelper);
|
||||
this.groupCallRingDatabase = new GroupCallRingDatabase(context, databaseHelper);
|
||||
}
|
||||
|
||||
public void onApplicationLevelUpgrade(@NonNull Context context, @NonNull MasterSecret masterSecret,
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package org.thoughtcrime.securesms.database
|
||||
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import org.signal.ringrtc.CallManager
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||
import org.thoughtcrime.securesms.util.CursorUtil
|
||||
import org.thoughtcrime.securesms.util.SqlUtil
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* Track state of Group Call ring cancellations.
|
||||
*/
|
||||
class GroupCallRingDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Database(context, databaseHelper) {
|
||||
|
||||
companion object {
|
||||
private val VALID_RING_DURATION = TimeUnit.MINUTES.toMillis(30)
|
||||
|
||||
private const val TABLE_NAME = "group_call_ring"
|
||||
|
||||
private const val ID = "_id"
|
||||
private const val RING_ID = "ring_id"
|
||||
private const val DATE_RECEIVED = "date_received"
|
||||
private const val RING_STATE = "ring_state"
|
||||
|
||||
@JvmField
|
||||
val CREATE_TABLE = """
|
||||
CREATE TABLE $TABLE_NAME (
|
||||
$ID INTEGER PRIMARY KEY,
|
||||
$RING_ID INTEGER UNIQUE,
|
||||
$DATE_RECEIVED INTEGER,
|
||||
$RING_STATE INTEGER
|
||||
)
|
||||
""".trimIndent()
|
||||
|
||||
@JvmField
|
||||
val CREATE_INDEXES = arrayOf(
|
||||
"CREATE INDEX date_received_index on $TABLE_NAME ($DATE_RECEIVED)"
|
||||
)
|
||||
}
|
||||
|
||||
fun isCancelled(ringId: Long): Boolean {
|
||||
val db = databaseHelper.signalReadableDatabase
|
||||
|
||||
db.query(TABLE_NAME, null, "$RING_ID = ?", SqlUtil.buildArgs(ringId), null, null, null).use { cursor ->
|
||||
if (cursor.moveToFirst()) {
|
||||
return CursorUtil.requireInt(cursor, RING_STATE) != 0
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
fun insertGroupRing(ringId: Long, dateReceived: Long, ringState: CallManager.RingUpdate) {
|
||||
val db = databaseHelper.signalWritableDatabase
|
||||
val values = ContentValues().apply {
|
||||
put(RING_ID, ringId)
|
||||
put(DATE_RECEIVED, dateReceived)
|
||||
put(RING_STATE, ringState.toCode())
|
||||
}
|
||||
db.insert(TABLE_NAME, null, values)
|
||||
|
||||
removeOldRings()
|
||||
}
|
||||
|
||||
fun insertOrUpdateGroupRing(ringId: Long, dateReceived: Long, ringState: CallManager.RingUpdate) {
|
||||
val db = databaseHelper.signalWritableDatabase
|
||||
val values = ContentValues().apply {
|
||||
put(RING_ID, ringId)
|
||||
put(DATE_RECEIVED, dateReceived)
|
||||
put(RING_STATE, ringState.toCode())
|
||||
}
|
||||
db.insertWithOnConflict(TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE)
|
||||
|
||||
removeOldRings()
|
||||
}
|
||||
|
||||
fun removeOldRings() {
|
||||
val db = databaseHelper.signalWritableDatabase
|
||||
|
||||
db.delete(TABLE_NAME, "$DATE_RECEIVED < ?", SqlUtil.buildArgs(System.currentTimeMillis() - VALID_RING_DURATION))
|
||||
}
|
||||
}
|
||||
|
||||
private fun CallManager.RingUpdate.toCode(): Int {
|
||||
return when (this) {
|
||||
CallManager.RingUpdate.REQUESTED -> 0
|
||||
CallManager.RingUpdate.EXPIRED_REQUEST -> 1
|
||||
CallManager.RingUpdate.ACCEPTED_ON_ANOTHER_DEVICE -> 2
|
||||
CallManager.RingUpdate.DECLINED_ON_ANOTHER_DEVICE -> 3
|
||||
CallManager.RingUpdate.BUSY_LOCALLY -> 4
|
||||
CallManager.RingUpdate.BUSY_ON_ANOTHER_DEVICE -> 5
|
||||
CallManager.RingUpdate.CANCELLED_BY_RINGER -> 6
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import org.thoughtcrime.securesms.database.AttachmentDatabase;
|
||||
import org.thoughtcrime.securesms.database.ChatColorsDatabase;
|
||||
import org.thoughtcrime.securesms.database.DraftDatabase;
|
||||
import org.thoughtcrime.securesms.database.EmojiSearchDatabase;
|
||||
import org.thoughtcrime.securesms.database.GroupCallRingDatabase;
|
||||
import org.thoughtcrime.securesms.database.GroupDatabase;
|
||||
import org.thoughtcrime.securesms.database.GroupReceiptDatabase;
|
||||
import org.thoughtcrime.securesms.database.IdentityDatabase;
|
||||
@@ -212,8 +213,9 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper implements SignalDatab
|
||||
private static final int THREAD_CLEANUP = 112;
|
||||
private static final int SESSION_MIGRATION = 113;
|
||||
private static final int IDENTITY_MIGRATION = 114;
|
||||
private static final int GROUP_CALL_RING_TABLE = 115;
|
||||
|
||||
private static final int DATABASE_VERSION = 114;
|
||||
private static final int DATABASE_VERSION = 115;
|
||||
private static final String DATABASE_NAME = "signal.db";
|
||||
|
||||
private final Context context;
|
||||
@@ -255,6 +257,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper implements SignalDatab
|
||||
db.execSQL(ChatColorsDatabase.CREATE_TABLE);
|
||||
db.execSQL(EmojiSearchDatabase.CREATE_TABLE);
|
||||
db.execSQL(AvatarPickerDatabase.CREATE_TABLE);
|
||||
db.execSQL(GroupCallRingDatabase.CREATE_TABLE);
|
||||
executeStatements(db, SearchDatabase.CREATE_TABLE);
|
||||
executeStatements(db, RemappedRecordsDatabase.CREATE_TABLE);
|
||||
executeStatements(db, MessageSendLogDatabase.CREATE_TABLE);
|
||||
@@ -272,6 +275,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper implements SignalDatab
|
||||
executeStatements(db, MentionDatabase.CREATE_INDEXES);
|
||||
executeStatements(db, PaymentDatabase.CREATE_INDEXES);
|
||||
executeStatements(db, MessageSendLogDatabase.CREATE_INDEXES);
|
||||
executeStatements(db, GroupCallRingDatabase.CREATE_INDEXES);
|
||||
|
||||
executeStatements(db, MessageSendLogDatabase.CREATE_TRIGGERS);
|
||||
|
||||
@@ -2016,6 +2020,11 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper implements SignalDatab
|
||||
Log.d(TAG, "Identity migration took " + (System.currentTimeMillis() - start) + " ms");
|
||||
}
|
||||
|
||||
if (oldVersion < GROUP_CALL_RING_TABLE) {
|
||||
db.execSQL("CREATE TABLE group_call_ring (_id INTEGER PRIMARY KEY, ring_id INTEGER UNIQUE, date_received INTEGER, ring_state INTEGER)");
|
||||
db.execSQL("CREATE INDEX date_received_index on group_call_ring (date_received)");
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
|
||||
Reference in New Issue
Block a user