Closed penn5 closed 2 years ago
I have a similar issue, termux keeps getting killed in background on my Huawei Y5 2019 phone, i disabled battery optimizations and all on it but still.
I recently got a HUAWEI MediaPad T5, model AGS2-L03 android 8. When termux is running in the background with tor and ZeroNet the ap seems to kill the session after a while, which means that tor and ZeorNet are no longer running, I lose my command history and when I switch back to Termux it is a new session.
I've read that this is related to how huawei tries to save battery life. Under battery/Launch for termux I have manual management with, "auto-launch", "Secondary Launch" and "run in background". I have termux configured to ignore battery optimization and I do not have it set as a power intensive ap. Yet the problem persists.
I think that updating might help but my phone provider doesn't have any updates for this device and I'm not sure it is wise to update a new device by other means.
P.S. Using a wake-lock doesn't help with this issue. Also I don't have this issue with my Samsung devices, which likely have a newer version of android. I was surprised that my phone provider is selling phones with an android version that is two generations out of date.
A possible fix can be found on stack overflow. I have not been able to test it though.
However, I have found a workaround (without tediously compiling anything) for the problem, though it is certainly only applicable to certain use cases. I am running sshd to share files and access the device. For this to work stable on the huawei mate9 I setup the following stuff:
#!/data/data/com.termux/files/usr/bin/sh
sshd
touch ~/.ssh-running while [ -e ~/.ssh-running ]; do termux-wake-lock sleep 5 termux-wake-unlock sleep 1 done
stop-sshd:
killall sshd rm -f ~/.ssh-running
Note that whenever you turn off the display, termux will be killed some time later. I hope this helps some people who encounter the same issues as me.
@penn5 which EMUI version? Have you tried following the steps described at https://dontkillmyapp.com/huawei e.g. disabling powergenie? If the vendor software decides to kill the app even if it's compliant with the Android foreground execution policies than there is little termux can do about this. You should find a workaround for your device.
Closing since kinda issues is not solvable by termux app. Some vendors ignore wakelocks held by apps not on vendor whitelist. Follow dontkillmyapp suggestions or root your device and install a custom rom compliant with AOSP.
I have interesting case on Redmi 7A MIUI 12.5, Android 10. When the device connected to the charger the background Termux process is working normally (during many days). If the device is disconnected from the charged he background Termux process gets killed by the system about 1 hour after the disconnect. The device configured according to https://dontkillmyapp.com/xiaomi
At the same time on this device is run Telegram SMS
app ( https://github.com/telegram-sms/telegram-sms ) as background service. And this app is not being killed by the system.
Problem description Evil OEMs kill apps in the name of the user, even when they hold wakelocks
Steps to reproduce Try to keep termux running some kind of server/persistent thing on emui or another evil skin
Expected behavior Termux keeps running
Additional information Try https://dontkillmyapp.com/. tldr fake the wakelock tag on https://github.com/termux/termux-app/blob/e502b9169fdec30200a631cd42dfd3a092e0948e/app/src/main/java/com/termux/app/TermuxService.java#L107 (and possibly on the WiFi wakelock too? I'm not sure if it's needed)