[Android] Harden JNI resource ownership - #1525
Open
bmehta001 wants to merge 2 commits into
Open
Conversation
Fix normal Android JNI paths that could retain invalid pointers, leak JNI references, dispatch UUID context through the wrong overload, or publish partially initialized Privacy Guard state. Files changed: - lib/jni/LogManager_jni.cpp: validate string conversion, correct UUID context, and safely own debug callbacks. - lib/jni/JniConvertors.cpp: stop array conversion when JNI raises an exception. - lib/jni/PrivacyGuard_jni.cpp: co-own borrowed event names and fail before singleton publication. - lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/LogManagerProvider.java: reset listener identities after final removal. - lib/android_build/app/src/androidTest/java/com/microsoft/applications/events/maesdktest/LogManagerDDVUnitTest.java: cover listener identity reuse and release. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d7d2f27a-7339-4585-ad02-9f89ce20ef40
Pin JNI callbacks across reentrant dispatch, make add/remove registration transitions transactional, and atomically snapshot Privacy Guard state so teardown cannot race active users or commit partial JNI conversions. Files changed: - lib/callbacks/DebugSource.cpp: snapshot dispatch listeners and track pending callback lifetimes. - lib/callbacks/DebugSourceInternal.hpp: expose internal pending-listener cleanup hooks. - lib/jni/LogManager_jni.cpp: serialize listener state transitions without lock inversion and retain callbacks through dispatch. - lib/jni/PrivacyGuard_jni.cpp: publish atomic shared snapshots and reject partial conversion results. - tests/unittests/DebugEventSourceTests.cpp: cover reentrant removal during dispatch. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: de6b1234-574e-4b12-9f45-88ff809818ab
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.
Description
Harden normal Android JNI resource ownership and failure handling found during the repository-wide follow-up to #1523.
GUID_t; the previous code converted the UUID string but accidentally passed the Javajstring, selecting the booleanSetContextoverload.The listener changes follow the existing explicit lifecycle: callers remove debug listeners before closing their manager. This PR does not add support for concurrent or reentrant listener mutation.
Validation
MATSDK_WARNINGS_AS_ERRORS=ON, exempting only the pre-existingpessimizing-move,unused-variable, andsign-comparewarning categories.No Android device was connected, so the instrumentation APK was assembled but not executed.