Skip to content

Commit a34dd38

Browse files
antonisclaude
andcommitted
fix(feedback): address PR review feedback
- Add @ApiStatus.Experimental to enableFeedbackOnShake/disableFeedbackOnShake - Add tests for runtime toggle (enable after init, disable after init) - Fix init() comment to accurately describe idempotent behavior - Fix javadoc on disableFeedbackOnShake to clarify behavior - Consolidate duplicate Features sections in changelog Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 52e392f commit a34dd38

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55
### Features
66

77
- Add `Sentry.enableFeedbackOnShake()` and `Sentry.disableFeedbackOnShake()` for runtime control of shake-to-report ([#5232](https://github.com/getsentry/sentry-java/pull/5232))
8-
9-
### Fixes
10-
11-
- Session Replay: Fix Compose text masking mismatch with weighted text ([#5218](https://github.com/getsentry/sentry-java/pull/5218))
12-
13-
### Features
14-
158
- Add configurable `IScopesStorageFactory` to `SentryOptions` for providing a custom `IScopesStorage`, e.g. when the default `ThreadLocal`-backed storage is incompatible with non-pinning thread models ([#5199](https://github.com/getsentry/sentry-java/pull/5199))
169
- Android: Add `beforeErrorSampling` callback to Session Replay ([#5214](https://github.com/getsentry/sentry-java/pull/5214))
1710
- Allows filtering which errors trigger replay capture before the `onErrorSampleRate` is checked
@@ -28,6 +21,10 @@
2821
}
2922
```
3023

24+
### Fixes
25+
26+
- Session Replay: Fix Compose text masking mismatch with weighted text ([#5218](https://github.com/getsentry/sentry-java/pull/5218))
27+
3128
### Dependencies
3229

3330
- Bump OpenTelemetry ([#5225](https://github.com/getsentry/sentry-java/pull/5225))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private void startShakeDetection(final @NotNull Activity activity) {
147147
if (options == null) {
148148
return;
149149
}
150-
// Lazily initialize sensor and thread on first use
150+
// Initialize sensor and thread if not already done (idempotent)
151151
shakeDetector.init(application, options.getLogger());
152152
// Stop any existing detection (e.g. when transitioning between activities)
153153
stopShakeDetection();

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,34 @@ class FeedbackShakeIntegrationTest {
102102
val sut = fixture.getSut()
103103
sut.close()
104104
}
105+
106+
@Test
107+
fun `enabling shake at runtime starts detection on next activity resume`() {
108+
val sut = fixture.getSut(useShakeGesture = false)
109+
sut.register(fixture.scopes, fixture.options)
110+
111+
whenever(fixture.activity.getSystemService(any())).thenReturn(null)
112+
113+
// Shake is disabled, onActivityResumed should not crash
114+
sut.onActivityResumed(fixture.activity)
115+
116+
// Now enable at runtime and resume a new activity
117+
fixture.options.feedbackOptions.isUseShakeGesture = true
118+
sut.onActivityResumed(fixture.activity)
119+
// Should not throw — shake detection attempted (fails gracefully with null SensorManager)
120+
}
121+
122+
@Test
123+
fun `disabling shake at runtime stops detection on next activity resume`() {
124+
val sut = fixture.getSut(useShakeGesture = true)
125+
sut.register(fixture.scopes, fixture.options)
126+
127+
whenever(fixture.activity.getSystemService(any())).thenReturn(null)
128+
sut.onActivityResumed(fixture.activity)
129+
130+
// Disable at runtime and resume
131+
fixture.options.feedbackOptions.isUseShakeGesture = false
132+
sut.onActivityResumed(fixture.activity)
133+
// Should not throw — detection stopped gracefully
134+
}
105135
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,16 +1373,18 @@ public static void showUserFeedbackDialog(
13731373

13741374
/**
13751375
* Enables shake-to-report for user feedback. When enabled, shaking the device will show the
1376-
* feedback dialog. This can be toggled at runtime.
1376+
* feedback dialog. Takes effect on the next activity transition. This can be toggled at runtime.
13771377
*/
1378+
@ApiStatus.Experimental
13781379
public static void enableFeedbackOnShake() {
13791380
getCurrentScopes().getOptions().getFeedbackOptions().setUseShakeGesture(true);
13801381
}
13811382

13821383
/**
1383-
* Disables shake-to-report for user feedback. Shake detection will stop on the next activity
1384-
* transition.
1384+
* Disables shake-to-report for user feedback. Takes effect on the next activity transition. If a
1385+
* shake occurs before the transition, the dialog will not be shown.
13851386
*/
1387+
@ApiStatus.Experimental
13861388
public static void disableFeedbackOnShake() {
13871389
getCurrentScopes().getOptions().getFeedbackOptions().setUseShakeGesture(false);
13881390
}

0 commit comments

Comments
 (0)