Skip to content

Commit

Permalink
recording: OnTouchEventListener try catch guard to swallow unexpected…
Browse files Browse the repository at this point in the history
… errors take 2 (#196)
  • Loading branch information
marandaneto authored Oct 9, 2024
1 parent e1a87f4 commit 629bcc1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 629bcc1

Please sign in to comment.