From 629bcc13cc2aa727d9c347acf2a60261c222a15a Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> Date: Wed, 9 Oct 2024 17:32:08 +0200 Subject: [PATCH] recording: OnTouchEventListener try catch guard to swallow unexpected errors take 2 (#196) --- CHANGELOG.md | 2 + .../replay/PostHogReplayIntegration.kt | 37 +++++++++++-------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1cad765..39975479 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Next +- recording: `OnTouchEventListener` try catch guard to swallow unexpected errors take 2 ([#196](https://github.com/PostHog/posthog-android/pull/196)) + ## 3.8.0 - 2024-10-03 - feat: add referrerURL automatically ([#186](https://github.com/PostHog/posthog-android/pull/186)) diff --git a/posthog-android/src/main/java/com/posthog/android/replay/PostHogReplayIntegration.kt b/posthog-android/src/main/java/com/posthog/android/replay/PostHogReplayIntegration.kt index 8fc3af64..70488127 100644 --- a/posthog-android/src/main/java/com/posthog/android/replay/PostHogReplayIntegration.kt +++ b/posthog-android/src/main/java/com/posthog/android/replay/PostHogReplayIntegration.kt @@ -75,7 +75,7 @@ import com.posthog.internal.replay.RRWireframe import com.posthog.internal.replay.capture import curtains.Curtains import curtains.OnRootViewsChangedListener -import curtains.OnTouchEventListener +import curtains.TouchEventInterceptor import curtains.onDecorViewReady import curtains.phoneWindow import curtains.touchEventInterceptors @@ -216,27 +216,34 @@ public class PostHogReplayIntegration( } private val onTouchEventListener = - OnTouchEventListener { motionEvent -> + TouchEventInterceptor { motionEvent, dispatch -> val timestamp = config.dateProvider.currentTimeMillis() - executor.submit { - try { - if (!isSessionReplayEnabled) { - return@submit - } - when (motionEvent.action.and(MotionEvent.ACTION_MASK)) { - MotionEvent.ACTION_DOWN -> { - generateMouseInteractions(timestamp, motionEvent, RRMouseInteraction.TouchStart) + try { + val state = dispatch(motionEvent) + + executor.submit { + try { + if (!isSessionReplayEnabled) { + return@submit } - MotionEvent.ACTION_UP -> { - generateMouseInteractions(timestamp, motionEvent, RRMouseInteraction.TouchEnd) + when (motionEvent.action.and(MotionEvent.ACTION_MASK)) { + MotionEvent.ACTION_DOWN -> { + generateMouseInteractions(timestamp, motionEvent, RRMouseInteraction.TouchStart) + } + MotionEvent.ACTION_UP -> { + generateMouseInteractions(timestamp, motionEvent, RRMouseInteraction.TouchEnd) + } } + } catch (e: Throwable) { + config.logger.log("Executor#OnTouchEventListener $motionEvent failed: $e.") } - } catch (e: Throwable) { - config.logger.log("OnTouchEventListener $motionEvent failed: $e.") } + state + } catch (e: Throwable) { + config.logger.log("TouchEventInterceptor $motionEvent failed: $e.") + throw e } - return@OnTouchEventListener } private fun generateMouseInteractions(