From 6ed549cfb20d656d809ef9fbd2527aa513f70c15 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Tue, 1 Aug 2017 14:49:16 -0700 Subject: [PATCH] If two recipient ids get canonicalized to the same thing, drop one There's not a great way for me to know which of them is the "real" entry, which means that I could be deleting the wrong one. In the case of recipient "preferences," it's hopefully not a huge loss, and there aren't any other great options. Fixes #6838 // FREEBIE --- .../thoughtcrime/securesms/database/DatabaseFactory.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/org/thoughtcrime/securesms/database/DatabaseFactory.java b/src/org/thoughtcrime/securesms/database/DatabaseFactory.java index fa1770f89f..da2f1eb373 100644 --- a/src/org/thoughtcrime/securesms/database/DatabaseFactory.java +++ b/src/org/thoughtcrime/securesms/database/DatabaseFactory.java @@ -19,6 +19,7 @@ package org.thoughtcrime.securesms.database; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; +import android.database.sqlite.SQLiteConstraintException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; @@ -997,7 +998,13 @@ public class DatabaseFactory { ContentValues values = new ContentValues(1); values.put("recipient_ids", Util.join(addresses, " ")); - db.update("recipient_preferences", values, "_id = ?", new String[] {String.valueOf(id)}); + + try { + db.update("recipient_preferences", values, "_id = ?", new String[] {String.valueOf(id)}); + } catch (SQLiteConstraintException e) { + Log.w(TAG, e); + db.delete("recipient_preference", "_id = ?", new String[] {String.valueOf(id)}); + } } if (cursor != null) cursor.close();