Fix Android camera provider teardown race#318
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CameraManager.Disconnect()no-op once disposal has started, so queued disconnect work cannot run after dispose begins.ProcessCameraProviderwrapper during manager disposal; CameraX exposes this as a process-level provider, and disposing the managed Java peer can leave laterUnbindAll()calls with an invalid JNI peer.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 --nologodotnet restore BigIslandBarcode/BigIslandBarcode.csproj -p:TargetFramework=net10.0-android --nologodotnet build BigIslandBarcode/BigIslandBarcode.csproj -f net10.0-android -c Debug --no-restore --nologodotnet build BigIslandBarcode/BigIslandBarcode.csproj -f net10.0-android -c Debug --no-restore --nologo -p:EmbedAssembliesIntoApk=trueBigIslandBarcode, granted camera permission, verified camera opened, released, resumed, and released again withoutJavaProxyThrowable,JniPeerMembers, orUnbindAllcrash 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.