Skip to content

Fix Android camera provider teardown race#318

Merged
jfversluis merged 2 commits into
mainfrom
jfversluis-fix-android-camera-teardown-race
Jul 3, 2026
Merged

Fix Android camera provider teardown race#318
jfversluis merged 2 commits into
mainfrom
jfversluis-fix-android-camera-teardown-race

Conversation

@jfversluis

@jfversluis jfversluis commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Make Android CameraManager.Disconnect() no-op once disposal has started, so queued disconnect work cannot run after dispose begins.
  • Clear the CameraX provider reference before unbinding during disconnect/dispose so later teardown work cannot reuse the same provider field.
  • Stop disposing the ProcessCameraProvider wrapper during manager disposal; CameraX exposes this as a process-level provider, and disposing the managed Java peer can leave later UnbindAll() calls with an invalid JNI peer.
  • Keep shared handler Disconnect() calls intact so iOS, Mac Catalyst, and Windows continue to run their platform-specific cleanup paths.

Validation

  • dotnet test ZXing.Net.MAUI.Tests/ZXing.Net.MAUI.Tests.csproj --no-restore --nologo
  • dotnet restore BigIslandBarcode/BigIslandBarcode.csproj -p:TargetFramework=net10.0-android --nologo
  • dotnet build BigIslandBarcode/BigIslandBarcode.csproj -f net10.0-android -c Debug --no-restore --nologo
  • dotnet build BigIslandBarcode/BigIslandBarcode.csproj -f net10.0-android -c Debug --no-restore --nologo -p:EmbedAssembliesIntoApk=true
  • Android emulator smoke test: launched BigIslandBarcode, granted camera permission, verified camera opened, released, resumed, and released again without JavaProxyThrowable, JniPeerMembers, or UnbindAll crash signatures in logcat.

Note: the available emulator is Android SDK 30, so I could not reproduce the exact Android 15/Oppo Play Console crash locally.

jfversluis and others added 2 commits July 2, 2026 21:43
Avoid calling Disconnect immediately before Dispose from camera handlers so Android teardown only has one owner during handler disposal. Clear the CameraX provider before unbinding during disconnect/dispose to prevent queued teardown work from reusing the same Java peer.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Restore the shared handler Disconnect calls so iOS, Mac Catalyst, and Windows continue to run their platform cleanup paths. Keep the Android teardown race hardening, and stop disposing the CameraX ProcessCameraProvider singleton wrapper during manager disposal.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@jfversluis jfversluis changed the title Fix Android camera teardown race Fix Android camera provider teardown race Jul 3, 2026
@jfversluis jfversluis merged commit 667f579 into main Jul 3, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant