Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: termux-setup-storage does not work on Android 14 #3647

Closed
rampadmin opened this issue Oct 15, 2023 · 49 comments
Closed

[Bug]: termux-setup-storage does not work on Android 14 #3647

rampadmin opened this issue Oct 15, 2023 · 49 comments

Comments

@rampadmin
Copy link

Problem description

I get the following error logs when trying to run termux-setup-storage on my Android 14 Pixel 7A device.

~ $ termux-setup-storage
/data/data/com.termux/files/usr/bin/termux-setup-storage: line 29: 25193 Aborted                 am broadcast --user 0 --es com.termux.app.reload_style storage -a com.termux.app.reload_style com.termux > /dev/null

Apparently, the message aborted comes even if I just run the am command.

Could someone please help me out with this issue?

Steps to reproduce the behavior.

Run termux-setup-storage on Android 14 (preferably on Pixel 7a) device.

What is the expected behavior?

termux-setup-storage should setup a storage folder as usual.

System information

  • Termux application version: v0.118.0
  • Android OS version: 14
  • Device model: Pixel 7a
@THEGOLDENPRO
Copy link

I'm getting the same issue with mpv.

@THEGOLDENPRO
Copy link

It started happening right after I upgraded to Android 14. I really want to downgrade now 😔

@agnostic-apollo
Copy link
Member

Run pkg install termux-am.

@agnostic-apollo agnostic-apollo closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2023
@THEGOLDENPRO
Copy link

THEGOLDENPRO commented Oct 16, 2023

Run pkg install termux-am.

Omg thank you so much. 🙏 That worked!

@rampadmin
Copy link
Author

Thanks a lot @agnostic-apollo! The issue gets resolved after running this command.

@agnostic-apollo
Copy link
Member

Welcome both. On related pull, the termux-am doesn't need to be installed, it is already installed by default, it needs to be updated to >= v0.6.0.

termux/TermuxAm@598a9c0

termux/TermuxAm@8761289

@THEGOLDENPRO
Copy link

I see that makes more sense. Thanks

@Kaz205
Copy link

Kaz205 commented Dec 11, 2023

Seems to be broken again on Android 14 QPR1. I don't get any errors but the storage directory isn't created and the app doesn't request the relevant permissions.

@joshDamian
Copy link

Experiencing the same issue as @Kaz205 on Android 14. Running termux-setup-storage does nothing.

@paschun
Copy link

paschun commented Dec 14, 2023

Same, with the latest Android 14. I tried explicitly granting the "Files" permission in App Info -> App Permissions, but no dice.

@agnostic-apollo
Copy link
Member

Make sure to run pkg install termux-am on Android 14 before reporting issues.

Storage permissions are given in the following way.

  • Android < 11: Android Settings -> Apps -> Termux -> Permissions -> Storage
  • Android >= 11: Android Settings -> Apps -> Termux -> Permissions -> Files and media -> Allow management of all files
  • Android >= 13: Android Settings -> Apps -> (Advanced ->) Special app access -> All files access -> Termux

If using GitHub action builds, then running test -d "$HOME/storage" || termux-am broadcast --user 0 --es com.termux.app.reload_style storage -a com.termux.app.reload_style com.termux > /dev/null should work.

As for termux-setup-storage not working, post or email me adb logcat -d > logcat.txt output after running command.

@paschun
Copy link

paschun commented Dec 15, 2023

Thanks for the detailed response!

I'm on a fresh install of termux on Android 14 from f-droid. termux-am got installed already somewhere along the way during the setup of termux and termux:api.

Permissions for me are : Android Settings -> Apps -> Termux -> Permissions -> Files -> Allow
Then Photos and Videos and Music and audio permissions additionally auto jump to the Allowed section.

Running termux-setup-storage, nothing happens, exit code 255. Here's the logcat.

12-14 17:01:38.574 30708 30708 W bash    : type=1400 audit(0.0:8680): avc:  granted  { execute } for  name="termux-setup-storage" dev="dm-52" ino=326783 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.574 30708 30708 W bash    : type=1400 audit(0.0:8681): avc:  granted  { execute } for  name="termux-setup-storage" dev="dm-52" ino=326783 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.574 30708 30708 W bash    : type=1400 audit(0.0:8682): avc:  granted  { execute_no_trans } for  path="/data/data/com.termux/files/usr/bin/termux-setup-storage" dev="dm-52" ino=326783 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.574 30708 30708 W bash    : type=1400 audit(0.0:8683): avc:  granted  { execute } for  name="bash" dev="dm-52" ino=320121 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.582 30708 30708 W termux-setup-st: type=1400 audit(0.0:8684): avc:  granted  { execute } for  path="/data/data/com.termux/files/usr/bin/bash" dev="dm-52" ino=320121 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.586 30708 30708 W termux-setup-st: type=1400 audit(0.0:8685): avc:  denied  { search } for  name="tests" dev="dm-52" ino=111 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:shell_test_data_file:s0 tclass=dir permissive=0 app=com.termux.api
12-14 17:01:38.586 30708 30708 W termux-setup-st: type=1400 audit(0.0:8686): avc:  denied  { search } for  name="tests" dev="dm-52" ino=111 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:shell_test_data_file:s0 tclass=dir permissive=0 app=com.termux.api
12-14 17:01:38.586 30708 30708 W termux-setup-st: type=1400 audit(0.0:8687): avc:  denied  { search } for  name="tests" dev="dm-52" ino=111 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:shell_test_data_file:s0 tclass=dir permissive=0 app=com.termux.api
12-14 17:01:38.586 30708 30708 W termux-setup-st: type=1400 audit(0.0:8688): avc:  denied  { search } for  name="tests" dev="dm-52" ino=111 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:shell_test_data_file:s0 tclass=dir permissive=0 app=com.termux.api
12-14 17:01:38.594 30708 30708 W termux-setup-st: type=1400 audit(0.0:8689): avc:  granted  { execute } for  path="/data/data/com.termux/files/usr/lib/libandroid-support.so" dev="dm-52" ino=331849 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.594 30708 30708 W termux-setup-st: type=1400 audit(0.0:8690): avc:  granted  { execute } for  path="/data/data/com.termux/files/usr/lib/libreadline.so.8.2" dev="dm-52" ino=328324 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.594 30708 30708 W termux-setup-st: type=1400 audit(0.0:8691): avc:  granted  { execute } for  path="/data/data/com.termux/files/usr/lib/libncursesw.so.6.4" dev="dm-52" ino=332842 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.594 30708 30708 W termux-setup-st: type=1400 audit(0.0:8692): avc:  granted  { execute } for  path="/data/data/com.termux/files/usr/lib/libiconv.so" dev="dm-52" ino=331804 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.594 30708 30708 W termux-setup-st: type=1400 audit(0.0:8693): avc:  granted  { execute } for  path="/data/data/com.termux/files/usr/lib/libtermux-exec.so" dev="dm-52" ino=320801 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.602 30709 30709 W termux-setup-st: type=1400 audit(0.0:8694): avc:  granted  { execute } for  name="am" dev="dm-52" ino=330219 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.602 30709 30709 W termux-setup-st: type=1400 audit(0.0:8695): avc:  granted  { execute } for  name="am" dev="dm-52" ino=330219 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.602 30709 30709 W termux-setup-st: type=1400 audit(0.0:8696): avc:  granted  { execute_no_trans } for  path="/data/data/com.termux/files/usr/bin/am" dev="dm-52" ino=330219 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.602 30709 30709 W termux-setup-st: type=1400 audit(0.0:8697): avc:  granted  { execute } for  name="dash" dev="dm-52" ino=324608 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.606 30709 30709 W am      : type=1400 audit(0.0:8698): avc:  granted  { execute } for  path="/data/data/com.termux/files/usr/bin/dash" dev="dm-52" ino=324608 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.606 30709 30709 W am      : type=1400 audit(0.0:8699): avc:  denied  { search } for  name="tests" dev="dm-52" ino=111 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:shell_test_data_file:s0 tclass=dir permissive=0 app=com.termux.api
12-14 17:01:38.606 30709 30709 W am      : type=1400 audit(0.0:8700): avc:  denied  { search } for  name="tests" dev="dm-52" ino=111 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:shell_test_data_file:s0 tclass=dir permissive=0 app=com.termux.api
12-14 17:01:38.606 30709 30709 W am      : type=1400 audit(0.0:8701): avc:  denied  { search } for  name="tests" dev="dm-52" ino=111 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:shell_test_data_file:s0 tclass=dir permissive=0 app=com.termux.api
12-14 17:01:38.606 30709 30709 W am      : type=1400 audit(0.0:8702): avc:  denied  { search } for  name="tests" dev="dm-52" ino=111 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:shell_test_data_file:s0 tclass=dir permissive=0 app=com.termux.api
12-14 17:01:38.614 30709 30709 W am      : type=1400 audit(0.0:8703): avc:  granted  { execute } for  path="/data/data/com.termux/files/usr/lib/libtermux-exec.so" dev="dm-52" ino=320801 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.626 30710 30710 W am      : type=1400 audit(0.0:8704): avc:  granted  { execute } for  name="getprop" dev="dm-52" ino=327138 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.626 30710 30710 W am      : type=1400 audit(0.0:8705): avc:  granted  { execute } for  name="getprop" dev="dm-52" ino=327138 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.626 30710 30710 W am      : type=1400 audit(0.0:8706): avc:  granted  { execute_no_trans } for  path="/data/data/com.termux/files/usr/bin/getprop" dev="dm-52" ino=327138 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.626 30710 30710 W am      : type=1400 audit(0.0:8707): avc:  granted  { execute } for  name="dash" dev="dm-52" ino=324608 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.626 30710 30710 W getprop : type=1400 audit(0.0:8708): avc:  granted  { execute } for  path="/data/data/com.termux/files/usr/bin/dash" dev="dm-52" ino=324608 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.626 30710 30710 W getprop : type=1400 audit(0.0:8709): avc:  denied  { search } for  name="tests" dev="dm-52" ino=111 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:shell_test_data_file:s0 tclass=dir permissive=0 app=com.termux.api
12-14 17:01:38.626 30710 30710 W getprop : type=1400 audit(0.0:8710): avc:  denied  { search } for  name="tests" dev="dm-52" ino=111 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:shell_test_data_file:s0 tclass=dir permissive=0 app=com.termux.api
12-14 17:01:38.626 30710 30710 W getprop : type=1400 audit(0.0:8711): avc:  denied  { search } for  name="tests" dev="dm-52" ino=111 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:shell_test_data_file:s0 tclass=dir permissive=0 app=com.termux.api
12-14 17:01:38.626 30710 30710 W getprop : type=1400 audit(0.0:8712): avc:  denied  { search } for  name="tests" dev="dm-52" ino=111 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:shell_test_data_file:s0 tclass=dir permissive=0 app=com.termux.api
12-14 17:01:38.634 30710 30710 W getprop : type=1400 audit(0.0:8713): avc:  granted  { execute } for  path="/data/data/com.termux/files/usr/lib/libtermux-exec.so" dev="dm-52" ino=320801 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.670 30711 30711 W am      : type=1400 audit(0.0:8714): avc:  granted  { execute } for  name="cmd" dev="dm-52" ino=326829 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.674 30712 30712 W am      : type=1400 audit(0.0:8715): avc:  granted  { execute } for  name="cmd" dev="dm-52" ino=326829 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.674 30712 30712 W am      : type=1400 audit(0.0:8716): avc:  granted  { execute_no_trans } for  path="/data/data/com.termux/files/usr/bin/cmd" dev="dm-52" ino=326829 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.674 30712 30712 W am      : type=1400 audit(0.0:8717): avc:  granted  { execute } for  name="dash" dev="dm-52" ino=324608 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.674 30712 30712 W cmd     : type=1400 audit(0.0:8718): avc:  granted  { execute } for  path="/data/data/com.termux/files/usr/bin/dash" dev="dm-52" ino=324608 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:app_data_file:s0:c135,c256,c512,c768 tclass=file app=com.termux.api
12-14 17:01:38.678 30712 30712 W cmd     : type=1400 audit(0.0:8719): avc:  denied  { search } for  name="tests" dev="dm-52" ino=111 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:shell_test_data_file:s0 tclass=dir permissive=0 app=com.termux.api
12-14 17:01:38.678 30712 30712 W cmd     : type=1400 audit(0.0:8720): avc:  denied  { search } for  name="tests" dev="dm-52" ino=111 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:shell_test_data_file:s0 tclass=dir permissive=0 app=com.termux.api
12-14 17:01:38.678 30712 30712 W cmd     : type=1400 audit(0.0:8721): avc:  denied  { search } for  name="tests" dev="dm-52" ino=111 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:shell_test_data_file:s0 tclass=dir permissive=0 app=com.termux.api
12-14 17:01:38.678 30712 30712 W cmd     : type=1400 audit(0.0:8722): avc:  denied  { search } for  name="tests" dev="dm-52" ino=111 scontext=u:r:untrusted_app_27:s0:c135,c256,c512,c768 tcontext=u:object_r:shell_test_data_file:s0 tclass=dir permissive=0 app=com.termux.api
12-14 17:01:38.708 30712 30712 E cutils-trace: Error opening trace file: No such file or directory (2)

@agnostic-apollo
Copy link
Member

Did you run log with adb?

@bridgemsource
Copy link

Not sure if it helps but I see storage at /sdcard/ now instead of ~/storage/. I ran termux-setup-storage and gave file permissions beforehand but am not sure if either was necessary for this.

@kpedro88
Copy link

I'm having the same issue on a new Pixel 8 with stock Android 14. Installed Termux and Termux:API from f-droid, ran pkg install termux-am, and then termux-setup-storage has exit code 255.

Notably, the app has regular file permissions, but it does not show up in the "All files access" list of apps.

@paschun
Copy link

paschun commented Dec 22, 2023

Not sure if it helps but I see storage at /sdcard/ now instead of ~/storage/. I ran termux-setup-storage and gave file permissions beforehand but am not sure if either was necessary for this.

Yes, thank you @bridgemsource ! Even though the ~/storage links aren't created, I can see folders in /sdcard. However I can't see inside them, maybe because they have permissions 770 (plus setuid on group), and ownership is u0_a121:media_rw. My current user is u0_a135, perhaps ownership got out of sync when I re-installed termux?

Also looks like I can't just add u0_a135 to group media_rw ... https://wiki.termux.com/wiki/Differences_from_Linux#Termux_is_single-user

@EasyClifton
Copy link

I also experienced this issue and after a bit of messing around I think executing am broadcast --user 0 --es com.termux.app.reload_style storage -a com.termux.app.reload_style com.termux manually through adb shell on a PC got it to work.
At some point I also executed adb shell appops set --uid com.termux MANAGE_EXTERNAL_STORAGE allow, which should theoretically grant Termux the permission to access all storage, but I don't think it actually did anything because the app hasn't appeared in the All files access list.

@agnostic-apollo
Copy link
Member

You may want to check Android Settings -> Apps -> Termux -> Permissions -> (Storage | Files and media | Files)

/sdcard is a shortcut for /storage/emulated/0 (path that termux symlinks to) by default for primary user. If app has storage permission, it will be able to access the files under either path. Ownership will not matter due to fuse filesystem.

@paschun
Copy link

paschun commented Dec 23, 2023

Here's the app permissions:

termux

Earlier I said I couldn't see inside the /sdcard/*folders, but that no longer seems to be the case. I'm not sure if something changed. I didn't run any mysterious adb commands, just termux-setup-storage and toggling the app permissions a couple times, maybe a reboot? I can ls -l /storage/emulated/0/DCIM/Camera/ and see the files just fine now.

Although Oddly still, from Termux I can't see older files inside the shared storage root dir ls -la /storage/emulated/0, only the folders - but I can see those files in the Files app. However if I create a new file in the shared storage root I can see it, and it has owner u0_a121 I guess because of fuse like you said.

@timwhite
Copy link

The last line of the script exists with code 255

am broadcast --user 0 \
		 --es com.termux.app.reload_style storage \
		 -a com.termux.app.reload_style com.termux

The logcat has

12-23 20:57:28.920 15912 15912 W bash    : type=1400 audit(0.0:44063): avc:  granted  { execute } for  name="termux-setup-storage" dev="dm-53" ino=174738 scontext=u:r:untrusted_app_27:s0:c209,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c209,c257,c512,c768 tclass=file app=com.termux
12-23 20:57:28.920 15912 15912 W bash    : type=1400 audit(0.0:44064): avc:  granted  { execute } for  name="termux-setup-storage" dev="dm-53" ino=174738 scontext=u:r:untrusted_app_27:s0:c209,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c209,c257,c512,c768 tclass=file app=com.termux
12-23 20:57:28.920 15912 15912 W bash    : type=1400 audit(0.0:44065): avc:  granted  { execute_no_trans } for  path="/data/data/com.termux/files/usr/bin/termux-setup-storage" dev="dm-53" ino=174738 scontext=u:r:untrusted_app_27:s0:c209,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c209,c257,c512,c768 tclass=file app=com.termux
12-23 20:57:28.920 15912 15912 W bash    : type=1400 audit(0.0:44066): avc:  granted  { execute } for  name="bash" dev="dm-53" ino=174443 scontext=u:r:untrusted_app_27:s0:c209,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c209,c257,c512,c768 tclass=file app=com.termux
12-23 20:57:28.920 15912 15912 W termux-setup-st: type=1400 audit(0.0:44067): avc:  granted  { execute } for  path="/data/data/com.termux/files/usr/bin/bash" dev="dm-53" ino=174443 scontext=u:r:untrusted_app_27:s0:c209,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c209,c257,c512,c768 tclass=file app=com.termux
12-23 20:57:28.924 15912 15912 W termux-setup-st: type=1400 audit(0.0:44068): avc:  denied  { search } for  name="tests" dev="dm-53" ino=106 scontext=u:r:untrusted_app_27:s0:c209,c257,c512,c768 tcontext=u:object_r:shell_test_data_file:s0 tclass=dir permissive=0 app=com.termux
12-23 20:57:31.672 16008 16008 W bash    : type=1400 audit(0.0:44106): avc:  granted  { execute } for  name="coreutils" dev="dm-53" ino=174518 scontext=u:r:untrusted_app_27:s0:c209,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c209,c257,c512,c768 tclass=file app=com.termux
12-23 20:57:31.672 16008 16008 W bash    : type=1400 audit(0.0:44107): avc:  granted  { execute } for  name="coreutils" dev="dm-53" ino=174518 scontext=u:r:untrusted_app_27:s0:c209,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c209,c257,c512,c768 tclass=file app=com.termux
12-23 20:57:31.672 16008 16008 W bash    : type=1400 audit(0.0:44108): avc:  granted  { execute_no_trans } for  path="/data/data/com.termux/files/usr/bin/coreutils" dev="dm-53" ino=174518 scontext=u:r:untrusted_app_27:s0:c209,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c209,c257,c512,c768 tclass=file app=com.termux
12-23 20:57:31.672 16008 16008 W ls      : type=1400 audit(0.0:44109): avc:  granted  { execute } for  path="/data/data/com.termux/files/usr/bin/coreutils" dev="dm-53" ino=174518 scontext=u:r:untrusted_app_27:s0:c209,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c209,c257,c512,c768 tclass=file app=com.termux
12-23 20:57:31.680 16008 16008 W ls      : type=1400 audit(0.0:44110): avc:  denied  { search } for  name="tests" dev="dm-53" ino=106 scontext=u:r:untrusted_app_27:s0:c209,c257,c512,c768 tcontext=u:object_r:shell_test_data_file:s0 tclass=dir permissive=0 app=com.termux

After giving the correct permissions manually, it still exists with 255, and the following logcat

12-23 21:06:28.844 17294 17294 W bash    : type=1400 audit(0.0:45821): avc:  granted  { execute } for  name="termux-setup-storage" dev="dm-53" ino=819994 scontext=u:r:untrusted_app_27:s0:c209,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c209,c257,c512,c768 tclass=file app=com.termux
12-23 21:06:28.844 17294 17294 W bash    : type=1400 audit(0.0:45822): avc:  granted  { execute } for  name="termux-setup-storage" dev="dm-53" ino=819994 scontext=u:r:untrusted_app_27:s0:c209,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c209,c257,c512,c768 tclass=file app=com.termux
12-23 21:06:28.844 17294 17294 W bash    : type=1400 audit(0.0:45823): avc:  granted  { execute_no_trans } for  path="/data/data/com.termux/files/usr/bin/termux-setup-storage" dev="dm-53" ino=819994 scontext=u:r:untrusted_app_27:s0:c209,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c209,c257,c512,c768 tclass=file app=com.termux
12-23 21:06:28.844 17294 17294 W bash    : type=1400 audit(0.0:45824): avc:  granted  { execute } for  name="bash" dev="dm-53" ino=174443 scontext=u:r:untrusted_app_27:s0:c209,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c209,c257,c512,c768 tclass=file app=com.termux
12-23 21:06:28.844 17294 17294 W termux-setup-st: type=1400 audit(0.0:45825): avc:  granted  { execute } for  path="/data/data/com.termux/files/usr/bin/bash" dev="dm-53" ino=174443 scontext=u:r:untrusted_app_27:s0:c209,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c209,c257,c512,c768 tclass=file app=com.termux

/sdcard is present and I can read files in it, but the symlink ~/storage isn't created

agnostic-apollo added a commit to termux/termux-api-package that referenced this issue Dec 23, 2023
…always using `TermuxAm` to send intents instead of the socket server that is run by the app

This is currently only done for Android `>= 14` and is a temporary patch until termux-app release is made with finalized support for termux-am-socket to send intents

Closes termux/termux-api#638, termux/termux-app#3754
Related termux/termux-app#3647, termux/TermuxAm@8b9844ab
agnostic-apollo added a commit to termux/TermuxAm that referenced this issue Dec 23, 2023
…on Android `>= 14` but do not wait for result and always exit with exit code 0

When `broadcastIntent()` is called with a `IIntentReceiver resultTo` to be able to get back the broadcast result, Android uses the `IApplicationThread caller` passed to get the `ProcessRecord` of the app from its internal cache (`getRecordForAppLOSP()`) based on the `caller`. Since `TermuxAm` uses a fake `IApplicationThread` that does not belong to an app, the `resultToApp` would not be found. For this, android logs the `Sending broadcast <action> with resultTo requires resultToApp` exception and terminates the process. To prevent this from happening, we do not pass the `resultTo` so that Android uses the `system_server` `ProcessRecord` instead at the cost of not being able to get back the result for the broadcast. This will trigger the following exception in `logcat`, but if broadcast was valid, then it will still have been sent.

```
java.lang.RuntimeException: BroadcastReceiver trying to return result during a non-ordered broadcast
	at android.content.BroadcastReceiver$PendingResult.checkSynchronousHint(BroadcastReceiver.java:351)
	at android.content.BroadcastReceiver$PendingResult.setResultCode(BroadcastReceiver.java:154)
	at com.termux.api.util.ResultReturner.lambda$returnData$0(ResultReturner.java:196)
	at com.termux.api.util.ResultReturner$$ExternalSyntheticLambda0.run(Unknown Source:8)
	at java.lang.Thread.run(Thread.java:1012)
```

- https://cs.android.com/android/_/android/platform/frameworks/base/+/a51563231919be01f2d3de53a88df70154ac8992
- https://cs.android.com/android/platform/superproject/+/android-14.0.0_r1:frameworks/base/core/java/android/content/BroadcastReceiver.java;l=350
- https://cs.android.com/android/platform/superproject/+/android-14.0.0_r1:frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java;l=14391
https://cs.android.com/android/platform/superproject/+/android-14.0.0_r1:frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java;l=15309

We cannot use `/system/bin/am` on Android `14` December security patch as `am` commands can only be run with `adb` and `root` users now. Normally, no output will be received when the command will be run and exit code will be `255`. I got the exception once, not sure how to reproduce, there is likely some AOSP bug, using subshell hack and even disabling selinux does not work, but it did get logged while selinux was disabled.

- https://cs.android.com/android/_/android/platform/frameworks/base/+/3ef3f18ba3094c4cc4f954ba23d1da421f9ca8b0

```
java.lang.SecurityException: Shell commands are only callable by root or shell
 at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
 at android.os.Parcel.createException(Parcel.java:3041)
 at android.os.Parcel.readException(Parcel.java:3024)
 at android.os.Parcel.readException(Parcel.java:2966)
 at android.os.BinderProxy.shellCommand(BinderProxy.java:692)
 at com.android.commands.am.Am.runAmCmd(Am.java:146)
 at com.android.commands.am.Am.onRun(Am.java:87)
 at com.android.internal.os.BaseCommand.run(BaseCommand.java:62)
 at com.android.commands.am.Am.main(Am.java:54)
 at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
 at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:359)
Caused by: android.os.RemoteException: Remote stack trace:
 at com.android.server.am.ActivityManagerService.onShellCommand(ActivityManagerService.java:9763)
 at android.os.Binder.shellCommand(Binder.java:1071)
 at android.os.Binder.onTransact(Binder.java:888)
 at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:5267)
 at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2763)
 ```

Closes termux/termux-app#3754
Related termux/termux-app#3647, termux/termux-api#638
@agnostic-apollo
Copy link
Member

termux/termux-api#638 (comment)

@timwhite
Copy link

Running the below now fixes the problem. Thanks @agnostic-apollo

apt update
apt install termux-api termux-am

@agnostic-apollo
Copy link
Member

Great. You are welcome.

@twaik
Copy link
Member

twaik commented Dec 27, 2023

It is still showing aborted in my case🥲

Can you please post logcat after running termux-am?

@RevealedSoulEven
Copy link

Ahhh now it's working. I was using Android5 build maybe, then I noticed there are android7 builds which did work

@agnostic-apollo
Copy link
Member

Running termux-am will run termux-am-socket and running am will run TermuxAm provided by termux-am package, which is what's required.

@RevealedSoulEven
Copy link

Thanks a lot devs for the quick replies.

@cristobal-db
Copy link

I followed all the steps until the last one and it still denies my access and it still aborts in my case I have a s23u

@agnostic-apollo
Copy link
Member

What's the output of apt show termux-am termux-api termux-tools

@laur89
Copy link

laur89 commented Dec 31, 2023

Run pkg install termux-am.

Could this please be added to the relevant docs?

@mmiller7
Copy link

Hitting this issue with a Samsung S23...doing "pkg install termux-am" installed a package but didn't fix it. Attempting "apt install termux-api" says no candidates.

@Fly3RC
Copy link

Fly3RC commented Mar 4, 2024

@rampadmin Just enable "Settings → Developer Options → Disable child process restrictions" before running
termux-setup-storage

@sylirre
Copy link
Member

sylirre commented Mar 4, 2024

@Fly3RC This has nothing to do with child process restrictions (phantom process killer).

@100497
Copy link

100497 commented Apr 28, 2024

pkg install termux-am
That works

@jstephencorey
Copy link

For me, installing termux-am, then running termux-setup-storage worked. I'm running Android 14 on a pixel 7.

@Salientekill
Copy link

Make sure to run pkg install termux-am on Android 14 before reporting issues.

Storage permissions are given in the following way.

  • Android < 11: Android Settings -> Apps -> Termux -> Permissions -> Storage
  • Android >= 11: Android Settings -> Apps -> Termux -> Permissions -> Files and media -> Allow management of all files
  • Android >= 13: Android Settings -> Apps -> (Advanced ->) Special app access -> All files access -> Termux

If using GitHub action builds, then running test -d "$HOME/storage" || termux-am broadcast --user 0 --es com.termux.app.reload_style storage -a com.termux.app.reload_style com.termux > /dev/null should work.

As for termux-setup-storage not working, post or email me adb logcat -d > logcat.txt output after running command.

Thank you, I was getting desperate as I couldn't find a solution, it just meant full access to the files

@jasonm23
Copy link

Small caveat, after doing

pkg install termux-am

Allowed me to run

termux-setup-storage

Without errors, but with Files permissions on for Termux, I got permission errors doing:

ls ~/storage/downloads

I added photos and music permissions to Termux, after that working fine.

@twaik
Copy link
Member

twaik commented May 29, 2024

I can add something to this.
image

@agnostic-apollo can you please make Termux ask for multimedia and all-files permissions too please (via termux-storage-setup command)?

@agnostic-apollo
Copy link
Member

Android 14 already request other multimedia permissions when READ_EXTERNAL_STORAGE is requested. Anyways, termux will request all files access of android >= 11 from next version instead of READ_EXTERNAL_STORAGE regardless of targetSdkVersion, so should not be an issue.

Screenshot_1716984718

@vishnudas-bluefox
Copy link

Does anyone find the solution?????

@jasonm23
Copy link

@bluefox8976 - what happened when you try the solution I outlined.

Could you explain the step where it failed, or any other details that might be relevant?

@jasonm23
Copy link

jasonm23 commented Jun 11, 2024

(it'll be important to know how / where you installed Termux from, that you have the latest version or not, you know the drill.) @bluefox8976

@sylirre
Copy link
Member

sylirre commented Jun 11, 2024

The latest version is 0.118. Ignore these 0.120, 0.122+ currently published on Play Store.

Current latest version tag can be always viewed by this permanent link: https://github.com/termux/termux-app/releases/latest

@jasonm23
Copy link

jasonm23 commented Jun 11, 2024

@sylirre - thanks I should've mentioned that too.

FDroid releases are not as up to date as what you can get from https://github.com/termux/termux-app/releases/latest so it's best to use no app stores for Termux

@sylirre
Copy link
Member

sylirre commented Jun 11, 2024

FDroid releases are not as up to date as what you can get from https://github.com/termux/termux-app/releases/latest

They are equally same except signatures.

versioncompare

Newer version can be obtained only from per-commit builds (GitHub Actions).

@isman-rtkpd
Copy link

Termux closed when running termux-setup-storage
When I checked the permission, "No permission requested"
image

@Grimler91
Copy link
Member

@isman-rtkpd I guess that means that you are using a fork: #4000

agnostic-apollo added a commit that referenced this issue Jun 17, 2024
…`>= 11` when running `termux-setup-storage`

Requesting `MANAGE_EXTERNAL_STORAGE` should additionally grant access to unreliable/removable volumes like USB OTG devices under the `/mnt/media_rw/XXXX-XXXX` paths on `Android >= 12`, so request that if possible. Check #71 (comment) for more info.

Fixes issue on Android `14`, where using `targetSdkVersion=28`, that requests the legacy `WRITE_EXTERNAL_STORAGE` will actually request the `photos, music, video, and other files` permissions (`READ_MEDIA_AUDIO`/`READ_MEDIA_IMAGES`/`READ_MEDIA_VIDEO`) and apparently access to full external storage `/sdcard` is not available for some users, maybe because `READ_EXTERNAL_STORAGE` and `WRITE_EXTERNAL_STORAGE` permissions are not granted for those device automatically in addition to `READ_MEDIA_*` permission. The issue is not reproducible on Android `13-15` avd. To solve this, we request the singular `MANAGE_EXTERNAL_STORAGE` permission instead so that full access is always available.

Related: #3647 (comment)

See also:
- https://developer.android.com/training/data-storage/shared/media#access-other-apps-files
- https://developer.android.com/reference/android/Manifest.permission#READ_MEDIA_IMAGES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests