termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
13.1k stars 3.01k forks source link

Termux-api not working? #334

Closed ghost closed 6 years ago

ghost commented 8 years ago

Termux-api is installed from Google's Play store. I've also installed termux-api from Termux with apt.

Calling termux-api commands doesn't do anything (it just 'hangs' there).

screenshot_2016-06-19-20-01-19

I'm using Asus ZC550KL, Android 5.0.2.

ghost commented 3 years ago

You have 2 interesting lines:

10-28 00:29:59.365   932  5839 I FreemeLogger: AppAutoStartupPolicy:prevent start receiver of package com.termux.api for action null
10-28 00:29:59.365   932  1204 I FreemeLogger: AppAutoStartupPolicy:startRecordService { when=0 what=7 target=com.freeme.server.pfw.policy.FreemePFWAppAutoStartupPolicy$StartupPolicyHandler }

System thing (AppAutoStartupPolicy) blocks the startup of Termux:API. That's a different case, but related to some Intent Firewall like in https://github.com/termux/termux-packages/issues/3809#issuecomment-717594188.

For now I can suggest you to check system settings, maybe there are menus where you can configure application autostart policies. Otherwise only rooting & removing "bloatware" from /system.

exander77 commented 3 years ago

Yes, I think something is blocking, but can't seem to find details AppAutoStartupPolicy.

exander77 commented 3 years ago

@xeffyr I upgraded to Android 10.

10-28 19:44:03.628  9052  9052 D AndroidRuntime: Calling main entry com.example.termuxam.Am
10-28 19:44:03.642  1053  3623 D FreemeLogger: AutoStartupDataMgr:isUnderControll third party not in whitelist: com.termux.api
10-28 19:44:03.642  1053  3623 D FreemeLogger: AutoStartupDataMgr:retrieveStartupSettings type 0 of com.termux.api is 2
10-28 19:44:03.642  1053  3623 I FreemeLogger: AppAutoStartupPolicy:sendStartupRecordMsg, pkg=com.termux.api,caller=r,resultfalse,pid=-1,uid=-1
10-28 19:44:03.642  1053  3623 I FreemeLogger: AppAutoStartupPolicy:prevent start receiver of package com.termux.api for action null
10-28 19:44:03.642  1053  1232 I FreemeLogger: AppAutoStartupPolicy:startRecordService { when=0 what=7 target=com.freeme.server.pfw.policy.FreemePFWAppAutoStartupPolicy$StartupPolicyHandler }
10-28 19:44:03.643  9052  9052 D AndroidRuntime: Shutting down VM

I think it is safe to say that Termux:API does not work at least on Android 9 and Android 10 on my device. I think it may be using some either deprecated or undocumented techniques which are not generally supported. I think maybe there should be Termux and Termux with integrated API? Btw, Termux:Widget suffers the same problem.

AlainKnaff commented 3 years ago

Some phones or tablets seem to have more strict rules concerning intents sent to services than others. I have 2 devices where it works fine, but one where it is broken. All 3 of them are Android 9.

On the broken one, I could get it to work by adding an interactive activity to termux-api (just a screen that says "hello world"). As long as this is up, termux can invoke termux-api.

exander77 commented 3 years ago

@AlainKnaff Yes, I think that it is because it is a backend service. Is there a Termux-API version like that? Or do I have to build it myself?

AlainKnaff commented 3 years ago

I've uploaded my test version (apk, and diff) to http://alain.knaff.lu/TermuxApi/

However, as obviously I could not sign it with the official key, this is of little use apart from testing. termux-dialog -t test does show the dialog. However, command hangs and little else works. This is because the server (termux-api) connects back to a pair of Unix domain sockets created by the client (the shell in termux), and it cannot do so if the user ids don't match, which happens if the signing key is different.

But still shows, as a proof of concept, that the approach should be viable.

aliko4949 commented 3 years ago

​10-28 00:29:59.349 30038 30038 D AndroidRuntime: Calling main entry com.example.termuxam.Am 10-28 00:29:59.364   932  5839 D FreemeLogger: AutoStartupDataMgr:isUnderControll third party not in whitelist: com.termux.api 10-28 00:29:59.364   932  5839 D FreemeLogger: AutoStartupDataMgr:retrieveStartupSettings type 0 of com.termux.api is 2 10-28 00:29:59.365   932  5839 I FreemeLogger: AppAutoStartupPolicy:sendStartupRecordMsg, pkg=com.termux.api,caller=r,resultfalse,pid=-1,uid=-1 10-28 00:29:59.365   932  5839 I FreemeLogger: AppAutoStartupPolicy:prevent start receiver of package com.termux.api for action null 10-28 00:29:59.365   932  1204 I FreemeLogger: AppAutoStartupPolicy:startRecordService { when=0 what=7 target=com.freeme.server.pfw.policy.FreemePFWAppAutoStartupPolicy$StartupPolicyHandler } 10-28 00:29:59.367   932  1021 I ActivityManager: Killing 29850:com.android.traceur/u0a54 (adj 906): empty #11 10-28 00:29:59.368 30038 30038 D AndroidRuntime: Shutting down VM

vinniec commented 3 years ago

I've uploaded my test version (apk, and diff) to http://alain.knaff.lu/TermuxApi/

However, as obviously I could not sign it with the official key, this is of little use apart from testing. termux-dialog -t test does show the dialog. However, command hangs and little else works. This is because the server (termux-api) connects back to a pair of Unix domain sockets created by the client (the shell in termux), and it cannot do so if the user ids don't match, which happens if the signing key is different.

But still shows, as a proof of concept, that the approach should be viable.

With your version of termux-api I can do something, like start the vibration, use dialog or turn on and off the flashlight. But most things still don't work anyway :(

ghost commented 3 years ago

i have the issue that termux-api commands(like termux-volume etc) works only for some time...my guess is that Termux:api background app is automaticly stopped or disabled on my android 10 device(oukitel wp5) after some time..(i can get it to work back if i uninstall and reinstall but just for some time...), we need a version of Termux:api that is kept alive maybe with a pseudo interactive screen, like @AlainKnaff said. I don't have any 'protected apps' option in settings nor in dev options. And it's not possible to 'autostart' this app since its not interactive. Help needed with that please! :]

AlainKnaff commented 3 years ago

Hi,

Just a short update about my Vankyo Tablet where I had difficulty using termux-api.

I didn't have a "protected" setting in App settings, but eventually I found "Auto launch management" hidden under the power savings options, which allowed me to solve the issue.

To get to this setting, I had to do the following:

  1. Slide you finger down from the top edge to bring up the notifications
  2. Slide again from top edge to bring up the quick configuration icons
  3. Click on the "battery" icon ("Smart saving mode")
  4. In the popup you get a choice between 3 modes: "Smart saving mode", "Power saving mode", "Ultra saving mode". Leave that choice as it is, but look at the lower edge of that popup. There you have "More settings". Click on it.
  5. This brings up a "battery" configuration page, chose "Auto launch management"
  6. Chose "App secondary launch"
  7. This shows all apps with a slider "Don't allow the app secondary launch". By default for all apps the slider is off (left side), and it says "Don't allow". Slide it to the right for "Termux:API" to "Allow".

You can skip steps 1-4 by just searching for "launch" or "battery" from Setting's main page.

A similar issue with Termux:Boot and Termux:Widget may be solved by allowing Termux (main package) for "App secondary launch", and allowing Termux:Boot and Termux:Widget for "App auto launch"

Maybe on other tablets the setting is not in this exact location, but it may help looking for it under "power management" rather than "Apps & notifications".

victorsv91 commented 3 years ago

I have a Moto G7 Plus (XT1965-3) with TWRP (3.5.2_9-0-lake), LineageOS 18.1 (Android 11) and MagiskHide (23.0) did not work any command.

Girish-ai commented 3 years ago

I have same plobrem it just hangs up and do nothing i kept it running for 2hrs but it still won't worked.

Device :- Realme C3 Android version - android 10

Also, I was building a program in python which uses news api to collect latest news and speak Top Headlines i was coding it in pydroid3 but at there i have issue with TTS pytysx3 is giving error i tried to reslove it but it won't worked so, then i coded it for qpython there is a pre built system controller so speaks works very well but it won't support requests module finally i decided to code it for termux and then api not working. Please help if you know how i can fix it.

truboxl commented 3 years ago

@Girish-ai You can try make a function that: Kills processes named main and termux-api Calls whatever termux-api command with timeout 5 command and store the value / error in current variable Then filter out current variable If it's empty, call again the function If it's an error, call again the function Else proceed as usual

Sample bash code that handles this for termux-battery-status (you may need to modify into other languages) https://github.com/truboxl/boinc-termux-client/blob/e5a28136df8473f49413343c2be155a8177714fe/sh/start-boinc#L63-L80

The old variable is thrown in so that only in the first call of function it will loop endlessly to get one real value

while subsequent calls to the function will just use back the old value if timeout