Skip to content

Commit 7aa100c

Browse files
romtsnclaude
andcommitted
fix(gestures): Remove stale GestureDetectorCompat class availability check
UserInteractionIntegration gated itself on GestureDetectorCompat being available via classloader check, but SentryGestureDetector only uses Android SDK classes. Remove the check so the integration works without androidx.core. Also remove the stale proguard -keep rule. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d5baf94 commit 7aa100c

File tree

3 files changed

+11
-40
lines changed

3 files changed

+11
-40
lines changed

sentry-android-core/proguard-rules.pro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
##---------------Begin: proguard configuration for android-core ----------
22

33
##---------------Begin: proguard configuration for androidx.core ----------
4-
-keep class androidx.core.view.GestureDetectorCompat { <init>(...); }
54
-keep class androidx.core.app.FrameMetricsAggregator { <init>(...); }
65
-keep interface androidx.core.view.ScrollingView { *; }
76
##---------------End: proguard configuration for androidx.core ----------

sentry-android-core/src/main/java/io/sentry/android/core/UserInteractionIntegration.java

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,11 @@ public final class UserInteractionIntegration
2828
private @Nullable IScopes scopes;
2929
private @Nullable SentryAndroidOptions options;
3030

31-
private final boolean isAndroidXAvailable;
3231
private final boolean isAndroidxLifecycleAvailable;
3332

3433
public UserInteractionIntegration(
3534
final @NotNull Application application, final @NotNull io.sentry.util.LoadClass classLoader) {
3635
this.application = Objects.requireNonNull(application, "Application is required");
37-
isAndroidXAvailable =
38-
classLoader.isClassAvailable("androidx.core.view.GestureDetectorCompat", options);
3936
isAndroidxLifecycleAvailable =
4037
classLoader.isClassAvailable("androidx.lifecycle.Lifecycle", options);
4138
}
@@ -128,27 +125,19 @@ public void register(@NotNull IScopes scopes, @NotNull SentryOptions options) {
128125
.log(SentryLevel.DEBUG, "UserInteractionIntegration enabled: %s", integrationEnabled);
129126

130127
if (integrationEnabled) {
131-
if (isAndroidXAvailable) {
132-
application.registerActivityLifecycleCallbacks(this);
133-
this.options.getLogger().log(SentryLevel.DEBUG, "UserInteractionIntegration installed.");
134-
addIntegrationToSdkVersion("UserInteraction");
135-
136-
// In case of a deferred init, we hook into any resumed activity
137-
if (isAndroidxLifecycleAvailable) {
138-
final @Nullable Activity activity = CurrentActivityHolder.getInstance().getActivity();
139-
if (activity instanceof LifecycleOwner) {
140-
if (((LifecycleOwner) activity).getLifecycle().getCurrentState()
141-
== Lifecycle.State.RESUMED) {
142-
startTracking(activity);
143-
}
128+
application.registerActivityLifecycleCallbacks(this);
129+
this.options.getLogger().log(SentryLevel.DEBUG, "UserInteractionIntegration installed.");
130+
addIntegrationToSdkVersion("UserInteraction");
131+
132+
// In case of a deferred init, we hook into any resumed activity
133+
if (isAndroidxLifecycleAvailable) {
134+
final @Nullable Activity activity = CurrentActivityHolder.getInstance().getActivity();
135+
if (activity instanceof LifecycleOwner) {
136+
if (((LifecycleOwner) activity).getLifecycle().getCurrentState()
137+
== Lifecycle.State.RESUMED) {
138+
startTracking(activity);
144139
}
145140
}
146-
} else {
147-
options
148-
.getLogger()
149-
.log(
150-
SentryLevel.INFO,
151-
"androidx.core is not available, UserInteractionIntegration won't be installed");
152141
}
153142
}
154143
}

sentry-android-core/src/test/java/io/sentry/android/core/UserInteractionIntegrationTest.kt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,8 @@ class UserInteractionIntegrationTest {
3939

4040
fun getSut(
4141
callback: Window.Callback? = null,
42-
isAndroidXAvailable: Boolean = true,
4342
isLifecycleAvailable: Boolean = true,
4443
): UserInteractionIntegration {
45-
whenever(
46-
loadClass.isClassAvailable(
47-
eq("androidx.core.view.GestureDetectorCompat"),
48-
anyOrNull<SentryAndroidOptions>(),
49-
)
50-
)
51-
.thenReturn(isAndroidXAvailable)
5244
whenever(
5345
loadClass.isClassAvailable(
5446
eq("androidx.lifecycle.Lifecycle"),
@@ -99,15 +91,6 @@ class UserInteractionIntegrationTest {
9991
verify(fixture.application).unregisterActivityLifecycleCallbacks(any())
10092
}
10193

102-
@Test
103-
fun `when androidx is unavailable doesn't register a callback`() {
104-
val sut = fixture.getSut(isAndroidXAvailable = false)
105-
106-
sut.register(fixture.scopes, fixture.options)
107-
108-
verify(fixture.application, never()).registerActivityLifecycleCallbacks(any())
109-
}
110-
11194
@Test
11295
fun `registers window callback on activity resumed`() {
11396
val sut = fixture.getSut()

0 commit comments

Comments
 (0)