Skip to content

Commit 99cea60

Browse files
committed
Fix deletion of random SMS when trying to update threads
Commit 44c540b (Fixed updating last message after deleting (#167), 2021-09-04) introduced a hack to update the conversation snippet, however there is a bug in that code: it tries to delete by thread ID, but the condition is applied to the SMS table, not to the threads table.[1] So instead of deleting the thread with that ID, it deletes whichever SMS happens to have that ID. The fix is to change the condition to an always-false condition, so that no messages will be deleted. The threads will still get updated.[2] Fixes #148. [1] https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/android14-release/src/com/android/providers/telephony/MmsSmsProvider.java#1405 [2] https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/android14-release/src/com/android/providers/telephony/MmsSmsProvider.java#1409
1 parent 1c7376c commit 99cea60

File tree

1 file changed

+5
-3
lines changed
  • app/src/main/kotlin/org/fossify/messages/extensions

1 file changed

+5
-3
lines changed

app/src/main/kotlin/org/fossify/messages/extensions/Context.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -990,11 +990,13 @@ fun Context.deleteSmsDraft(threadId: Long) {
990990
}
991991

992992
fun Context.updateLastConversationMessage(threadId: Long) {
993+
// update the date and the snippet of the thread, by triggering the
994+
// following Android code (which runs even if no messages are deleted):
995+
// https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/android14-release/src/com/android/providers/telephony/MmsSmsProvider.java#1409
993996
val uri = Threads.CONTENT_URI
994-
val selection = "${Threads._ID} = ?"
995-
val selectionArgs = arrayOf(threadId.toString())
997+
val selection = "1 = 0" // always-false condition, because we don't actually want to delete any messages
996998
try {
997-
contentResolver.delete(uri, selection, selectionArgs)
999+
contentResolver.delete(uri, selection, null)
9981000
val newConversation = getConversations(threadId)[0]
9991001
insertOrUpdateConversation(newConversation)
10001002
} catch (e: Exception) {

0 commit comments

Comments
 (0)