Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### Fixes

- Kotlin now sees `Attachment.getBytes()`, `Device.getArchs()`, `Spring.getActiveProfiles()` and `JsonSerializationUtils.bytesFrom(...)` as nullable, because `@Nullable` now annotates the returned array instead of its elements ([#6558](https://github.com/getsentry/sentry-java/pull/6558))
- Shake-to-report no longer leaks the first Activity that resumes after `Sentry.init` ([#6686](https://github.com/getsentry/sentry-java/pull/6686))

## 8.65.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ private synchronized void init(final @NotNull Context context) {
return;
}
if (sensorManager == null) {
sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
// An Activity's SensorManager holds on to that Activity, and the cached manager outlives it.
sensorManager =
(SensorManager)
ContextUtils.getApplicationContext(context).getSystemService(Context.SENSOR_SERVICE);
}
if (sensorManager != null && accelerometer == null) {
accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ class SentryShakeDetectorTest {
)
}

@Test
fun `resolves SensorManager from the application context`() {
val activityContext = mock<Context>()
whenever(activityContext.applicationContext).thenReturn(fixture.context)

val sut = fixture.getSut()
sut.start(activityContext, fixture.listener)

verify(activityContext, never()).getSystemService(any<String>())
verify(fixture.sensorManager)
.registerListener(
eq(sut),
eq(fixture.accelerometer),
eq(SensorManager.SENSOR_DELAY_NORMAL),
isA<Handler>(),
)
}

@Test
fun `unregisters sensor listener on stop`() {
val sut = fixture.getSut()
Expand Down
Loading