I am modifying the AudioSystem.cpp code which is part of the mediaserver process running in Android Framework. I added few lines of code in order to make it to write a file located in the sdcard of a Nexus 5 phone.
I am using the following code:
int fd = open("/mnt/shell/emulated/0/file.txt", O_RDWR | O_APPEND | O_CREAT, 0666);
if(fd > -1) {
__android_log_print(ANDROID_LOG_DEBUG, "gxp18", "Writing to SDCARD");
write(fd, "1", strlen("1"));
write(fd, "\n", 1);
close(fd);
}
I am always getting fd = -1. I don't have idea why it fails. In the phone FS I can see that only root and sdcard_r can access the folder:
shell@hammerhead:/mnt/shell/emulated $ ll
drwxrwx--x root sdcard_r 1970-07-04 21:05 0
Interestingly the symbolic link to the sdcard is declare as world readable and writable:
shell@hammerhead:/ $ ll
lrwxrwxrwx root root 1970-07-04 21:04 sdcard -> /storage/emulated/legacy
shell@hammerhead:/storage/emulated $ ll
lrwxrwxrwx root root 1970-07-04 21:04 legacy -> /mnt/shell/emulated/0
I am completely lost. why my write in the AudioSystem.cpp always fails?
Thanks in advance ;)