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

Commit 148954a6 authored by Daichi Hirono's avatar Daichi Hirono
Browse files

Add eventsSupported property to MtpDeviceInfo.

The property provides the set of event code that are supported by
MtpDevice.

BUG=26147375

Change-Id: I54be75e4bb52ddfe9aba8630538ddd32d1a641c8
parent 69c8cc29
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -22632,6 +22632,7 @@ package android.mtp {
  }
  public class MtpDeviceInfo {
    method public final int[] getEventsSupported();
    method public final java.lang.String getManufacturer();
    method public final java.lang.String getModel();
    method public final int[] getOperationsSupported();
+1 −0
Original line number Diff line number Diff line
@@ -24190,6 +24190,7 @@ package android.mtp {
  }
  public class MtpDeviceInfo {
    method public final int[] getEventsSupported();
    method public final java.lang.String getManufacturer();
    method public final java.lang.String getModel();
    method public final int[] getOperationsSupported();
+1 −0
Original line number Diff line number Diff line
@@ -22640,6 +22640,7 @@ package android.mtp {
  }
  public class MtpDeviceInfo {
    method public final int[] getEventsSupported();
    method public final java.lang.String getManufacturer();
    method public final java.lang.String getModel();
    method public final int[] getOperationsSupported();
+64 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ public class MtpDeviceInfo {
    private String mVersion;
    private String mSerialNumber;
    private int[] mOperationsSupported;
    private int[] mEventsSupported;

    // only instantiated via JNI
    private MtpDeviceInfo() {
@@ -74,9 +75,71 @@ public class MtpDeviceInfo {
    /**
     * Returns operation code supported by the device.
     *
     * @return supported operation code
     * @return supported operation code. Can be null if device does not provide the property.
     * @see MtpConstants#OPERATION_GET_DEVICE_INFO
     * @see MtpConstants#OPERATION_OPEN_SESSION
     * @see MtpConstants#OPERATION_CLOSE_SESSION
     * @see MtpConstants#OPERATION_GET_STORAGE_I_DS
     * @see MtpConstants#OPERATION_GET_STORAGE_INFO
     * @see MtpConstants#OPERATION_GET_NUM_OBJECTS
     * @see MtpConstants#OPERATION_GET_OBJECT_HANDLES
     * @see MtpConstants#OPERATION_GET_OBJECT_INFO
     * @see MtpConstants#OPERATION_GET_OBJECT
     * @see MtpConstants#OPERATION_GET_THUMB
     * @see MtpConstants#OPERATION_DELETE_OBJECT
     * @see MtpConstants#OPERATION_SEND_OBJECT_INFO
     * @see MtpConstants#OPERATION_SEND_OBJECT
     * @see MtpConstants#OPERATION_INITIATE_CAPTURE
     * @see MtpConstants#OPERATION_FORMAT_STORE
     * @see MtpConstants#OPERATION_RESET_DEVICE
     * @see MtpConstants#OPERATION_SELF_TEST
     * @see MtpConstants#OPERATION_SET_OBJECT_PROTECTION
     * @see MtpConstants#OPERATION_POWER_DOWN
     * @see MtpConstants#OPERATION_GET_DEVICE_PROP_DESC
     * @see MtpConstants#OPERATION_GET_DEVICE_PROP_VALUE
     * @see MtpConstants#OPERATION_SET_DEVICE_PROP_VALUE
     * @see MtpConstants#OPERATION_RESET_DEVICE_PROP_VALUE
     * @see MtpConstants#OPERATION_TERMINATE_OPEN_CAPTURE
     * @see MtpConstants#OPERATION_MOVE_OBJECT
     * @see MtpConstants#OPERATION_COPY_OBJECT
     * @see MtpConstants#OPERATION_GET_PARTIAL_OBJECT
     * @see MtpConstants#OPERATION_INITIATE_OPEN_CAPTURE
     * @see MtpConstants#OPERATION_GET_OBJECT_PROPS_SUPPORTED
     * @see MtpConstants#OPERATION_GET_OBJECT_PROP_DESC
     * @see MtpConstants#OPERATION_GET_OBJECT_PROP_VALUE
     * @see MtpConstants#OPERATION_SET_OBJECT_PROP_VALUE
     * @see MtpConstants#OPERATION_GET_OBJECT_REFERENCES
     * @see MtpConstants#OPERATION_SET_OBJECT_REFERENCES
     * @see MtpConstants#OPERATION_SKIP
     */
    public final @Nullable int[] getOperationsSupported() {
        return mOperationsSupported;
    }

    /**
     * Returns event code supported by the device.
     *
     * @return supported event code. Can be null if device does not provide the property.
     * @see MtpConstants#EVENT_UNDEFINED
     * @see MtpConstants#EVENT_CANCEL_TRANSACTION
     * @see MtpConstants#EVENT_OBJECT_ADDED
     * @see MtpConstants#EVENT_OBJECT_REMOVED
     * @see MtpConstants#EVENT_STORE_ADDED
     * @see MtpConstants#EVENT_STORE_REMOVED
     * @see MtpConstants#EVENT_DEVICE_PROP_CHANGED
     * @see MtpConstants#EVENT_OBJECT_INFO_CHANGED
     * @see MtpConstants#EVENT_DEVICE_INFO_CHANGED
     * @see MtpConstants#EVENT_REQUEST_OBJECT_TRANSFER
     * @see MtpConstants#EVENT_STORE_FULL
     * @see MtpConstants#EVENT_DEVICE_RESET
     * @see MtpConstants#EVENT_STORAGE_INFO_CHANGED
     * @see MtpConstants#EVENT_CAPTURE_COMPLETE
     * @see MtpConstants#EVENT_UNREPORTED_STATUS
     * @see MtpConstants#EVENT_OBJECT_PROP_CHANGED
     * @see MtpConstants#EVENT_OBJECT_PROP_DESC_CHANGED
     * @see MtpConstants#EVENT_OBJECT_REFERENCES_CHANGED
     */
    public final @Nullable int[] getEventsSupported() {
        return mEventsSupported;
    }
}
+31 −6
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@
#include <unistd.h>
#include <fcntl.h>

#include <memory>

#include "jni.h"
#include "JNIHelp.h"
#include "ScopedPrimitiveArray.h"
@@ -66,6 +68,7 @@ static jfieldID field_deviceInfo_model;
static jfieldID field_deviceInfo_version;
static jfieldID field_deviceInfo_serialNumber;
static jfieldID field_deviceInfo_operationsSupported;
static jfieldID field_deviceInfo_eventsSupported;

// MtpStorageInfo fields
static jfieldID field_storageInfo_storageId;
@@ -216,7 +219,7 @@ android_mtp_MtpDevice_get_device_info(JNIEnv *env, jobject thiz)
        ALOGD("android_mtp_MtpDevice_get_device_info device is null");
        return NULL;
    }
    MtpDeviceInfo* deviceInfo = device->getDeviceInfo();
    std::unique_ptr<MtpDeviceInfo> deviceInfo(device->getDeviceInfo());
    if (!deviceInfo) {
        ALOGD("android_mtp_MtpDevice_get_device_info deviceInfo is null");
        return NULL;
@@ -224,7 +227,6 @@ android_mtp_MtpDevice_get_device_info(JNIEnv *env, jobject thiz)
    jobject info = env->NewObject(clazz_deviceInfo, constructor_deviceInfo);
    if (info == NULL) {
        ALOGE("Could not create a MtpDeviceInfo object");
        delete deviceInfo;
        return NULL;
    }

@@ -242,17 +244,35 @@ android_mtp_MtpDevice_get_device_info(JNIEnv *env, jobject thiz)
            env->NewStringUTF(deviceInfo->mSerial));
    if (deviceInfo->mOperations) {
        const size_t size = deviceInfo->mOperations->size();
        const jintArray operations = env->NewIntArray(size);
        ScopedLocalRef<jintArray> operations(env, static_cast<jintArray>(env->NewIntArray(size)));
        {
            ScopedIntArrayRW elements(env, operations);
            ScopedIntArrayRW elements(env, operations.get());
            if (elements.get() == NULL) {
                ALOGE("Could not create operationsSupported element.");
                return NULL;
            }
            for (size_t i = 0; i < size; ++i) {
                elements[i] = deviceInfo->mOperations->itemAt(i);
            }
            env->SetObjectField(info, field_deviceInfo_operationsSupported, operations.get());
        }
    }
    if (deviceInfo->mEvents) {
        const size_t size = deviceInfo->mEvents->size();
        ScopedLocalRef<jintArray> events(env, static_cast<jintArray>(env->NewIntArray(size)));
        {
            ScopedIntArrayRW elements(env, events.get());
            if (elements.get() == NULL) {
                ALOGE("Could not create eventsSupported element.");
                return NULL;
            }
            for (size_t i = 0; i < size; ++i) {
                elements[i] = deviceInfo->mEvents->itemAt(i);
            }
            env->SetObjectField(info, field_deviceInfo_eventsSupported, events.get());
        }
        env->SetObjectField(info, field_deviceInfo_operationsSupported, operations);
    }

    delete deviceInfo;
    return info;
}

@@ -686,6 +706,11 @@ int register_android_mtp_MtpDevice(JNIEnv *env)
        ALOGE("Can't find MtpDeviceInfo.mOperationsSupported");
        return -1;
    }
    field_deviceInfo_eventsSupported = env->GetFieldID(clazz, "mEventsSupported", "[I");
    if (field_deviceInfo_eventsSupported == NULL) {
        ALOGE("Can't find MtpDeviceInfo.mEventsSupported");
        return -1;
    }
    clazz_deviceInfo = (jclass)env->NewGlobalRef(clazz);

    clazz = env->FindClass("android/mtp/MtpStorageInfo");
Loading