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

Commit e4880e42 authored by Mike Lockwood's avatar Mike Lockwood
Browse files

MTP: Improve MtpProperty logging support



Change-Id: I46800b99763edcc5e994d912941f9f5e9b1c94d2
Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent 5768f108
Loading
Loading
Loading
Loading
+40 −5
Original line number Diff line number Diff line
@@ -63,21 +63,17 @@ void MtpDevice::initialize() {
    openSession();
    mDeviceInfo = getDeviceInfo();
    if (mDeviceInfo) {
        mDeviceInfo->print();

        if (mDeviceInfo->mDeviceProperties) {
            int count = mDeviceInfo->mDeviceProperties->size();
            for (int i = 0; i < count; i++) {
                MtpDeviceProperty propCode = (*mDeviceInfo->mDeviceProperties)[i];
                MtpProperty* property = getDevicePropDesc(propCode);
                if (property) {
                    property->print();
                if (property)
                    mDeviceProperties.push(property);
            }
        }
    }
}
}

void MtpDevice::close() {
    if (mDevice) {
@@ -87,6 +83,45 @@ void MtpDevice::close() {
    }
}

void MtpDevice::print() {
    if (mDeviceInfo) {
        mDeviceInfo->print();

        if (mDeviceInfo->mDeviceProperties) {
            LOGI("***** DEVICE PROPERTIES *****\n");
            int count = mDeviceInfo->mDeviceProperties->size();
            for (int i = 0; i < count; i++) {
                MtpDeviceProperty propCode = (*mDeviceInfo->mDeviceProperties)[i];
                MtpProperty* property = getDevicePropDesc(propCode);
                if (property) {
                    property->print();
                }
            }
        }
    }

    if (mDeviceInfo->mPlaybackFormats) {
            LOGI("***** OBJECT PROPERTIES *****\n");
        int count = mDeviceInfo->mPlaybackFormats->size();
        for (int i = 0; i < count; i++) {
            MtpObjectFormat format = (*mDeviceInfo->mPlaybackFormats)[i];
            LOGI("*** FORMAT: %s\n", MtpDebug::getFormatCodeName(format));
            MtpObjectPropertyList* props = getObjectPropsSupported(format);
            if (props) {
                for (int j = 0; j < props->size(); j++) {
                    MtpObjectProperty prop = (*props)[j];
                    MtpProperty* property = getObjectPropDesc(prop);
                    if (property)
                        property->print();
                    else
                        LOGE("could not fetch property: %s",
                                MtpDebug::getObjectPropCodeName(prop));
                }
            }
        }
    }
}

const char* MtpDevice::getDeviceName() {
    if (mDevice)
        return usb_device_get_name(mDevice);
+1 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ public:

    void                    initialize();
    void                    close();
    void                    print();
    const char*             getDeviceName();

    bool                    openSession();
+88 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#define LOG_TAG "MtpProperty"

#include "MtpDataPacket.h"
#include "MtpDebug.h"
#include "MtpProperty.h"
#include "MtpStringBuffer.h"
#include "MtpUtils.h"
@@ -317,9 +318,93 @@ void MtpProperty::setFormDateTime() {
}

void MtpProperty::print() {
    LOGV("MtpProperty %04X\n", mCode);
    LOGV("    type %04X\n", mType);
    LOGV("    writeable %s\n", (mWriteable ? "true" : "false"));
    MtpString buffer;
    bool deviceProp = isDeviceProperty();
    if (deviceProp)
        LOGI("    %s (%04X)", MtpDebug::getDevicePropCodeName(mCode), mCode);
    else
        LOGI("    %s (%04X)", MtpDebug::getObjectPropCodeName(mCode), mCode);
    LOGI("    type %04X", mType);
    LOGI("    writeable %s", (mWriteable ? "true" : "false"));
    buffer = "    default value: ";
    print(mDefaultValue, buffer);
    LOGI("%s", (const char *)buffer);
    if (deviceProp) {
        buffer = "    current value: ";
        print(mCurrentValue, buffer);
        LOGI("%s", (const char *)buffer);
    }
    switch (mFormFlag) {
        case kFormNone:
            break;
        case kFormRange:
            buffer = "    Range (";
            print(mMinimumValue, buffer);
            buffer += ", ";
            print(mMaximumValue, buffer);
            buffer += ", ";
            print(mStepSize, buffer);
            LOGI("%s", (const char *)buffer);
            break;
        case kFormEnum:
            buffer = "    Enum { ";
            for (int i = 0; i < mEnumLength; i++) {
                print(mEnumValues[i], buffer);
                buffer += " ";
            }
            buffer += "}";
            LOGI("%s", (const char *)buffer);
            break;
        case kFormDateTime:
            LOGI("    DateTime\n");
            break;
        default:
            LOGI("    form %d\n", mFormFlag);
            break;
    }
}

void MtpProperty::print(MtpPropertyValue& value, MtpString& buffer) {
    switch (mType) {
        case MTP_TYPE_INT8:
            buffer.appendFormat("%d", value.u.i8);
            break;
        case MTP_TYPE_UINT8:
            buffer.appendFormat("%d", value.u.u8);
            break;
        case MTP_TYPE_INT16:
            buffer.appendFormat("%d", value.u.i16);
            break;
        case MTP_TYPE_UINT16:
            buffer.appendFormat("%d", value.u.u16);
            break;
        case MTP_TYPE_INT32:
            buffer.appendFormat("%d", value.u.i32);
            break;
        case MTP_TYPE_UINT32:
            buffer.appendFormat("%d", value.u.u32);
            break;
        case MTP_TYPE_INT64:
            buffer.appendFormat("%lld", value.u.i64);
            break;
        case MTP_TYPE_UINT64:
            buffer.appendFormat("%lld", value.u.u64);
            break;
        case MTP_TYPE_INT128:
            buffer.appendFormat("%08X%08X%08X%08X", value.u.i128[0], value.u.i128[1],
                    value.u.i128[2], value.u.i128[3]);
            break;
        case MTP_TYPE_UINT128:
            buffer.appendFormat("%08X%08X%08X%08X", value.u.u128[0], value.u.u128[1],
                    value.u.u128[2], value.u.u128[3]);
            break;
        case MTP_TYPE_STR:
            buffer.appendFormat("%s", value.str);
            break;
        default:
            LOGE("unsupported type for MtpProperty::print\n");
            break;
    }
}

void MtpProperty::readValue(MtpDataPacket& packet, MtpPropertyValue& value) {
+1 −0
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ public:
    void                setFormDateTime();

    void                print();
    void                print(MtpPropertyValue& value, MtpString& buffer);

    inline bool         isDeviceProperty() const {
                            return (   ((mCode & 0xF000) == 0x5000)