androidandroid-permissionsandroid-sourceaudioflingerandroid-rom

Attempting to open output file inside audioflinger (AOSP)


I'm attempting to write a simple log file from inside av/services/audioflinger/AudioStreamOut.cpp, for testing a custom ROM. I need it to work on Nexus 5X (bullhead).

if (logFile1 == NULL)
    logFile1 = fopen("/sdcard/log_before.pcm", "ab");


if (logFile1 == NULL)
    ALOGE("can't open 1, errno %d", errno);

I'm getting permission denied (ERRNO is 13).

I tried modifying frameworks/base/data/etc/platform.xml by adding the following:

<assign-permission name="android.permission.WRITE_EXTERNAL_STORAGE" uid="media" />
<assign-permission name="android.permission.WRITE_EXTERNAL_STORAGE" uid="audioserver" />
<assign-permission name="android.permission.WRITE_EXTERNAL_STORAGE" uid="audio" />

Still no change. How can I get this to work? Or is there another place in the filesystem where a system service like audioflinger is supposed to use for writing files?

UPDATE:

I just found a solution that works for emulator - in Android N, write to /data/misc/audioserver.

When I use ADB shell, it shows me that this particular folder has the "audioserver" group, which is why it works.

I found about this folder from this link: https://source.android.com/devices/audio/debugging.html

But this folder seems not accessible on Nexus 5X - can't get to it with shell, even with su root.


Solution

  • I found a way around the permission issue.

    First, write the log file to /data/misc/audioserver

    Then:

    adb shell su root cp /data/misc/audioserver/log_before.pcm sdcard/.
    

    Etc.

    And then I can pull the file:

    adb pull /sdcard/log_before.pcm .