termux-location -p gps -r updates crashes on second location update and always exits after ~30 seconds
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.3k
- Forks
- 920
- PR merge metrics
- No merged PRs in 30d
Description
Problem description
I'm trying to understand the intended behavior of termux-location -p gps -r updates.
When running:
termux-location -p gps -r updates
the command prints the first location fix, waits about 20–30 seconds, then exits.
Looking at LocationAPI.java, it appears that requestLocationUpdates() is called, but the looper is stopped after 30 seconds:
manager.requestLocationUpdates(provider, 5000, 50.f, listener, null);
... Thread.sleep(30 * 1000);
looper.quit();
Is this the intended behavior of -r updates, or is it expected to provide continuous location updates?
Additionally, if a second location update is delivered before the 30-second timeout (for example, by moving more than the configured 50 m), the Termux app crashes with:
IllegalStateException: JSON must have only one top-level value
This produces an "Error in ResultReturner" notification and temporarily disrupts location delivery. In my testing, concurrent termux-location -p gps -r once polling also missed fixes for a few seconds, resulting in a visible gap in the recorded GPS track.
From the code, it appears that multiple location updates are written using the same JsonWriter, causing the second top-level JSON value to throw the exception.
Steps to reproduce
- Run:
termux-location -p gps -r updates - Move more than approximately 50 m within 30 seconds (e.g. while driving or cycling).
- Observe that Termux crashes with:
IllegalStateException: JSON must have only one top-level value
Expected behavior
Either:
-r updatesis intended to stream location updates, in which case it should continue delivering updates without crashing, or- if the 30-second lifetime is intentional, the command should still not crash when a second update is delivered during that period.
Additional information
- termux-api application version: 0.59.1-1 (F-Droid)
- termux-api package version (installed through apt): 0.59.1
- Android OS version: 13
- Device model: Samsung Galaxy S21
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 with LocationAPI.java and reproduce termux-location -p gps -r updates on the reported Android setup. Inspect how requestLocationUpdates, the looper timeout, and the shared JsonWriter handle a second fix. Done means the command no longer crashes on a second update and the intended 30-second or continuous-update behavior is established and verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, cli, mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100