So far I've been using adb run-as and cat to extract files from apps private storage /data/user/0/com.myapp.android. Simply catting the file and piping it to a local file on my pc worked a treat.

Now i'm trying to do the opposite, send a file from my PC to apps private storage. I thought of using adb push to send the file to a shared storage location and then using run-as to copy the file internally to the private storage.

I have given my app READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permission, and linux permission knowledge seems to suggest I should be able to access the shared storage, but I won't, as seen in the example:

# Running as default user works fine
OnePlus9Pro:/ $ ls -l /sdcard/Android/data/com.myapp.android                                                                                                                                                                                
total 3
drwxrws--- 2 u0_a347 ext_data_rw 3452 2022-08-19 12:03 files

# Running as the application won't work
OnePlus9Pro:/ $ run-as com.myapp.android ls -l /sdcard/Android/data/com.myapp.android                                                                                                                                                    
ls: /sdcard/Android/data/com.myapp.android: Permission denied

# But the application user is the owner of the directory?!
OnePlus9Pro:/ $ run-as com.myapp.android id                                                                                                                                                                                               
uid=10347(u0_a347) gid=10347(u0_a347) groups=10347(u0_a347),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),1078(ext_data_rw),1079(ext_obb_rw),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats),3009(readproc),3011(uhid),3012,50347(all_a347) context=u:r:runas_app:s0:c91,c257,c512,c768

From here you can see the shared storage (/sdcard/Android/data/com.myapp.android ) is owned by user u0_a347 with full permissions. run-as com.myapp.android is executing under u0_a347 and in addition it has ext_data_rw group as well.

How can I access both shared storage and application private storage at the same time?

  • 2
    Apparently adb command worksfine with stdin, so I was able to copy the using cat data/storage.sqlite | adb shell com.myapp.android dd of=databases/RKStorage. Still curious about the permissions though.
    – Kristian
    Commented Aug 19, 2022 at 10:42
  • 1
    Android permissions are for apps which run-as is not. All ADB commands run with the privileges of "Shell" (com.android.shell) app which already has Storage permission granted for primary user (but not for secondary users / profiles: android.stackexchange.com/a/221534/218526). Commented Aug 19, 2022 at 11:21
  • 1
    cat data/storage.sqlite | adb exec-in 'run-as com.myapp.android cat > databases/RKStorage'
    – alecxs
    Commented Aug 19, 2022 at 13:21
  • @IrfanLatif If i understand this correctly, then the matching unix user and group id-s don't matter since android implements it's own layer on top of that?
    – Kristian
    Commented Aug 30, 2022 at 8:08


You must log in to answer this question.

Browse other questions tagged .