From 8b8a4f3d7be1eee231f27a399c052f4a090cb63b Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Thu, 28 Jul 2022 16:51:11 +0200 Subject: [PATCH 1/4] Fixing missing clear on audio tracker listeners --- .../im/vector/app/features/home/room/detail/TimelineFragment.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt index 8f9564789a..62677ce9ef 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt @@ -966,6 +966,7 @@ class TimelineFragment @Inject constructor( override fun onDestroyView() { audioMessagePlaybackTracker.makeAllPlaybacksIdle() + audioMessagePlaybackTracker.clear() lazyLoadedViews.unBind() timelineEventController.callback = null timelineEventController.removeModelBuildListener(modelBuildListener) From 018772ca9a8f1fbcce92e73fc8310d06e590816a Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Thu, 28 Jul 2022 16:57:08 +0200 Subject: [PATCH 2/4] Adding changelog entry --- changelog.d/6678.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/6678.misc diff --git a/changelog.d/6678.misc b/changelog.d/6678.misc new file mode 100644 index 0000000000..a7a53257d8 --- /dev/null +++ b/changelog.d/6678.misc @@ -0,0 +1 @@ +[Timeline] Memory leak in audio message playback tracker From 81cba3d27520bee6acd311e38cd8c6b977d6b138 Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Fri, 29 Jul 2022 09:44:23 +0200 Subject: [PATCH 3/4] Using ViewModel to handle clearing of audio controller --- .../vector/app/features/home/room/detail/TimelineFragment.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt index 62677ce9ef..220893b31c 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt @@ -965,8 +965,7 @@ class TimelineFragment @Inject constructor( } override fun onDestroyView() { - audioMessagePlaybackTracker.makeAllPlaybacksIdle() - audioMessagePlaybackTracker.clear() + messageComposerViewModel.handle(MessageComposerAction.EndAllVoiceActions()) lazyLoadedViews.unBind() timelineEventController.callback = null timelineEventController.removeModelBuildListener(modelBuildListener) @@ -1099,7 +1098,7 @@ class TimelineFragment @Inject constructor( else -> state.isAllowedToManageWidgets } menu.findItem(R.id.video_call).icon?.alpha = if (callButtonsEnabled) 0xFF else 0x40 - menu.findItem(R.id.voice_call).icon?.alpha = if (callButtonsEnabled || state.hasActiveElementCallWidget()) 0xFF else 0x40 + menu.findItem(R.id.voice_call).icon?.alpha = if (callButtonsEnabled || state.hasActiveElementCallWidget()) 0xFF else 0x40 val matrixAppsMenuItem = menu.findItem(R.id.open_matrix_apps) val widgetsCount = state.activeRoomWidgets.invoke()?.size ?: 0 From 64c25f073ce82eddc9c431798f8c88e5852eb0ec Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Mon, 1 Aug 2022 09:35:29 +0200 Subject: [PATCH 4/4] Calling directly the ViewModel clear method instead of using a view action --- .../vector/app/features/home/room/detail/TimelineFragment.kt | 2 +- .../home/room/detail/composer/MessageComposerAction.kt | 1 - .../home/room/detail/composer/MessageComposerViewModel.kt | 3 +-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt index 220893b31c..f164183914 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt @@ -965,7 +965,7 @@ class TimelineFragment @Inject constructor( } override fun onDestroyView() { - messageComposerViewModel.handle(MessageComposerAction.EndAllVoiceActions()) + messageComposerViewModel.endAllVoiceActions() lazyLoadedViews.unBind() timelineEventController.callback = null timelineEventController.removeModelBuildListener(modelBuildListener) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerAction.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerAction.kt index 0da324ffc2..527f42a67a 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerAction.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerAction.kt @@ -41,7 +41,6 @@ sealed class MessageComposerAction : VectorViewModelAction { object PauseRecordingVoiceMessage : MessageComposerAction() data class PlayOrPauseVoicePlayback(val eventId: String, val messageAudioContent: MessageAudioContent) : MessageComposerAction() object PlayOrPauseRecordingPlayback : MessageComposerAction() - data class EndAllVoiceActions(val deleteRecord: Boolean = true) : MessageComposerAction() data class VoiceWaveformTouchedUp(val eventId: String, val duration: Int, val percentage: Float) : MessageComposerAction() data class VoiceWaveformMovedTo(val eventId: String, val duration: Int, val percentage: Float) : MessageComposerAction() data class AudioSeekBarMovedTo(val eventId: String, val duration: Int, val percentage: Float) : MessageComposerAction() diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt index ce4235a825..ca86010915 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt @@ -107,7 +107,6 @@ class MessageComposerViewModel @AssistedInject constructor( is MessageComposerAction.PlayOrPauseVoicePlayback -> handlePlayOrPauseVoicePlayback(action) MessageComposerAction.PauseRecordingVoiceMessage -> handlePauseRecordingVoiceMessage() MessageComposerAction.PlayOrPauseRecordingPlayback -> handlePlayOrPauseRecordingPlayback() - is MessageComposerAction.EndAllVoiceActions -> handleEndAllVoiceActions(action.deleteRecord) is MessageComposerAction.InitializeVoiceRecorder -> handleInitializeVoiceRecorder(action.attachmentData) is MessageComposerAction.OnEntersBackground -> handleEntersBackground(action.composerText) is MessageComposerAction.VoiceWaveformTouchedUp -> handleVoiceWaveformTouchedUp(action) @@ -887,7 +886,7 @@ class MessageComposerViewModel @AssistedInject constructor( audioMessageHelper.startOrPauseRecordingPlayback() } - private fun handleEndAllVoiceActions(deleteRecord: Boolean) { + fun endAllVoiceActions(deleteRecord: Boolean = true) { audioMessageHelper.clearTracker() audioMessageHelper.stopAllVoiceActions(deleteRecord) }