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

Commit fcfb516b authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

Improve AudioPolicyManager dump, Part 2

- Align devices representation between various parts of the dump.
- Align device and mix ports format in the patches dump.

This allows unified searching of devices and port instances.

Bug: 205884982
Test: adb shell dumpsys media.audio_policy
Change-Id: I9c96ff8214c003dd4af2b9cb74d261b4f4423227
parent bf6c4d41
Loading
Loading
Loading
Loading
+18 −32
Original line number Diff line number Diff line
@@ -70,48 +70,34 @@ const DeviceTypeSet& getAudioDeviceOutAllBleSet() {
    return audioDeviceOutAllBleSet;
}

bool deviceTypesToString(const DeviceTypeSet &deviceTypes, std::string &str) {
std::string deviceTypesToString(const DeviceTypeSet &deviceTypes) {
    if (deviceTypes.empty()) {
        str = "Empty device types";
        return true;
        return "Empty device types";
    }
    bool ret = true;
    for (auto it = deviceTypes.begin(); it != deviceTypes.end();) {
        std::string deviceTypeStr;
        ret = audio_is_output_device(*it) ?
              OutputDeviceConverter::toString(*it, deviceTypeStr) :
              InputDeviceConverter::toString(*it, deviceTypeStr);
        if (!ret) {
            break;
        }
        str.append(deviceTypeStr);
        if (++it != deviceTypes.end()) {
            str.append(" , ");
    std::stringstream ss;
    for (auto it = deviceTypes.begin(); it != deviceTypes.end(); ++it) {
        if (it != deviceTypes.begin()) {
            ss << ", ";
        }
        const char* strType = audio_device_to_string(*it);
        if (strlen(strType) != 0) {
            ss << strType;
        } else {
            ss << "unknown type:0x" << std::hex << *it;
        }
    if (!ret) {
        str = "Unknown values";
    }
    return ret;
    return ss.str();
}

std::string dumpDeviceTypes(const DeviceTypeSet &deviceTypes) {
    std::string ret;
    for (auto it = deviceTypes.begin(); it != deviceTypes.end();) {
    std::stringstream ss;
        ss << "0x" << std::hex << (*it);
        ret.append(ss.str());
        if (++it != deviceTypes.end()) {
            ret.append(" , ");
    for (auto it = deviceTypes.begin(); it != deviceTypes.end(); ++it) {
        if (it != deviceTypes.begin()) {
            ss << ", ";
        }
        ss << "0x" << std::hex << (*it);
    }
    return ret;
}

std::string toString(const DeviceTypeSet& deviceTypes) {
    std::string ret;
    deviceTypesToString(deviceTypes, ret);
    return ret;
    return ss.str();
}

} // namespace android
+5 −2
Original line number Diff line number Diff line
@@ -100,7 +100,10 @@ void AudioDeviceTypeAddr::reset() {

std::string AudioDeviceTypeAddr::toString(bool includeSensitiveInfo) const {
    std::stringstream sstream;
    sstream << "type:0x" << std::hex << mType;
    sstream << audio_device_to_string(mType);
    if (sstream.str().empty()) {
        sstream << "unknown type:0x" << std::hex << mType;
    }
    // IP and MAC address are sensitive information. The sensitive information will be suppressed
    // is `includeSensitiveInfo` is false.
    sstream << ", @:"
+1 −2
Original line number Diff line number Diff line
@@ -121,8 +121,7 @@ void DeviceDescriptorBase::dump(std::string *dst, int spaces, int index,
    if (extraInfo != nullptr) {
        dst->append(base::StringPrintf("%s; ", extraInfo));
    }
    dst->append(base::StringPrintf("%s (%s)\n",
                    audio_device_to_string(mDeviceTypeAddr.mType),
    dst->append(base::StringPrintf("{%s}\n",
                    mDeviceTypeAddr.toString(true /*includeSensitiveInfo*/).c_str()));

    dst->append(base::StringPrintf(
+4 −2
Original line number Diff line number Diff line
@@ -131,14 +131,16 @@ static inline DeviceTypeSet deviceTypesFromBitMask(audio_devices_t types) {
    return deviceTypes;
}

bool deviceTypesToString(const DeviceTypeSet& deviceTypes, std::string &str);
std::string deviceTypesToString(const DeviceTypeSet& deviceTypes);

std::string dumpDeviceTypes(const DeviceTypeSet& deviceTypes);

/**
 * Return human readable string for device types.
 */
std::string toString(const DeviceTypeSet& deviceTypes);
inline std::string toString(const DeviceTypeSet& deviceTypes) {
    return deviceTypesToString(deviceTypes);
}


} // namespace android
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ public:

    void setUid(uid_t uid) { mUid = uid; }

    void dump(String8 *dst, int spaces, int index) const;
    void dump(String8 *dst, int spaces) const;

    struct audio_patch mPatch;

Loading