chore(android): port NeurophoneService Kotlin→Java JNI shim (#83)#123
Open
hyperpolymath wants to merge 2 commits into
Open
chore(android): port NeurophoneService Kotlin→Java JNI shim (#83)#123hyperpolymath wants to merge 2 commits into
hyperpolymath wants to merge 2 commits into
Conversation
Replace the Kotlin foreground Service with a minimal hand-written Java Service shim that delegates all business logic to Rust via the neurophone-android JNI boundary. The shim: - onCreate -> NativeLib.init(null) + NativeLib.start() - onDestroy -> NativeLib.stop() - streams sensor events via NativeLib.processSensor(typeId, values, timestampNs, accuracy) Replicates the prior Kotlin convenience mapping (sensor type -> id: accelerometer=1, magnetometer=2, gyroscope=4, light=5, proximity=8, else=0) and the ms->ns timestamp conversion. Synthetic salience and widget publishing are dropped; those now belong to Rust. Hand-written Java is permitted only under android/ (exempt via .hypatia-baseline.json). Integration seams marked TODO(#83 rebase) pending sub-PR #3 (Gossamer scaffolding) and #4 (NativeLib->Rust JNI). No Rust/Cargo files touched; cargo workspace behaviour unchanged. https://claude.ai/code/session_01Gu1JFCZHuBtBhAWPr4sMQw
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.
Sub-PR #5 — Port
NeurophoneService(Kotlin → Java JNI shim)Part of the Android Kotlin→Rust/Gossamer migration: epic #83, RFC PR #97, sub-issue #111.
What changed
android/app/src/main/java/ai/neurophone/NeurophoneService.kt(Kotlin foreground service that carried business logic + synthetic salience + widget publishing).android/app/src/main/java/ai/neurophone/NeurophoneService.java— a minimal hand-written JavaServiceshim. Same class name (ai.neurophone.NeurophoneService), so the existingBootReceiver.kt,widget/NeurophoneAppWidget.kt, and theAndroidManifest.xml.NeurophoneServiceentry resolve to it unchanged.JNI calls used (
NativeLib, Kotlinobject→NativeLib.INSTANCE)onCreate()→NativeLib.init(null)thenNativeLib.start()onDestroy()→NativeLib.stop()onSensorChanged()→NativeLib.processSensor(typeId, values, timestampNs, accuracy)All JNI calls are wrapped in
try/catch (Throwable)so dev hardware without the native lib still runs (matches prior Kotlin behaviour).Convenience mapping replicated
Sensor type → compact id (mirrors the old
NativeLib.pushSensorEventtable):Timestamp converted ms → ns (
System.currentTimeMillis() * 1_000_000L). Accuracy defaults to3(SENSOR_STATUS_ACCURACY_HIGH).Kept thin (in scope)
Business logic stays in Rust. The shim keeps only the Android-owned concerns: foreground notification + channel, partial wake lock, and sensor registration (accelerometer only for now). Widgets / boot receiver / UI not ported.
Verification
android/(one Java add, one Kotlin delete). No Rust orCargo.*files changed → cargo behaviour is identical tomain.cargo build --workspaceandcargo test --workspacefail onmainalready, incrates/lsmandcrates/esnonly (pre-existing rand 0.10 API drift:random()/sample()no longer resolve). This is unrelated to this PR and unaffected by it. Theneurophone-androidcrate is an untouched stub and compiles.TODOs / risks
TODO(#83 rebase):NativeLibJNI signatures depend on sub-PR chore(deps): update thiserror requirement from 1.0 to 2.0 #4 landing the Rust exports (init/start/stop/processSensor).TODO(#83): widen sensor registration beyond accelerometer once the Rust core consumes the full set (the id mapping already covers them).TODO(#83): foreground notification / wake lock should migrate behind Gossamer/Rust, shrinking or removing this shim with the rest ofandroid/.objectinterop usesNativeLib.INSTANCE; if chore(deps): update thiserror requirement from 1.0 to 2.0 #4 reimplementsNativeLibas a Java class or changes the singleton shape, the call sites need a trivial rebase (flagged).https://claude.ai/code/session_01Gu1JFCZHuBtBhAWPr4sMQw
Generated by Claude Code