From 73feba72f5b20853550cfa40fc2af5b2bdc882ee Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Mon, 30 May 2022 13:02:02 +0200 Subject: [PATCH] Fix some notifications never getting dismissed Persisting notification info fails for non-null Uris: E NotificationEventPersistence: ## Failed to save cached notification info E NotificationEventPersistence: java.io.NotSerializableException: android.net.Uri$HierarchicalUri E NotificationEventPersistence: at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1240) E NotificationEventPersistence: at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1604) E NotificationEventPersistence: at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1565) E NotificationEventPersistence: at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1488) E NotificationEventPersistence: at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1234) E NotificationEventPersistence: at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:354) E NotificationEventPersistence: at java.util.ArrayList.writeObject(ArrayList.java:762) E NotificationEventPersistence: at java.lang.reflect.Method.invoke(Native Method) E NotificationEventPersistence: at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1036) E NotificationEventPersistence: at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1552) E NotificationEventPersistence: at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1488) E NotificationEventPersistence: at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1234) E NotificationEventPersistence: at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:354) E NotificationEventPersistence: at org.matrix.android.sdk.internal.session.securestorage.SecretStoringUtils.saveSecureObjectM(SecretStoringUtils.kt:283) E NotificationEventPersistence: at org.matrix.android.sdk.internal.session.securestorage.SecretStoringUtils.securelyStoreObject(SecretStoringUtils.kt:150) E NotificationEventPersistence: at org.matrix.android.sdk.internal.session.securestorage.DefaultSecureStorageService.securelyStoreObject(DefaultSecureStorageService.kt:27) E NotificationEventPersistence: at im.vector.app.features.notifications.NotificationEventPersistence.persistEvents(NotificationEventPersistence.kt:58) E NotificationEventPersistence: at im.vector.app.features.notifications.NotificationDrawerManager$persistEvents$1.invoke(NotificationDrawerManager.kt:183) E NotificationEventPersistence: at im.vector.app.features.notifications.NotificationDrawerManager$persistEvents$1.invoke(NotificationDrawerManager.kt:182) E NotificationEventPersistence: at im.vector.app.features.notifications.NotificationState.queuedEvents(NotificationState.kt:55) E NotificationEventPersistence: at im.vector.app.features.notifications.NotificationDrawerManager.persistEvents(NotificationDrawerManager.kt:182) E NotificationEventPersistence: at im.vector.app.features.notifications.NotificationDrawerManager.refreshNotificationDrawerBg(NotificationDrawerManager.kt:177) Accordingly, if a notification for an image is shown, and the notification state is loaded from storage later, none of the previously shown notifications will get dismissed once read. Change-Id: I2d6be497e8b92e770b680e16e42b3610add57323 --- .../app/features/notifications/NotifiableEventResolver.kt | 4 ++-- .../app/features/notifications/NotifiableMessageEvent.kt | 7 ++++++- .../notifications/NotificationBroadcastReceiver.kt | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt b/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt index b9d9261abe..acc4e5945b 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt @@ -151,7 +151,7 @@ class NotifiableEventResolver @Inject constructor( senderName = senderDisplayName, senderId = event.root.senderId, body = body.toString(), - imageUri = event.fetchImageIfPresent(session), + imageUriString = event.fetchImageIfPresent(session)?.toString(), roomId = event.root.roomId!!, roomName = roomName, matrixID = session.myUserId @@ -176,7 +176,7 @@ class NotifiableEventResolver @Inject constructor( senderName = senderDisplayName, senderId = event.root.senderId, body = body, - imageUri = event.fetchImageIfPresent(session), + imageUriString = event.fetchImageIfPresent(session)?.toString(), roomId = event.root.roomId!!, roomName = roomName, roomIsDirect = room.roomSummary()?.isDirect ?: false, diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotifiableMessageEvent.kt b/vector/src/main/java/im/vector/app/features/notifications/NotifiableMessageEvent.kt index d13e41daa8..68268739a0 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/NotifiableMessageEvent.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotifiableMessageEvent.kt @@ -27,7 +27,9 @@ data class NotifiableMessageEvent( val senderName: String?, val senderId: String?, val body: String?, - val imageUri: Uri?, + // We cannot use Uri? type here, as that could trigger a + // NotSerializableException when persisting this to storage + val imageUriString: String?, val roomId: String, val roomName: String?, val roomIsDirect: Boolean = false, @@ -45,4 +47,7 @@ data class NotifiableMessageEvent( val type: String = EventType.MESSAGE val description: String = body ?: "" val title: String = senderName ?: "" + + val imageUri: Uri? + get() = imageUriString?.let { Uri.parse(it) } } diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotificationBroadcastReceiver.kt b/vector/src/main/java/im/vector/app/features/notifications/NotificationBroadcastReceiver.kt index a4022f75c8..736b501772 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/NotificationBroadcastReceiver.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotificationBroadcastReceiver.kt @@ -145,7 +145,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { ?: context?.getString(R.string.notification_sender_me), senderId = session.myUserId, body = message, - imageUri = null, + imageUriString = null, roomId = room.roomId, roomName = room.roomSummary()?.displayName ?: room.roomId, roomIsDirect = room.roomSummary()?.isDirect == true,