Skip to content

fix(android): stop ServiceBound disposing the caller's context - #4514

Merged
glennawatson merged 1 commit into
mainfrom
fix/android-servicebound-context
Sep 26, 2026
Merged

glennawatson merged 1 commit into
mainfrom
fix/android-servicebound-context

Conversation

@glennawatson

Copy link
Copy Markdown
Contributor

Summary

Disposing a ContextExtensions.ServiceBound subscription unbinds the service and leaves the caller's Context alone.

  • The service connection no longer disposes the context it binds through. It only unbinds. The caller owns the context, which is usually its own activity.

Why

Ending the subscription disposed the caller's managed Context, so its Handle became zero and the object could no longer be used.

Closes #4511

Breaking changes

None.

How this was verified

A device test binds a local service through the app context, disposes the subscription, and checks that the context still works.

  • It failed on the Android emulator before the change and passes after it.
  • The existing service-binding tests now pass the app context directly instead of a ContextWrapper.

Notes for the reviewer

The change is in the private ServiceConnection<TBinder>.

  • The connection now reads the context from its primary constructor parameter instead of a field, since it does not own the context and never disposes it.
  • Android code is outside the Sonar coverage run, so the device tests are the coverage for these lines.

Checklist

  • I have read the Contribute guide
  • The PR title follows Conventional Commits
  • Tests cover this change, or the summary says why they do not
  • New or changed public API has XML documentation

@codecov

codecov Bot commented Sep 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.62%. Comparing base (dde34a2) to head (b1cb12e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4514   +/-   ##
=======================================
  Coverage   93.62%   93.62%           
=======================================
  Files         175      175           
  Lines        6227     6227           
  Branches      743      743           
=======================================
  Hits         5830     5830           
  Misses        396      396           
  Partials        1        1           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud

Copy link
Copy Markdown

@glennawatson
glennawatson merged commit a579b33 into main Sep 26, 2026
17 of 18 checks passed
@glennawatson
glennawatson deleted the fix/android-servicebound-context branch September 26, 2026 13:22
@github-actions

Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ContextExtensions.ServiceBound disposes the caller's Context when the subscription ends

1 participant

⌂ 换网址