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
35.03k stars 3.69k forks source link

termux-wake-lock/unlock issues #3472

Closed angelog0 closed 1 year ago

angelog0 commented 1 year ago

Problem description

Running termux-wake-lock the first time opens a popup asking for consensus: this only the first time than it does not ask any more.

  1. How can I revert this so that the next time I run that command it asks for consensus?

  2. How can I know if the wake lock is active? Tried:

termux-notification-list | jq -r '.[] | select(.id == 1337).content' | grep -qF 'wake lock held' && locked="true" || locked="false"

but it seems to hang: I have to CTRL-C..

Steps to reproduce the behavior.

.

What is the expected behavior?

No response

System information

tareksander commented 1 year ago

Normally the wake lock is a permission granted to apps without user conset IIRC. You can try searching Termux in your app list in the settings app and look for denied permissions.

angelog0 commented 1 year ago

@tareksander, here it asked. There was a sort of warning about the usage of app in background consuming battery. I searched in Settings (Termux, Notifications, Battery) but found anything of useful.. and about my question n. 2?

tareksander commented 1 year ago

Do you have the Termux:API app installed?

angelog0 commented 1 year ago

@tareksander, I installed the termux-api and jq packages..

tareksander commented 1 year ago

You have to install the app: https://github.com/termux/termux-api

angelog0 commented 1 year ago

Ah, ok... and for my question n. 1? I would interested to revert consensus..

sylirre commented 1 year ago

@angelog0 If you disabled the battery optimization, it can be enabled again in the battery settings of Android OS. There is a dedicated list of apps and their battery optimization status. Applicable to Samsung and other device models unless they run exotic fork of Android.

Left is menu on Pixel 5 and the right on Samsung Galaxy S7:

termux battery optimization


termux-wake-lock or button in the notification will ask to disable battery optimization only if this was not done. You won't be asked again when the optimization has been disabled. This is done through Android Intent ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, so basically it works one way - to disable the optimization and will not let you enable it again. Moreover that's the point, to disable the optimization once and never ask for doing it again.

tareksander commented 1 year ago

I don't think that's possible.

angelog0 commented 1 year ago

@sylirre, thanks for all your suggestion but here, Xiaomi with AOS 8.1, in Settings - App-Termux-Energy saving, Termux has Save Battery (suggested) enabled (the other would be Unrestricted, etc.)

instead in Settings - Battery and performance - battery - save energy app there are many app listed between which Termux and tapping on it it returns to what I have just described above... and termux-wake-lock does ask any more..

agnostic-apollo commented 1 year ago

Xiaomi phones and others have multiple battery related settings for apps, you will have to find on your own, check https://dontkillmyapp.com/xiaomi

  1. Termux will not ask user for disabling battery optimizations if already granted by user, no point in that and it is working as intended. To disable battery optimizations with an android prompt yourself, run am start --user 0 -a android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS -d "package:com.termux" and select Allow. If optimizations are already disabled, then no prompt will be shown and the battery optimizations settings for all apps will need to be opened with am start --user 0 -a android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS.

  2. Use following after granting termux DUMP permission with adb or root. 356a442c

adb shell dumpsys power | grep -E 'PARTIAL_WAKE_LOCK.*termux:service-wakelock'
  PARTIAL_WAKE_LOCK              'termux:service-wakelock' ACQ=-1m48s379ms LONG (uid=10169 pid=15126)