SensorAPI: killing termux-sensor CLI leaves sensors registered; later -c is a no-op
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.3k
- Forks
- 920
- PR merge metrics
- No merged PRs in 30d
Description
Summary
When a continuous termux-sensor -s … stream is stopped by killing the CLI process (broken output socket) instead of sending termux-sensor -c first, sensor listeners stay registered in Termux:API. A subsequent termux-sensor -c then prints Sensor cleanup unnecessary and does not unregister, so gravity/accelerometer stay occupied until Termux:API (and often Termux) are force-stopped.
Expected
- Closing/killing the streaming client should unregister listeners (or otherwise release sensors).
termux-sensor -cshould always unregister listeners if any are still registered, even whenoutputWriteris already null.
Actual
From current SensorAPI.java:
SensorOutputWritererror path only nullsoutputWriterviaonErrorListener— it does not callunregisterListener.cleanupHandler(-c) only unregisters whenoutputWriter != null:
if (outputWriter != null) {
outputWriter.interrupt();
outputWriter = null;
sensorManager.unregisterListener(sensorEventListener);
result.message = "Sensor cleanup successful!";
} else {
result.message = "Sensor cleanup unnecessary";
}
So the failure order is:
termux-sensor -s gravity -d 100(stream)- Kill the CLI → socket error →
outputWriter = null, listeners still registered termux-sensor -c→ “cleanup unnecessary” → sensors still held
Contrast with SensorReaderService.cleanup() / onDestroy(), which always unregisters when sensorManager != null.
Repro
# terminal A
termux-sensor -s gravity -d 100
# terminal B — kill the PID of the process in A, then:
termux-sensor -c
# often: Sensor cleanup unnecessary
# sensors remain stuck for other apps / a new termux-sensor -s until force-stop
Suggested fix
- In the
SensorOutputWritererror / finish path: alwaysunregisterListener(same ascleanup()). - In
cleanupHandler: always unregister if listeners may still be active (do not gate solely onoutputWriter != null), or track a separate “listening” flag.
Impact / consumers
fount’s Termux logo gravity (termux-sensor child process) must call -c before killing the stream CLI to avoid this. After a kill-first leak, -c cannot recover without force-stopping apps.
When this is fixed upstream, clients can still keep -c-before-kill as the documented stop sequence; kill-then--c and abrupt CLI death should also release sensors.
Follow-up for fount (when closed)
Repo: https://github.com/steve02081504/fount
After upstream fix lands in a Termux:API release:
- Re-check
imgs/icon_anime/gravity_acquire/termux.mjsstop path — keep-cbefore kill (correct API usage), but abrupt kill / exit-only paths should no longer brick sensors. - Optional: simplify or drop process-
exitbelt-and-suspenders if no longer needed for this leak. - Manual Termux: start
fount logo, kill-sCLI without-c, confirm sensors still release /-crecovers.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in SensorAPI.java by reading the SensorOutputWriter error or finish path and cleanupHandler, then compare their listener handling with SensorReaderService.cleanup() and onDestroy(). Reproduce the kill-first sequence with termux-sensor -s gravity -d 100 and termux-sensor -c. Done means abrupt stream termination releases listeners and a later cleanup command can unregister any remaining listeners.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- api, mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100