Commit 2fcda64
fix(gestures): Thread-safe SentryGestureDetector with per-gesture VelocityTracker recycle (#5301)
* fix(gestures): Recycle VelocityTracker per gesture and guard state with a lock
Recycle VelocityTracker on every ACTION_UP/ACTION_CANCEL instead of only when the detector is torn down, so the pooled native tracker isn't held across gestures (matches Android's framework GestureDetector behavior). Merges endGesture() and release() into a single recycle() method.
Guard onTouchEvent and recycle with an AutoClosableReentrantLock — SentryWindowCallback.stopTracking() can be invoked from a bg thread via Sentry.close(), which would otherwise race with the UI thread's touch dispatch and cause use-after-recycle on the native MotionEvent/VelocityTracker pools. recycle() captures the native handles under the lock and performs the JNI recycle() calls outside it to keep the bg thread's critical section to a pointer swap.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* changelog
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 952b180 commit 2fcda64Copy full SHA for 2fcda64
4 files changed
+119-87Lines changed: 119 additions & 87 deletions
File tree
Expand file treeCollapse file tree
Open diff view settings
Filter options
- sentry-android-core/src
- main/java/io/sentry/android/core/internal/gestures
- test/java/io/sentry/android/core/internal/gestures
Expand file treeCollapse file tree
Open diff view settings
Collapse file
+2-1Lines changed: 2 additions & 1 deletion
- Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
6 | 6 | |
7 | 7 | |
8 | 8 | |
| 9 | + |
| 10 | + |
9 | 11 | |
10 | 12 | |
11 | 13 | |
| ||
27 | 29 | |
28 | 30 | |
29 | 31 | |
30 | | - |
31 | 32 | |
32 | 33 | |
33 | 34 | |
|
Collapse file
sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryGestureDetector.java
Copy file name to clipboardExpand all lines: sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryGestureDetector.java+88-85Lines changed: 88 additions & 85 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
5 | 5 | |
6 | 6 | |
7 | 7 | |
| 8 | + |
| 9 | + |
8 | 10 | |
9 | 11 | |
10 | 12 | |
| ||
35 | 37 | |
36 | 38 | |
37 | 39 | |
| 40 | + |
| 41 | + |
38 | 42 | |
39 | 43 | |
40 | 44 | |
| ||
46 | 50 | |
47 | 51 | |
48 | 52 | |
49 | | - |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
50 | 74 | |
51 | | - |
52 | | - |
53 | | - |
| 75 | + |
| 76 | + |
54 | 77 | |
55 | | - |
56 | | - |
57 | | - |
58 | | - |
59 | | - |
60 | | - |
61 | | - |
62 | | - |
63 | | - |
64 | | - |
65 | | - |
66 | | - |
67 | | - |
68 | | - |
69 | | - |
70 | | - |
71 | | - |
72 | | - |
73 | | - |
74 | | - |
75 | | - |
76 | | - |
77 | | - |
78 | | - |
79 | | - |
80 | | - |
81 | | - |
82 | | - |
83 | | - |
84 | | - |
85 | | - |
86 | | - |
87 | | - |
88 | | - |
89 | | - |
90 | | - |
91 | | - |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
92 | 95 | |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | + |
93 | 104 | |
94 | | - |
95 | | - |
96 | | - |
97 | | - |
98 | | - |
99 | | - |
100 | | - |
101 | | - |
102 | | - |
103 | | - |
104 | | - |
105 | | - |
106 | | - |
107 | | - |
108 | | - |
109 | | - |
110 | | - |
111 | | - |
112 | | - |
113 | | - |
114 | | - |
115 | | - |
116 | | - |
117 | | - |
118 | | - |
119 | | - |
120 | | - |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | + |
121 | 110 | |
122 | | - |
123 | | - |
124 | | - |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | + |
125 | 126 | |
126 | | - |
127 | | - |
128 | | - |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | + |
129 | 131 | |
130 | 132 | |
131 | 133 | |
132 | | - |
133 | | - |
134 | | - |
135 | | - |
136 | | - |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | + |
| 140 | + |
137 | 141 | |
138 | 142 | |
139 | | - |
140 | | - |
141 | | - |
142 | | - |
143 | | - |
144 | | - |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | + |
| 147 | + |
145 | 148 | |
146 | 149 | |
147 | 150 | |
Collapse file
sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryWindowCallback.java
Copy file name to clipboardExpand all lines: sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryWindowCallback.java+1-1Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
81 | 81 | |
82 | 82 | |
83 | 83 | |
84 | | - |
| 84 | + |
85 | 85 | |
86 | 86 | |
87 | 87 | |
|
Collapse file
sentry-android-core/src/test/java/io/sentry/android/core/internal/gestures/SentryGestureDetectorTest.kt
Copy file name to clipboardExpand all lines: sentry-android-core/src/test/java/io/sentry/android/core/internal/gestures/SentryGestureDetectorTest.kt+28Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
322 | 322 | |
323 | 323 | |
324 | 324 | |
| 325 | + |
| 326 | + |
| 327 | + |
| 328 | + |
| 329 | + |
| 330 | + |
| 331 | + |
| 332 | + |
| 333 | + |
| 334 | + |
| 335 | + |
| 336 | + |
| 337 | + |
| 338 | + |
| 339 | + |
| 340 | + |
| 341 | + |
| 342 | + |
| 343 | + |
| 344 | + |
| 345 | + |
| 346 | + |
| 347 | + |
| 348 | + |
| 349 | + |
| 350 | + |
| 351 | + |
| 352 | + |
325 | 353 | |
326 | 354 | |
327 | 355 | |
|
0 commit comments