Skip to content

Commit afdc825

Browse files
committed
Fix GestureDetectorCompat crashes if initialized from background thread
1 parent 7d49fce commit afdc825

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryWindowCallback.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.sentry.android.core.internal.gestures;
22

33
import android.content.Context;
4+
import android.os.Handler;
5+
import android.os.Looper;
46
import android.view.MotionEvent;
57
import android.view.Window;
68
import androidx.core.view.GestureDetectorCompat;
@@ -27,7 +29,7 @@ public SentryWindowCallback(
2729
final @Nullable SentryOptions options) {
2830
this(
2931
delegate,
30-
new GestureDetectorCompat(context, gestureListener),
32+
new GestureDetectorCompat(context, gestureListener, new Handler(Looper.getMainLooper())),
3133
gestureListener,
3234
options,
3335
new MotionEventObtainer() {});

sentry/src/main/java/io/sentry/Sentry.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,16 @@ private static void init(final @NotNull SentryOptions options, final boolean glo
345345
// and Scopes was still NoOp.
346346
// Registering integrations here make sure that Scopes is already created.
347347
for (final Integration integration : options.getIntegrations()) {
348-
integration.register(ScopesAdapter.getInstance(), options);
348+
try {
349+
integration.register(ScopesAdapter.getInstance(), options);
350+
} catch (Throwable t) {
351+
options
352+
.getLogger()
353+
.log(
354+
SentryLevel.WARNING,
355+
"Failed to register the integration " + integration.getClass().getName(),
356+
t);
357+
}
349358
}
350359

351360
notifyOptionsObservers(options);

0 commit comments

Comments
 (0)