Repository navigation
fix(android): synchronize JNI initialization and declare greeting safety - #865
Conversation
…ing safety Git-Session-Id: c3c8da94-dbad-484a-96d4-d196650f3287
Review guide (auto-posted)Structured warm-up for reviewers — what changed, what to run, where to look. Key files
Suggested verification
Known risks / watch points
Suggested review focus
Generated by |
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryThis PR makes Android startup safe for simultaneous callers and states the safety requirements for the greeting function.
No actionable issues found. The host checks could not run here because Reviews (1) · Last reviewed commit: "fix(android): synchronize JNI logger ini..." · Reviewed by Greptile |
|
Greptile reviewed current head |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #865 +/- ##
===========================================
+ Coverage 70.81% 85.92% +15.11%
===========================================
Files 51 90 +39
Lines 2916 13105 +10189
===========================================
+ Hits 2065 11261 +9196
- Misses 851 1844 +993 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
CI-green and mergeable (Greptile 5/5) — waiting only on a maintainer click. This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted. |
🤖 AI code reviewReplaces the unsynchronized Safe to merge — no P0/P1 findingsConfidence 5/5 ✅ No thread-worthy findings. Advisory notes follow; they are retained without opening review threads. 2 advisory findings (summary-only, not scored)These P2 guard, heuristic, trade-off, or documentation claims are retained for judgment without opening review threads.
This is a How this was verified: static preflight: fix-commit + touched-files scan (rule 7)
The How this was verified: Compared the safety comment (lines 15-19) against the only in-repo caller (lines 93-97) and the greeting harness inputs (script lines 142-149, which use raw bytes, not JNI modified UTF-8). No code path in the diff validates JNI's NUL-termination guarantee. Consensus: 2/3 passes agreed — pass 1 looked and disagreed Files changed (3) — the diff as I read it
Reviewed Maintainer commands
|
Summary
static mut INITIALIZEDflag withstd::sync::Once. Concurrent callers wait until logger/panic-hook setup completes; repeat callers keep theAlready initializedlog and the per-call JNI workaround.call_once_forceso an initialization panic caught by the existing JNI guard does not permanently poison initialization: a later caller can retry as before.rust_greetingAPIunsafe extern "C"with a safety contract. Keep the live JNI string guard explicit at its caller. This does not change the C symbol or ABI, and aw-android still calls greeting throughRustInterface.sayHello.Reproduction
At current master
eed49e6, a host harness running the exact JNI initializer body with 16 simultaneous callers entered the initialization block 16 times and installed the panic hook 16 times. The final regression harness also fails against that original source.android_logger::init_oncehas its own guard, but the raw bool andlog_panics::initaround it are not synchronized.The regression covers one-time setup under concurrency, waiting for panic-hook installation before returning, repeat-call logging/JNI workaround, retry after a caught setup panic, and greeting allocation/reclamation for valid, empty and non-UTF-8 C strings. It is a host test, not an Android device runtime test; the real Android dependencies are checked separately.
Verification
python3 scripts/test-android-init.py— passes (original source fails).bash scripts/test-compile-android-cwd.sh— passes.cargo check --locked -p aw-server --lib --target aarch64-linux-android— passes with NDK 27.2/API 24 compiler, archiver and ranlib.cargo clippy --workspace --locked -- -D warnings— passes.cargo test --locked -p aw-server --lib— 108 passed, 1 ignored.cargo fmt --all -- --checkand Python Ruff check/format — pass.No device runtime verification claimed. The optional module-wide unsafe-operation lint is deliberately omitted to keep this scoped to the two unsafe API defects.