Fix issue where we could give storageIds to MMS groups or emails.
Things like force-unread and mute could be applied to MMS groups or unregistered users (the worst kind being email SMS contacts) that could result in crashes down the line. Includes a DB migration to clean up the bad stuff.
This commit is contained in:
parent
2f30d29351
commit
d58f68cb44
2 changed files with 17 additions and 2 deletions
|
@ -2662,12 +2662,17 @@ public class RecipientDatabase extends Database {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does not trigger any recipient refreshes -- it is assumed the caller handles this.
|
* Does not trigger any recipient refreshes -- it is assumed the caller handles this.
|
||||||
|
* Will *not* give storageIds to those that shouldn't get them (e.g. MMS groups, unregistered
|
||||||
|
* users).
|
||||||
*/
|
*/
|
||||||
void rotateStorageId(@NonNull RecipientId recipientId) {
|
void rotateStorageId(@NonNull RecipientId recipientId) {
|
||||||
ContentValues values = new ContentValues(1);
|
ContentValues values = new ContentValues(1);
|
||||||
values.put(STORAGE_SERVICE_ID, Base64.encodeBytes(StorageSyncHelper.generateKey()));
|
values.put(STORAGE_SERVICE_ID, Base64.encodeBytes(StorageSyncHelper.generateKey()));
|
||||||
|
|
||||||
databaseHelper.getWritableDatabase().update(TABLE_NAME, values, ID_WHERE, SqlUtil.buildArgs(recipientId));
|
String query = ID + " = ? AND (" + GROUP_TYPE + " IN (?, ?) OR " + REGISTERED + " = ?)";
|
||||||
|
String[] args = SqlUtil.buildArgs(recipientId, GroupType.SIGNAL_V1.getId(), GroupType.SIGNAL_V2.getId(), RegisteredState.REGISTERED.getId());
|
||||||
|
|
||||||
|
databaseHelper.getWritableDatabase().update(TABLE_NAME, values, query, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -179,8 +179,9 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper implements SignalDatab
|
||||||
private static final int CLEAN_STORAGE_IDS_WITHOUT_INFO = 95;
|
private static final int CLEAN_STORAGE_IDS_WITHOUT_INFO = 95;
|
||||||
private static final int CLEAN_REACTION_NOTIFICATIONS = 96;
|
private static final int CLEAN_REACTION_NOTIFICATIONS = 96;
|
||||||
private static final int STORAGE_SERVICE_REFACTOR = 97;
|
private static final int STORAGE_SERVICE_REFACTOR = 97;
|
||||||
|
private static final int CLEAR_MMS_STORAGE_IDS = 98;
|
||||||
|
|
||||||
private static final int DATABASE_VERSION = 97;
|
private static final int DATABASE_VERSION = 98;
|
||||||
private static final String DATABASE_NAME = "signal.db";
|
private static final String DATABASE_NAME = "signal.db";
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
@ -1438,6 +1439,15 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper implements SignalDatab
|
||||||
Log.d(TAG, String.format(Locale.US, "For storage service refactor migration, there were %d inserts, %d updated, and %d deletes. Cleared the dirty status on %d rows.", insertCount, updateCount, deleteCount, dirtyCount));
|
Log.d(TAG, String.format(Locale.US, "For storage service refactor migration, there were %d inserts, %d updated, and %d deletes. Cleared the dirty status on %d rows.", insertCount, updateCount, deleteCount, dirtyCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (oldVersion < CLEAR_MMS_STORAGE_IDS) {
|
||||||
|
ContentValues deleteValues = new ContentValues();
|
||||||
|
deleteValues.putNull("storage_service_key");
|
||||||
|
|
||||||
|
int deleteCount = db.update("recipient", deleteValues, "storage_service_key NOT NULL AND (group_type = 1 OR (group_type = 0 AND phone IS NULL AND uuid IS NULL))", null);
|
||||||
|
|
||||||
|
Log.d(TAG, "Cleared storageIds from " + deleteCount + " rows. They were either MMS groups or empty contacts.");
|
||||||
|
}
|
||||||
|
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
} finally {
|
} finally {
|
||||||
db.endTransaction();
|
db.endTransaction();
|
||||||
|
|
Loading…
Add table
Reference in a new issue