From 222201cc645e69a125b80da0f27268780c5b2430 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 12 Jul 2019 14:40:35 +0200 Subject: [PATCH 1/2] 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 411a6c83..a01b7416 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 97d3a67c..e145a4fb 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") } } From 0289d2ee87b28b9e5f699954d0c2c4a76aac05c8 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 12 Jul 2019 14:50:33 +0200 Subject: [PATCH 2/2] Simpler code --- .../notifications/NotificationDrawerManager.kt | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) 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 e145a4fb..72a9e1e3 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 @@ -60,7 +60,7 @@ class NotificationDrawerManager @Inject constructor(private val context: Context //The first time the notification drawer is refreshed, we force re-render of all notifications private var firstTime = true - private var eventList = loadEventInfo() + private val eventList = loadEventInfo() private val avatarSize = context.resources.getDimensionPixelSize(R.dimen.profile_avatar_size) @@ -123,10 +123,7 @@ class NotificationDrawerManager @Inject constructor(private val context: Context if (roomId != null) { synchronized(eventList) { eventList.removeAll { e -> - if (e is NotifiableMessageEvent) { - return@removeAll e.roomId == roomId - } - return@removeAll false + e is NotifiableMessageEvent && e.roomId == roomId } } NotificationUtils.cancelNotificationMessage(context, roomId, ROOM_MESSAGES_NOTIFICATION_ID) @@ -152,7 +149,8 @@ class NotificationDrawerManager @Inject constructor(private val context: Context fun homeActivityDidResume(matrixID: String?) { synchronized(eventList) { eventList.removeAll { e -> - return@removeAll e !is NotifiableMessageEvent //messages are cleared when entering room + // messages are cleared when entering room + e !is NotifiableMessageEvent } } } @@ -160,10 +158,7 @@ class NotificationDrawerManager @Inject constructor(private val context: Context fun clearMemberShipNotificationForRoom(roomId: String) { synchronized(eventList) { eventList.removeAll { e -> - if (e is InviteNotifiableEvent) { - return@removeAll e.roomId == roomId - } - return@removeAll false + e is InviteNotifiableEvent && e.roomId == roomId } } }