-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
termux-wake-lock and termux-wake-unlock take ~10 seconds in widgets on Android 12L #88
Comments
The 2-3 second delay may be related to termux/termux-tools#15 and needs to be investigated but shouldn't happen on next termux-app update due to The 10s delay could be due to intent to |
Okay; here's a simple Bash test script that removes a few variables:
Attached is a screenshot showing this script run in the console; another showing the same script run in a widget; and a logcat from the session. Termux app versions are captured as well, and all attachments are from the 12L Fold4. As shown, the calls take roughly 9-10 seconds in the widget, and 2-3 outside it. But this story is actually growing a bit stranger. On further testing, I've found that restarting the Android 12L test device will temporarily alleviate the problem: immediately after the restart, the lock and unlock calls run for 2-3 seconds in the widget, just like they do outside the widget. However, this doesn't last: after the device is allowed to sleep (e.g., by pressing the power button and waiting a few minutes), the calls go right back to taking 9-10 seconds in the widget again. Weird; maybe sleep—or Samsung's flavor of it—is somehow triggering the longer delays? Data point: in the logcat, there is a 6-second pause at the line So as it stands, restarting the phone is a work-around of sorts for the 10-second delays, but only until the next sleep state restores them. Backgrounding the calls avoids widget pauses either way, but gets dicey when the 10-second delays kick in. Attachments: |
Update: after upgrading the Fold4 to Android 13 in early 2023, the Termux:Widget wakelock-call pauses have largely gone away. On 13, the calls still take 2-3 seconds outside of widgets as before, but now just 3-4 seconds in widgets instead of 12L's 10. The shorter 3-4 second widget pauses are still long enough to warrant backgrounding, but this is a trivial workaround, and the pauses may be further addressed by other Termux changes noted on this thread. So, barring new reports, this seems close worthy at this point. No idea if it was fixed in Samsung or Android code, but nondeterminism seems a norm on this platform. |
termux/termux-tools@5dbde2e4 may be the reason for shorter delays. |
Thanks; this fix is clearly related. But possibly dumb question: I'm using the same versions of Termux and Termux:Widget on Android 13 as I did on 12L, and both seem to predate the fix; could this fix have influenced the results anyhow? I'm wondering if the fix will address the 2-3 second delays, but the 12L 10sec pauses was something else. |
The app versions don't matter. If you are using latest or fixed version of |
Looks like I wasn't using the latest The |
Unknown if related but using Termux:Tasker without the checkbox enabled to run it in the terminal for Termux apparently adds a lot more time to run the code. Samsung Galaxy S21 5G #!/data/data/com.termux/files/usr/bin/python
import subprocess, time
started = time.time()
result = subprocess.run(
'/data/data/com.termux/files/usr/bin/termux-battery-status',
text=True, stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
finished = time.time()
print(f'Time elapsed: {finished - started} second(s)\nExit status: {result.returncode}\nOutput:\n{result.stdout}') Note that without Termux:Tasker to start the script, (or with it but having it pop up Termux's terminal,) has it run in about 3 seconds on my system. I could guess that the long wait is due to Termux running in the background instead of the foreground. |
Maybe background processes having lesser cpu priority is causing
The |
termux-wake-lock
andtermux-wake-unlock
, run by Python'sos.system()
, have begun taking some 10 seconds each on an Android 12L device (a Samsung Fold4), when called from a Termux:Widget script only.These calls are useful for auto-locking in long-running widgets. They formerly returned immediately on Android 10 (a Note20 Ultra), and paused for 2-3 seconds on Android 12 (a Fold3). The 10-second pauses on 12L are new. The calls still run for 2-3 seconds outside the widget on 12L, but two 10-second pauses are naturally subpar for widget users.
As a workaround, running the lock and unlock calls in the background avoids the pauses, but this is brittle. Widget scripts in the subject program cannot run in parallel in general, but starting and stopping multiple widget scripts in rapid succession may leave the lock in an arbitrary state on 12L because backgrounded calls overlap (atypical, but possible).
It's impossible to know if this reflects Samsung or Android changes without more test devices and/or time; just reporting it as an otherwise satisfied Termux:Widget customer.
Context: this is part of a PC<=>Android content-sync package which uses Termux heavily, at https://learning-python.com/android-deltas-sync/. The widget scripts are simple shims that look like the following:
The text was updated successfully, but these errors were encountered: