From 222201cc645e69a125b80da0f27268780c5b2430 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 12 Jul 2019 14:40:35 +0200 Subject: [PATCH] Fix crash observe on the PlayStore (#341) --- CHANGES.md | 1 + .../NotificationDrawerManager.kt | 34 +++++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 411a6c83d7..a01b74169b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ Other changes: Bugfix: - Fix regression on permalink click + - Fix crash reported by the PlayStore (#341) Translations: - diff --git a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationDrawerManager.kt b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationDrawerManager.kt index 97d3a67cef..e145a4fb1c 100644 --- a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationDrawerManager.kt +++ b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationDrawerManager.kt @@ -121,11 +121,13 @@ class NotificationDrawerManager @Inject constructor(private val context: Context Timber.v("clearMessageEventOfRoom $roomId") if (roomId != null) { - eventList.removeAll { e -> - if (e is NotifiableMessageEvent) { - return@removeAll e.roomId == roomId + synchronized(eventList) { + eventList.removeAll { e -> + if (e is NotifiableMessageEvent) { + return@removeAll e.roomId == roomId + } + return@removeAll false } - return@removeAll false } NotificationUtils.cancelNotificationMessage(context, roomId, ROOM_MESSAGES_NOTIFICATION_ID) } @@ -433,18 +435,20 @@ class NotificationDrawerManager @Inject constructor(private val context: Context fun persistInfo() { - if (eventList.isEmpty()) { - deleteCachedRoomNotifications(context) - return - } - try { - val file = File(context.applicationContext.cacheDir, ROOMS_NOTIFICATIONS_FILE_NAME) - if (!file.exists()) file.createNewFile() - FileOutputStream(file).use { - SecretStoringUtils.securelyStoreObject(eventList, "notificationMgr", it, this.context) + synchronized(eventList) { + if (eventList.isEmpty()) { + deleteCachedRoomNotifications(context) + return + } + try { + val file = File(context.applicationContext.cacheDir, ROOMS_NOTIFICATIONS_FILE_NAME) + if (!file.exists()) file.createNewFile() + FileOutputStream(file).use { + SecretStoringUtils.securelyStoreObject(eventList, "notificationMgr", it, this.context) + } + } catch (e: Throwable) { + Timber.e(e, "## Failed to save cached notification info") } - } catch (e: Throwable) { - Timber.e(e, "## Failed to save cached notification info") } }