Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7ced919c authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

AudioPolicy: Improve audio patches dump

Was:

    Audio Patches:
      Audio patch 1:
      - handle:  5
      - audio flinger handle: 12
      - owner uid: 1041
      - 1 sources:
        - Mix ID 1 I/O handle 13
      - 1 sinks:
        - Device ID 3 AUDIO_DEVICE_OUT_SPEAKER

Now:

    Audio Patches:
      Patch 1: owner uid 1041, handle  5, af handle 12
        [src  1] Mix ID 1 I/O handle 13
        [sink 1] Device ID 3 AUDIO_DEVICE_OUT_SPEAKER

Test: adb shell dumpsys media.audio_policy
Change-Id: I164ab9b384e77929ef44dae019b7ec15239dceaa
parent 99c58a82
Loading
Loading
Loading
Loading
+19 −38
Original line number Diff line number Diff line
@@ -34,51 +34,32 @@ AudioPatch::AudioPatch(const struct audio_patch *patch, uid_t uid) :
{
}

status_t AudioPatch::dump(int fd, int spaces, int index) const
static String8 dumpPatchEndpoints(
        int spaces, const char *prefix, int count, const audio_port_config *cfgs)
{
    const size_t SIZE = 256;
    char buffer[SIZE];
    String8 result;

    snprintf(buffer, SIZE, "%*sAudio patch %d:\n", spaces, "", index+1);
    result.append(buffer);
    snprintf(buffer, SIZE, "%*s- handle: %2d\n", spaces, "", mHandle);
    result.append(buffer);
    snprintf(buffer, SIZE, "%*s- audio flinger handle: %2d\n", spaces, "", mAfPatchHandle);
    result.append(buffer);
    snprintf(buffer, SIZE, "%*s- owner uid: %2d\n", spaces, "", mUid);
    result.append(buffer);
    snprintf(buffer, SIZE, "%*s- %d sources:\n", spaces, "", mPatch.num_sources);
    result.append(buffer);
    for (size_t i = 0; i < mPatch.num_sources; i++) {
        if (mPatch.sources[i].type == AUDIO_PORT_TYPE_DEVICE) {
    for (int i = 0; i < count; ++i) {
        const audio_port_config &cfg = cfgs[i];
        result.appendFormat("%*s  [%s %d] ", spaces, "", prefix, i + 1);
        if (cfg.type == AUDIO_PORT_TYPE_DEVICE) {
            std::string device;
            deviceToString(mPatch.sources[i].ext.device.type, device);
            snprintf(buffer, SIZE, "%*s- Device ID %d %s\n", spaces + 2, "",
                     mPatch.sources[i].id,
                     device.c_str());
            deviceToString(cfg.ext.device.type, device);
            result.appendFormat("Device ID %d %s", cfg.id, device.c_str());
        } else {
            snprintf(buffer, SIZE, "%*s- Mix ID %d I/O handle %d\n", spaces + 2, "",
                     mPatch.sources[i].id, mPatch.sources[i].ext.mix.handle);
        }
        result.append(buffer);
            result.appendFormat("Mix ID %d I/O handle %d", cfg.id, cfg.ext.mix.handle);
        }
    snprintf(buffer, SIZE, "%*s- %d sinks:\n", spaces, "", mPatch.num_sinks);
    result.append(buffer);
    for (size_t i = 0; i < mPatch.num_sinks; i++) {
        if (mPatch.sinks[i].type == AUDIO_PORT_TYPE_DEVICE) {
            std::string device;
            deviceToString(mPatch.sinks[i].ext.device.type, device);
            snprintf(buffer, SIZE, "%*s- Device ID %d %s\n", spaces + 2, "",
                     mPatch.sinks[i].id,
                     device.c_str());
        } else {
            snprintf(buffer, SIZE, "%*s- Mix ID %d I/O handle %d\n", spaces + 2, "",
                     mPatch.sinks[i].id, mPatch.sinks[i].ext.mix.handle);
        result.append("\n");
    }
        result.append(buffer);
    return result;
}

status_t AudioPatch::dump(int fd, int spaces, int index) const
{
    String8 result;
    result.appendFormat("%*sPatch %d: owner uid %4d, handle %2d, af handle %2d\n",
            spaces, "", index + 1, mUid, mHandle, mAfPatchHandle);
    result.append(dumpPatchEndpoints(spaces, "src ", mPatch.num_sources, mPatch.sources));
    result.append(dumpPatchEndpoints(spaces, "sink", mPatch.num_sinks, mPatch.sinks));
    write(fd, result.string(), result.size());
    return NO_ERROR;
}