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

Commit ff68468f authored by Mike Lockwood's avatar Mike Lockwood Committed by Android (Google) Code Review
Browse files

Merge changes I4f117090,Ifd449c4e

* changes:
  MTP: Push queries for supported formats and properties up to Java.
  MTP: turn off verbose logging
parents 38b7eb96 4b322ce4
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -308,6 +308,13 @@ public final class Mtp
        public static final int FORMAT_ABSTRACT_CONTACT = 0xBB81;
        public static final int FORMAT_VCARD_2 = 0xBB82;

        // Object properties we support
        public static final int PROPERTY_STORAGE_ID = 0xDC01;
        public static final int PROPERTY_OBJECT_FORMAT = 0xDC02;
        public static final int PROPERTY_OBJECT_SIZE = 0xDC04;
        public static final int PROPERTY_OBJECT_FILE_NAME = 0xDC07;
        public static final int PROPERTY_PARENT_OBJECT = 0xDC0B;

        /**
         * Object is not protected. It may be modified and deleted, and its properties
         * may be modified.
+44 −0
Original line number Diff line number Diff line
@@ -220,6 +220,50 @@ public class MtpDatabase {
        return -1;
    }

    private int[] getSupportedPlaybackFormats() {
        return new int[] {
            Mtp.Object.FORMAT_ASSOCIATION,
            Mtp.Object.FORMAT_MP3,
            Mtp.Object.FORMAT_MPEG,
            Mtp.Object.FORMAT_EXIF_JPEG,
            Mtp.Object.FORMAT_TIFF_EP,
            Mtp.Object.FORMAT_GIF,
            Mtp.Object.FORMAT_JFIF,
            Mtp.Object.FORMAT_PNG,
            Mtp.Object.FORMAT_TIFF,
            Mtp.Object.FORMAT_WMA,
            Mtp.Object.FORMAT_OGG,
            Mtp.Object.FORMAT_AAC,
            Mtp.Object.FORMAT_MP4_CONTAINER,
            Mtp.Object.FORMAT_MP2,
            Mtp.Object.FORMAT_3GP_CONTAINER,
            Mtp.Object.FORMAT_ABSTRACT_AV_PLAYLIST,
            Mtp.Object.FORMAT_WPL_PLAYLIST,
            Mtp.Object.FORMAT_M3U_PLAYLIST,
            Mtp.Object.FORMAT_PLS_PLAYLIST,
        };
    }

    private int[] getSupportedCaptureFormats() {
        // no capture formats yet
        return null;
    }

    private int[] getSupportedObjectProperties(int handle) {
        return new int[] {
            Mtp.Object.PROPERTY_STORAGE_ID,
            Mtp.Object.PROPERTY_OBJECT_FORMAT,
            Mtp.Object.PROPERTY_OBJECT_SIZE,
            Mtp.Object.PROPERTY_OBJECT_FILE_NAME,
            Mtp.Object.PROPERTY_PARENT_OBJECT,
        };
    }

    private int[] getSupportedDeviceProperties() {
        // no device properties yet
        return null;
    }

    private int getObjectProperty(int handle, int property,
                            long[] outIntValue, char[] outStringValue) {
        Log.d(TAG, "getObjectProperty: " + property);
+91 −0
Original line number Diff line number Diff line
@@ -40,6 +40,10 @@ static jmethodID method_beginSendObject;
static jmethodID method_endSendObject;
static jmethodID method_getObjectList;
static jmethodID method_getNumObjects;
static jmethodID method_getSupportedPlaybackFormats;
static jmethodID method_getSupportedCaptureFormats;
static jmethodID method_getSupportedObjectProperties;
static jmethodID method_getSupportedDeviceProperties;
static jmethodID method_getObjectProperty;
static jmethodID method_getObjectInfo;
static jmethodID method_getObjectFilePath;
@@ -87,6 +91,13 @@ public:
                                            MtpObjectFormat format,
                                            MtpObjectHandle parent);

    // callee should delete[] the results from these
    // results can be NULL
    virtual MtpObjectFormatList*    getSupportedPlaybackFormats();
    virtual MtpObjectFormatList*    getSupportedCaptureFormats();
    virtual MtpObjectPropertyList*  getSupportedObjectProperties(MtpObjectFormat format);
    virtual MtpDevicePropertyList*  getSupportedDeviceProperties();

    virtual MtpResponseCode         getObjectProperty(MtpObjectHandle handle,
                                            MtpObjectProperty property,
                                            MtpDataPacket& packet);
@@ -190,6 +201,66 @@ int MyMtpDatabase::getNumObjects(MtpStorageID storageID,
                (jint)storageID, (jint)format, (jint)parent);
}

MtpObjectFormatList* MyMtpDatabase::getSupportedPlaybackFormats() {
    JNIEnv* env = AndroidRuntime::getJNIEnv();
    jintArray array = (jintArray)env->CallObjectMethod(mDatabase,
            method_getSupportedPlaybackFormats);
    if (!array)
        return NULL;
    MtpObjectFormatList* list = new MtpObjectFormatList();
    jint* formats = env->GetIntArrayElements(array, 0);
    jsize length = env->GetArrayLength(array);
    for (int i = 0; i < length; i++)
        list->push(formats[i]);
   env->ReleaseIntArrayElements(array, formats, 0);
   return list;
}

MtpObjectFormatList* MyMtpDatabase::getSupportedCaptureFormats() {
    JNIEnv* env = AndroidRuntime::getJNIEnv();
    jintArray array = (jintArray)env->CallObjectMethod(mDatabase,
            method_getSupportedCaptureFormats);
    if (!array)
        return NULL;
    MtpObjectFormatList* list = new MtpObjectFormatList();
    jint* formats = env->GetIntArrayElements(array, 0);
    jsize length = env->GetArrayLength(array);
    for (int i = 0; i < length; i++)
        list->push(formats[i]);
   env->ReleaseIntArrayElements(array, formats, 0);
   return list;
}

MtpObjectPropertyList* MyMtpDatabase::getSupportedObjectProperties(MtpObjectFormat format) {
    JNIEnv* env = AndroidRuntime::getJNIEnv();
    jintArray array = (jintArray)env->CallObjectMethod(mDatabase,
            method_getSupportedObjectProperties, (jint)format);
    if (!array)
        return NULL;
    MtpObjectPropertyList* list = new MtpObjectPropertyList();
    jint* properties = env->GetIntArrayElements(array, 0);
    jsize length = env->GetArrayLength(array);
    for (int i = 0; i < length; i++)
        list->push(properties[i]);
   env->ReleaseIntArrayElements(array, properties, 0);
   return list;
}

MtpDevicePropertyList* MyMtpDatabase::getSupportedDeviceProperties() {
    JNIEnv* env = AndroidRuntime::getJNIEnv();
    jintArray array = (jintArray)env->CallObjectMethod(mDatabase,
            method_getSupportedDeviceProperties);
    if (!array)
        return NULL;
    MtpDevicePropertyList* list = new MtpDevicePropertyList();
    jint* properties = env->GetIntArrayElements(array, 0);
    jsize length = env->GetArrayLength(array);
    for (int i = 0; i < length; i++)
        list->push(properties[i]);
   env->ReleaseIntArrayElements(array, properties, 0);
   return list;
}

MtpResponseCode MyMtpDatabase::getObjectProperty(MtpObjectHandle handle,
                                            MtpObjectProperty property,
                                            MtpDataPacket& packet) {
@@ -460,6 +531,26 @@ int register_android_media_MtpDatabase(JNIEnv *env)
        LOGE("Can't find getNumObjects");
        return -1;
    }
    method_getSupportedPlaybackFormats = env->GetMethodID(clazz, "getSupportedPlaybackFormats", "()[I");
    if (method_getSupportedPlaybackFormats == NULL) {
        LOGE("Can't find getSupportedPlaybackFormats");
        return -1;
    }
    method_getSupportedCaptureFormats = env->GetMethodID(clazz, "getSupportedCaptureFormats", "()[I");
    if (method_getSupportedCaptureFormats == NULL) {
        LOGE("Can't find getSupportedCaptureFormats");
        return -1;
    }
    method_getSupportedObjectProperties = env->GetMethodID(clazz, "getSupportedObjectProperties", "(I)[I");
    if (method_getSupportedObjectProperties == NULL) {
        LOGE("Can't find getSupportedObjectProperties");
        return -1;
    }
    method_getSupportedDeviceProperties = env->GetMethodID(clazz, "getSupportedDeviceProperties", "()[I");
    if (method_getSupportedDeviceProperties == NULL) {
        LOGE("Can't find getSupportedDeviceProperties");
        return -1;
    }
    method_getObjectProperty = env->GetMethodID(clazz, "getObjectProperty", "(II[J[C)I");
    if (method_getObjectProperty == NULL) {
        LOGE("Can't find getObjectProperty");
+7 −0
Original line number Diff line number Diff line
@@ -266,6 +266,13 @@ void MtpDataPacket::putAUInt16(const uint16_t* values, int count) {
        putUInt16(*values++);
}

void MtpDataPacket::putAUInt16(const UInt16List* values) {
    size_t count = (values ? values->size() : 0);
    putUInt32(count);
    for (size_t i = 0; i < count; i++)
        putUInt16((*values)[i]);
}

void MtpDataPacket::putAInt32(const int32_t* values, int count) {
    putUInt32(count);
    for (int i = 0; i < count; i++)
+1 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ public:
    void                putAUInt8(const uint8_t* values, int count);
    void                putAInt16(const int16_t* values, int count);
    void                putAUInt16(const uint16_t* values, int count);
    void                putAUInt16(const UInt16List* values);
    void                putAInt32(const int32_t* values, int count);
    void                putAUInt32(const uint32_t* values, int count);
    void                putAUInt32(const UInt32List* list);
Loading