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.

fornwall commented 8 years ago

Can you run

logcat -s termux:* termux-api:*

while executing termux-battery-status in another, and see if there is any logcat output?

ghost commented 8 years ago

logcat -s termux:* termux-api:* outputs only one line:

----------- beginning of main

empjustine commented 8 years ago

I'm also facing the same issue, with the same one line output from logcat.

DerekCL commented 8 years ago

Same issue as above with same output: --------- beginning of main

ghost commented 8 years ago

Marshallos upgrade fixed it for me. So it should be something to do with Asus' Android 5.

ghost commented 8 years ago

Marshmallow*

Alastor27 commented 7 years ago

I have the same problem here on ASUS Zenfone 2 (ZE551ML, Android 5). None of the Termux-API functions are working, all hangs the same way and doing nothing. I installed it as intended multiple times. (Both the package and the application) My logcat always says this:

W/BroadcastQueue( 1590): Reject to launch app com.termux.api/10315 for broadcast: App Op 48

I'm almost convinced, that this problem is unique to the ASUS phones with Lollipop, but I'm curious if someone can figure out, what the cause is?

empjustine commented 7 years ago

I found the issue. On my firmware (I think this is a Lenovo issue), random applications are denied from starting from not-launcher intents. I had to disable "Restrict to launch" and it worked.

agguser commented 7 years ago

For ASUS phones, for termux-api to work, it seems "Termux:API" must be "allowed" in Auto-start Manager.

chaoqing commented 7 years ago

My Nexus 5x with Android 7.1.1 also facing the hangs problem when I try to termux-wifi-scaninfo and the logcat says

   termux-api: Unrecognized 'api_method' extra: 'WifiScanInfo'
Neo-Oli commented 7 years ago

@chaoqing Do you have the Termux:API app installed and is it updated to the latest version?

chaoqing commented 7 years ago

@Neo-Oli Yes I have installed updated version and the termux-battery-status command works.

vishalbiswas commented 7 years ago

@chaoqing You need Termux:API android app v0.12. You have an older one. Update from the play store or f-droid.

chaoqing commented 7 years ago

@vishalbiswas Thanks for your reminding. The termux-wifi-scaninfo now works but it always returns []. I can see a lot of WiFi ssid around me from the system WiFi manager.

vishalbiswas commented 7 years ago

@chaoqing make sure you allow those permissions of Termux:API that you want to use.

chaoqing commented 7 years ago

@vishalbiswas I have checked the permission for both termux-api and termux but the problem still exist. logcat tell nothing.

guerby commented 6 years ago

On a wiko Tommy 2 Android 7.1 I had to do settings / protected apps and then enable "protect" on termux and termux-api in order to have termux-battery-status to work (if not it hangs)

nurettin commented 6 years ago

this is the output of termux-battery-info & logcat

.... 11-09 05:40:02.904 9353 9353 E libmdmdetect: Failed to open /sys/bus/msm_subsys/devices/subsys0/name: Permission denied 11-09 05:40:02.897 9353 9353 W main : type=1400 audit(0.0:19639): avc: denied { read } for uid=10160 name="name" dev="sysfs" ino=22215 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:sysfs:s0 tclass=file permissive=0 ....

nurettin commented 6 years ago

nevermind, I had to install the termux api app as well.

matthewsalmon commented 6 years ago

No output from termux-api on Android 5.1.1 and 6.0.1. Part of logcat for 6.0.1:

09-22 15:56:58.775 7393 7393 W art : Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg /data/data/com.termux/files/usr/libexec/termux-am/am.apk --instruction-set=arm --instruction-set-features=smp,-div,-atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a53 --instruction-set-features=default --dex-file=/data/data/com.termux/files/usr/libexec/termux-am/am.apk --oat-file=/data/dalvik-cache/arm/data@data@com.termux@files@usr@libexec@termux-am@am.apk@classes.dex) because non-0 exit status

ghost commented 6 years ago

@matthewsalmon Some devices require BOOTCLASSPATH variable set.

Try this:

for lib in $(find /system/framework -type f -iname \*.jar); do
    BOOTCLASSPATH=${lib}:${BOOTCLASSPATH};
done
BOOTCLASSPATH=${BOOTCLASSPATH%%:}
export BOOTCLASSPATH

and then execute one of termux-api commands.


There also PR for this: https://github.com/termux/termux-app/pull/811

ghost commented 6 years ago

I'm able to execute termux-api commands directly on the shell.

But when I try to schedule it using crond(or busybox crond) I keep getting a similar error, here's the logcat:

10-11 03:41:01.003 22025 22025 D AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 10347 <<<<<<
10-11 03:41:01.007 22025 22025 D AndroidRuntime: CheckJNI is OFF
10-11 03:41:01.046 22025 22025 D ICU     : No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
10-11 03:41:01.157 22031 22031 E dex2oat : Failed to create oat file: /data/dalvik-cache/arm/data@data@com.termux@files@usr@libexec@termux-am@am.apk@classes.dex: Permission denied
10-11 03:41:01.157 22031 22031 I dex2oat : dex2oat took 1.636ms (threads: 4)
10-11 03:41:01.162 22025 22025 W art     : Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg /data/data/com.termux/files/usr/libexec/termux-am/am.apk --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=krait --instruction-set-features=default --dex-file=/data/data/com.termux/files/usr/libexec/termux-am/am.apk --oat-file=/data/dalvik-cache/arm/data@data@com.termux@files@usr@libexec@termux-am@am.apk@classes.dex) because non-0 exit status
10-11 03:41:01.223 22025 22025 I Radio-JNI: register_android_hardware_Radio DONE
10-11 03:41:01.257 22025 22025 D AndroidRuntime: Calling main entry com.example.termuxam.Am
10-11 03:41:01.334 22025 22025 D AndroidRuntime: Shutting down VM

Not sure why executing it directly works on the shell but scheduling using crond fails.

@xeffyr export BOOTCLASSPATH does not seem to help. Any ideas?

ghost commented 6 years ago

10-11 03:41:01.157 22031 22031 E dex2oat : Failed to create oat file: /data/dalvik-cache/arm/data@data@com.termux@files@usr@libexec@termux-am@am.apk@classes.dex: Permission denied @xeffyr export BOOTCLASSPATH does not seem to help. Any ideas?

In your case you have to clear dalvik cache from recovery. In most cases you can do this even on fully official/stock ROMs.

I don't know why this happens as I never had similar problem and only few people reported it. But it may occur if you do:

  1. Uninstalling, then reinstalling Termux application - application user id changes and you lose access to files created in /data/* (dalvik cache in your case).
  2. You used termux-api commands from root or adb shell - root or adb has a different user id.
  3. You uninstalled Termux and restored it via Titanium Backup - Titanium backup does not know anything about dalvik cache so you messed up with user id.
  4. Android OS did reset of uid/gid for dalvik cache, e.g. after reboot - this usually shouldn't happen.

Setting bootclasspath variable should help only if termux-api commands hang or crash. I experienced this on Android 5/6 ROMs only. On Android 7 and higher seems termux-api is okay.

adbenitez commented 5 years ago

I am still having this issue, no output from logcat

ghost commented 5 years ago

@adbenitez Is https://play.google.com/store/apps/details?id=com.termux.api installed ?

adbenitez commented 5 years ago

I installed it from f-droid and installed the package inside termux

adbenitez commented 5 years ago

I am on Android 6.0, possible cause: I had removed privileges for termux api and then readded them, I am not sure but I may had installed the api package while the privileges were not granted to the api plugin.

adbenitez commented 5 years ago

I had backed up the termux and termux-api apks and I had done a factory reset, I had installed both apps, opened termux, and issued pkg install termux-api, I had executed termux-clipboard-get and the command just hang, I am hopeless :( please help!!! my phone has Android 6.0

seffparker commented 5 years ago

On my POCO F1 (Android 9 / MIUI 10.3), the termux- commands still hangs, and it prevents further termux- commands to be executed.

root@batmobile home # pgrep -f termux- -l
1869 /data/data/com.termux/files/usr/bin/sh /data/data/com.termux/files/usr/bin/termux-notification-remove dailyjobs
1875 /data/data/com.termux/files/usr/libexec/termux-api NotificationRemove --es id dailyjobs

root@batmobile home # pstree -p 1869
termux-notifica(1869)---termux-api(1875)

root@batmobile home # strace -p 1869
strace: Process 1869 attached
wait4(-1, ^Cstrace: Process 1869 detached
 <detached ...>

root@batmobile home # strace -p 1875
strace: Process 1875 attached
accept4(3, ^Cstrace: Process 1875 detached
 <detached ...>

As the strace shows, those are doing nothing, but simply waiting for something.

It works most times, but hangs sometimes on the same Shell environment.

The 'Protected App' options not found in my device. Any other fix for this?

divinity76 commented 5 years ago

why is this issue closed? anyway, i have the same issue on a Doogee S80, Android 8.1.0, security patch level "August 5 2018", kernel 4.4.95+(something), Termux 0.75, Termux API 0.36 installed from Play Store,

running termux-battery-status & logcat | tee log.txt writes this to the log: https://pastebin.com/H5kU1Vc2 (i chose not to inline it because it's nearly 300 lines)

i have given Termux and Termux API's all the permissions i could find, but "protected apps" does not exist, image

image

image

ghost commented 5 years ago

why is this issue closed?

Read the issue from beginning and you will figure out why.

writes this to the log: https://pastebin.com/FxSRFc8G

Your log contains

09-25 15:51:17.064 24847 24847 E DrmMtkUtil/SecureTimer: open proc/uptime failed: [Permission denied].
09-25 15:51:17.062 24847 24847 W app_process: type=1400 audit(0.0:15050): avc: denied { read } for name="uptime" dev="proc" ino=4026532104 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:proc:s0 tclass=file permissive=0

If app_process can't be launched properly due to error above, then no possible fix for that (SELinux permission denial).

divinity76 commented 5 years ago

@xeffyr fine, it can't be "fixed", but still, hanging indefinitely is the wrong thing to do here. upon insufficient permissions, termux-battery-status should return an error code, not hang indefinitely.. i bet there is a syscall somewhere that does not return E_OK but whose error code is being ignored somewhere..

ghost commented 5 years ago

termux-battery-status relying on dalvikvm which is a bit "misused" in Termux. We can't modify it because it is a system thing.

ghost commented 5 years ago

If things inside /system/bin are broken or can't be used for some reason, then certain things in Termux will behave incorrectly. Thanks to Android fragmentation...

vintprox commented 3 years ago

Termux:API is not supported on my device. Android 6.0.1, armv71

ghost commented 3 years ago

@vintprox Termux no longer supports Android 6.0.1.

divinity76 commented 3 years ago

@vintprox Termux no longer supports Android 6.0.1.

is there some official place to check "minimum supported android version" ?

Grimler91 commented 3 years ago

@divinity76 you can check minSdkVersion in termux-app's gradle.properties, on the master branch. It is right now set to API level 24, which corresponds to android 7.0: https://developer.android.com/studio/releases/platforms.

That's just the master branch though, we supported android < 7 in parallel to the master branch for quite some time before stopping updates for android < 7.

exander77 commented 3 years ago

I seems to be having similar problems, but I have no SElinux error:

$ logcat -s termux:* termux-api:*
--------- beginning of main
read: unexpected EOF!
$ 
ghost commented 3 years ago

read: unexpected EOF!

@exander77 Your ROM has bugs. If logging subsystem can't provide a stable stream and constantly crashes/restarts, I won't be surprised if something else does not work.

exander77 commented 3 years ago

constantly crashes/restarts

What are you talking about? Where did you got such nonsense?

ghost commented 3 years ago

What are you talking about?

I know what I'm talking about.

In your case, where you got read: unexpected EOF! when logcat was executed is possible only when system service /system/bin/logd does not work correctly and has to restart.

exander77 commented 3 years ago

constantly crashes/restarts

Nothing like that happened.

It did hang for a long time and I did various strange things trying to make it work. You are assuming things which did not happen.

exander77 commented 3 years ago

I modified termux-api slightly, to see what am outputs:

Broadcasting: Intent { cmp=com.termux.api/.TermuxApiReceiver (has extras) }
Broadcast completed: result=0

After that, it hangs indefinitely.

ghost commented 3 years ago

Nothing like that happened.

Ok.

It did hang for a long time and I did various strange things trying to make it work.

Then perhaps you need to do some other strange things to make Termux:API working.

Btw, your logcat command is wrong. Termux doesn't use these tags and also OS-specific things will not displayed with them anyway. Use logcat without specifying tags.

You are assuming things which did not happen.

I'm making assumptions basing on information I got and personal experience. If you thing that I'm not correct, provide more information proving that. Your comment in https://github.com/termux/termux-packages/issues/334#issuecomment-717575854 is real nonsense.

In https://github.com/termux/termux-packages/issues/334#issuecomment-717564332 you making assumption (aka I have no SElinux error) on zero information at all.

I modified termux-api slightly, to see what am outputs:

The output you get is correct. But to know why termux-api hangs we need full logs obtained with ADB or at least logcat from Termux session.

exander77 commented 3 years ago

The logcat with tags was in one of the issues and I assumed wrongly that it is (still) applicable like that.

Logcat without any tags provides this:

10-28 00:17:12.803 29435 29435 D PQCommon: [PQ_PROT] [PQCust] libpq_cust_base_mtk.so absent, libpq_cust_mtk.so absent
10-28 00:17:12.804 29435 29435 E DrmMtkUtil/SecureTimer: open proc/uptime failed: [Permission denied].
10-28 00:17:12.806 29435 29435 D AVStageFactory: createInstance(64bit): createVendorAVFactory success!
10-28 00:17:12.806 29435 29435 D AVStageUtils: createInstance(64bit): createVendorAVUtils success!
10-28 00:17:12.806 29435 29435 D AVStageFactory: createInstance(64bit): createVendorAVFactory success!
10-28 00:17:12.806 29435 29435 D AVStageUtils: createInstance(64bit): createVendorAVUtils success!
10-28 00:17:12.806 29435 29435 D AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 10186 <<<<<<
10-28 00:17:12.905 29435 29435 D AndroidRuntime: Calling main entry com.example.termuxam.Am
10-28 00:17:12.927 29435 29435 D AndroidRuntime: Shutting down VM
ghost commented 3 years ago

10-28 00:17:12.905 29435 29435 D AndroidRuntime: Calling main entry com.example.termuxam.Am 10-28 00:17:12.927 29435 29435 D AndroidRuntime: Shutting down VM

That is something better, but still no information about events between startup and termination of VM.

exander77 commented 3 years ago

@xeffyr What do you suggest?

ghost commented 3 years ago

Last thing is to get logs with ADB, i.e. adb logcat.

Your issue can be related to https://github.com/termux/termux-packages/issues/3809#issuecomment-717594188.

exander77 commented 3 years ago

This is everything between those two (including them):

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