termux / termux-app

Termux - a terminal emulator application for Android OS extendible by variety of packages.
https://f-droid.org/en/packages/com.termux
Other
34.59k stars 3.63k forks source link

Termux killed in background by EMUI #1172

Closed penn5 closed 2 years ago

penn5 commented 5 years ago

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)

ravener commented 4 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.

s243a commented 4 years ago

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.

hjudt commented 3 years ago

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:

  1. Attach the device to power supply. This is needed for step 2 to work.
  2. Keep the display always active when charging. This is needed for termux being able to keep the wakelock. Two possibilities: a. Activate system settings -> developer settings -> Always on b. Configure system settings -> display -> more display settings -> screen saver Set its deactivation time to something long enough or to never deactivate to always keep it running when charging.
  3. Keep the wake-lock by constantly aquiring and releasing it. I have two shortcut scripts start-sshd and stop-sshd: start-sshd:
    
    #!/data/data/com.termux/files/usr/bin/sh

can of course be any other daemon

sshd

re-acquire wake locks every few seconds

touch ~/.ssh-running while [ -e ~/.ssh-running ]; do termux-wake-lock sleep 5 termux-wake-unlock sleep 1 done


stop-sshd:

!/data/data/com.termux/files/usr/bin/sh

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.
emanuele-f commented 2 years ago

@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.

agnostic-apollo commented 2 years ago

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.

AntonSamokat commented 1 year ago

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.