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 @@ -25,6 +25,7 @@
- Session Replay: Send Ktor client network request start and end times in milliseconds, so the requests line up with the replay ([#6619](https://github.com/getsentry/sentry-java/pull/6619))
- Nav3: Stop attributing errors and spans from an Activity or ViewPager2 page without a `SentryNavEffect` to the most recently visited Nav3 root ([#6483](https://github.com/getsentry/sentry-java/pull/6483))
- Android: Count deep sleep in breadcrumb, screenshot and view hierarchy debounce windows, so the first low-memory or battery breadcrumb after a long Doze is no longer dropped ([#6590](https://github.com/getsentry/sentry-java/pull/6590))
- Android: Register network callbacks on API 24–25 when `AndroidConnectionStatusProvider` is created with a custom `Handler`, instead of failing because the `Handler` overload needs API 26 ([#6634](https://github.com/getsentry/sentry-java/pull/6634))

### Dependencies

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,8 @@ static boolean registerNetworkCallback(
return false;
}
try {
if (handler != null) {
// The Handler overload is API 26+. Below that, fall back to the default callback thread.
if (handler != null && buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.O) {
connectivityManager.registerDefaultNetworkCallback(networkCallback, handler);
} else {
connectivityManager.registerDefaultNetworkCallback(networkCallback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ class AndroidConnectionStatusProviderTest {
@Test
fun `registerNetworkCallback with a custom handlers calls connectivityManager with it`() {
val customHandler = object : Handler(Looper.getMainLooper()) {}
whenever(buildInfo.sdkInfoVersion).thenReturn(Build.VERSION_CODES.O)
whenever(contextMock.getSystemService(any())).thenReturn(connectivityManager)
AndroidConnectionStatusProvider.registerNetworkCallback(
contextMock,
Expand All @@ -999,4 +1000,25 @@ class AndroidConnectionStatusProviderTest {
verify(connectivityManager)
.registerDefaultNetworkCallback(any<NetworkCallback>(), argThat { this == customHandler })
}

@Test
fun `registerNetworkCallback with a custom handler below API 26 registers without it`() {
val customHandler = object : Handler(Looper.getMainLooper()) {}
val callback = mock<NetworkCallback>()
whenever(buildInfo.sdkInfoVersion).thenReturn(Build.VERSION_CODES.N_MR1)
whenever(contextMock.getSystemService(any())).thenReturn(connectivityManager)
val registered =
AndroidConnectionStatusProvider.registerNetworkCallback(
contextMock,
logger,
buildInfo,
customHandler,
callback,
)

assertThat(registered).isTrue()
verify(connectivityManager).registerDefaultNetworkCallback(callback)
verify(connectivityManager, never())
.registerDefaultNetworkCallback(eq(callback), any<Handler>())
}
}
Loading