How to add picture files to media/Pictures on virtual device

I’m trying to create an Anbox application where new instances will have some images in the media/Pictures directory that the user of the device can see and use.

I’ve tried placing the image files in a folder in my application definition and then copying them to where I think they should go in my post-start hook like so:

if  [ "$INSTANCE_TYPE" = "regular" ]; then
  exit 0
fi

cp /var/lib/anbox/app/media/* /var/lib/anbox/data/media/0/Pictures

I get the following error:

target '/var/lib/anbox/data/media/0/Pictures' is not a directory

This directory does exist on the completed instance once I’ve connected, but it doesn’t seem to when the hook is being run.

Should I copy the files somewhere else, or is there another way to do this?

Hey @al-p
Thanks for reaching out.
You’ve encountered a timing issue. At the point when the post-stop hook is executed for a base instance, the path /var/lib/anbox/data/media/0 and its subdirectories have not been fully created and initialized by the volume daemon (vold). The following logs imply that:

sh[1312]: + ls -al /var/lib/anbox/data/media/0
sh[1313]: ls: cannot access '/var/lib/anbox/data/media/0': No such file or directory
sh[1312]: + sleep 1
sh[1312]: + true
sh[1312]: + ls -al /var/lib/anbox/data/media/0
sh[1618]: total 20
sh[1618]: drwxrws---+ 5 101023 101023 4096 Jul  8 09:26 .
sh[1618]: drwxrwx---  4 101023 101023 4096 Jul  8 09:26 ..
sh[1618]: drwxrws--x+ 5 101023 101023 4096 Jul  8 09:26 Android
sh[1618]: drwxrws---+ 2 110078 101023 4096 Jul  8 09:26 Download
sh[1618]: drwxrws---+ 4 110078 101023 4096 Jul  8 09:26 .transforms
sh[1312]: + sleep 1
sh[1312]: + true
sh[1312]: + ls -al /var/lib/anbox/data/media/0
sh[1969]: total 1132
sh[1969]: drwxrws---+ 15 101023 101023    4096 Jul  8 09:26 .
sh[1969]: drwxrwx---   4 101023 101023    4096 Jul  8 09:26 ..
sh[1969]: drwxrws---+  2 110078 101023    4096 Jul  8 09:26 Alarms
sh[1969]: drwxrws--x+  5 101023 101023    4096 Jul  8 09:26 Android
sh[1969]: drwxrws---+  2 110078 101023    4096 Jul  8 09:26 Audiobooks
sh[1969]: drwxrws---+  2 110078 101023    4096 Jul  8 09:26 DCIM
sh[1969]: drwxrws---+  2 110078 101023    4096 Jul  8 09:26 Documents
sh[1969]: drwxrws---+  2 110078 101023    4096 Jul  8 09:26 Download
sh[1969]: drwxrws---+  3 110078 101023    4096 Jul  8 09:26 Movies
sh[1969]: drwxrws---+  3 110078 101023    4096 Jul  8 09:26 Music
sh[1969]: drwxrws---+  2 110078 101023    4096 Jul  8 09:26 Notifications
sh[1969]: -rw-r-----+  1 110078 101023 1096131 Jul  8 09:26 Pictures
sh[1969]: drwxrws---+  2 110078 101023    4096 Jul  8 09:26 Podcasts
sh[1969]: drwxrws---+  2 110078 101023    4096 Jul  8 09:26 Recordings
sh[1969]: drwxrws---+  2 110078 101023    4096 Jul  8 09:26 Ringtones
sh[1969]: drwxrws---+  4 110078 101023    4096 Jul  8 09:26 .transforms

To mitigate this situation, you could check for the existence of the target directory before executing the cp command. Hopefully, this would be helpful.

BR
Gary