mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 08:39:22 +01:00
Fix tracking of created_at in SenderKeyDatabase.
This commit is contained in:
@@ -735,7 +735,7 @@ private static final String[] GROUP_PROJECTION = {
|
||||
List<UUID> removed = DecryptedGroupUtil.removedMembersUuidList(change);
|
||||
|
||||
if (removed.size() > 0) {
|
||||
Log.i(TAG, removed.size() + " members were removed from group " + groupId + ". Rotating the sender key.");
|
||||
Log.i(TAG, removed.size() + " members were removed from group " + groupId + ". Rotating the DistributionId " + distributionId);
|
||||
SenderKeyUtil.rotateOurKey(context, distributionId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,14 +54,31 @@ public class SenderKeyDatabase extends Database {
|
||||
public void store(@NonNull SignalProtocolAddress address, @NonNull DistributionId distributionId, @NonNull SenderKeyRecord record) {
|
||||
SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(ADDRESS, address.getName());
|
||||
values.put(DEVICE, address.getDeviceId());
|
||||
values.put(DISTRIBUTION_ID, distributionId.toString());
|
||||
values.put(RECORD, record.serialize());
|
||||
values.put(CREATED_AT, System.currentTimeMillis());
|
||||
db.beginTransaction();
|
||||
try {
|
||||
ContentValues updateValues = new ContentValues();
|
||||
updateValues.put(RECORD, record.serialize());
|
||||
|
||||
db.insertWithOnConflict(TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
String query = ADDRESS + " = ? AND " + DEVICE + " = ? AND " + DISTRIBUTION_ID + " = ?";
|
||||
String[] args = SqlUtil.buildArgs(address.getName(), address.getDeviceId(), distributionId);
|
||||
int updateCount = db.update(TABLE_NAME, updateValues, query, args);
|
||||
|
||||
if (updateCount <= 0) {
|
||||
Log.d(TAG, "New sender key " + distributionId + " from " + address);
|
||||
|
||||
ContentValues insertValues = new ContentValues();
|
||||
insertValues.put(ADDRESS, address.getName());
|
||||
insertValues.put(DEVICE, address.getDeviceId());
|
||||
insertValues.put(DISTRIBUTION_ID, distributionId.toString());
|
||||
insertValues.put(RECORD, record.serialize());
|
||||
insertValues.put(CREATED_AT, System.currentTimeMillis());
|
||||
db.insertWithOnConflict(TABLE_NAME, null, insertValues, SQLiteDatabase.CONFLICT_REPLACE);
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
public @Nullable SenderKeyRecord load(@NonNull SignalProtocolAddress address, @NonNull DistributionId distributionId) {
|
||||
|
||||
Reference in New Issue
Block a user