diff options
author | 2016-01-11 13:33:41 +0900 | |
---|---|---|
committer | 2016-01-12 12:14:30 +0900 | |
commit | 2a9a43369b4717bcf6b372f6798f72e80e938e30 (patch) | |
tree | 5b0050d6d96ca7c9153acd304cd466b91e16a60f | |
parent | df7a1d69eab05f643bc7ec8bc43e93b441a5b7ad (diff) |
Reland "Add event parameters to MtpEvent."
The CL was previously reviewed at ag/842930.
> We can obtain detailed information of MtpEvent from devices. e.g. object
> handle of changed object. The CL adds the detailed information as
> properties of MtpEvent class.
>
> BUG=26480986
Change-Id: I93afad9caf118d74cd0923d70242133c4fb2a648
-rw-r--r-- | api/current.txt | 9 | ||||
-rw-r--r-- | api/system-current.txt | 9 | ||||
-rw-r--r-- | api/test-current.txt | 9 | ||||
-rw-r--r-- | media/java/android/mtp/MtpEvent.java | 139 | ||||
-rw-r--r-- | media/jni/android_mtp_MtpDevice.cpp | 24 | ||||
-rw-r--r-- | packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpManagerTest.java | 15 |
6 files changed, 203 insertions, 2 deletions
diff --git a/api/current.txt b/api/current.txt index 6c4904166ea6..baedbeb8002b 100644 --- a/api/current.txt +++ b/api/current.txt @@ -22538,7 +22538,16 @@ package android.mtp { public class MtpEvent { ctor public MtpEvent(); + method public int getDevicePropCode(); method public int getEventCode(); + method public int getObjectFormatCode(); + method public int getObjectHandle(); + method public int getObjectPropCode(); + method public int getParameter1(); + method public int getParameter2(); + method public int getParameter3(); + method public int getStorageId(); + method public int getTransactionId(); } public final class MtpObjectInfo { diff --git a/api/system-current.txt b/api/system-current.txt index 3ede80ac0d05..4c3efabbae53 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -24084,7 +24084,16 @@ package android.mtp { public class MtpEvent { ctor public MtpEvent(); + method public int getDevicePropCode(); method public int getEventCode(); + method public int getObjectFormatCode(); + method public int getObjectHandle(); + method public int getObjectPropCode(); + method public int getParameter1(); + method public int getParameter2(); + method public int getParameter3(); + method public int getStorageId(); + method public int getTransactionId(); } public final class MtpObjectInfo { diff --git a/api/test-current.txt b/api/test-current.txt index 306cf7362204..daecc2bce215 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -22546,7 +22546,16 @@ package android.mtp { public class MtpEvent { ctor public MtpEvent(); + method public int getDevicePropCode(); method public int getEventCode(); + method public int getObjectFormatCode(); + method public int getObjectHandle(); + method public int getObjectPropCode(); + method public int getParameter1(); + method public int getParameter2(); + method public int getParameter3(); + method public int getStorageId(); + method public int getTransactionId(); } public final class MtpObjectInfo { diff --git a/media/java/android/mtp/MtpEvent.java b/media/java/android/mtp/MtpEvent.java index 6ec16dba42ac..dc89a56cf0b3 100644 --- a/media/java/android/mtp/MtpEvent.java +++ b/media/java/android/mtp/MtpEvent.java @@ -18,15 +18,152 @@ package android.mtp; /** * This class encapsulates information about a MTP event. - * Event constants are defined by the USB-IF MTP specification. + * This corresponds to the events described in appendix G of the MTP specification. */ public class MtpEvent { private int mEventCode = MtpConstants.EVENT_UNDEFINED; + // Parameters for event. The interpretation of event parameters depends upon mEventCode. + private int mParameter1; + private int mParameter2; + private int mParameter3; + /** * Returns event code of MTP event. * See the USB-IF MTP specification for the details of event constants. * @return event code */ public int getEventCode() { return mEventCode; } + + /** + * Obtains the first event parameter. + */ + public int getParameter1() { return mParameter1; } + + /** + * Obtains the second event parameter. + */ + public int getParameter2() { return mParameter2; } + + /** + * Obtains the third event parameter. + */ + public int getParameter3() { return mParameter3; } + + /** + * Obtains objectHandle event parameter. + * + * @see MtpConstants#EVENT_OBJECT_ADDED + * @see MtpConstants#EVENT_OBJECT_REMOVED + * @see MtpConstants#EVENT_OBJECT_INFO_CHANGED + * @see MtpConstants#EVENT_REQUEST_OBJECT_TRANSFER + * @see MtpConstants#EVENT_OBJECT_PROP_CHANGED + * @see MtpConstants#EVENT_OBJECT_REFERENCES_CHANGED + */ + public int getObjectHandle() { + switch (mEventCode) { + case MtpConstants.EVENT_OBJECT_ADDED: + return mParameter1; + case MtpConstants.EVENT_OBJECT_REMOVED: + return mParameter1; + case MtpConstants.EVENT_OBJECT_INFO_CHANGED: + return mParameter1; + case MtpConstants.EVENT_REQUEST_OBJECT_TRANSFER: + return mParameter1; + case MtpConstants.EVENT_OBJECT_PROP_CHANGED: + return mParameter1; + case MtpConstants.EVENT_OBJECT_REFERENCES_CHANGED: + return mParameter1; + default: + throw new IllegalParameterAccess("objectHandle", mEventCode); + } + } + + /** + * Obtains storageID event parameter. + * + * @see MtpConstants#EVENT_STORE_ADDED + * @see MtpConstants#EVENT_STORE_REMOVED + * @see MtpConstants#EVENT_STORE_FULL + * @see MtpConstants#EVENT_STORAGE_INFO_CHANGED + */ + public int getStorageId() { + switch (mEventCode) { + case MtpConstants.EVENT_STORE_ADDED: + return mParameter1; + case MtpConstants.EVENT_STORE_REMOVED: + return mParameter1; + case MtpConstants.EVENT_STORE_FULL: + return mParameter1; + case MtpConstants.EVENT_STORAGE_INFO_CHANGED: + return mParameter1; + default: + throw new IllegalParameterAccess("storageID", mEventCode); + } + } + + /** + * Obtains devicePropCode event parameter. + * + * @see MtpConstants#EVENT_DEVICE_PROP_CHANGED + */ + public int getDevicePropCode() { + switch (mEventCode) { + case MtpConstants.EVENT_DEVICE_PROP_CHANGED: + return mParameter1; + default: + throw new IllegalParameterAccess("devicePropCode", mEventCode); + } + } + + /** + * Obtains transactionID event parameter. + * + * @see MtpConstants#EVENT_CAPTURE_COMPLETE + */ + public int getTransactionId() { + switch (mEventCode) { + case MtpConstants.EVENT_CAPTURE_COMPLETE: + return mParameter1; + default: + throw new IllegalParameterAccess("transactionID", mEventCode); + } + } + + /** + * Obtains objectPropCode event parameter. + * + * @see MtpConstants#EVENT_OBJECT_PROP_CHANGED + * @see MtpConstants#EVENT_OBJECT_PROP_DESC_CHANGED + */ + public int getObjectPropCode() { + switch (mEventCode) { + case MtpConstants.EVENT_OBJECT_PROP_CHANGED: + return mParameter2; + case MtpConstants.EVENT_OBJECT_PROP_DESC_CHANGED: + return mParameter1; + default: + throw new IllegalParameterAccess("objectPropCode", mEventCode); + } + } + + /** + * Obtains objectFormatCode event parameter. + * + * @see MtpConstants#EVENT_OBJECT_PROP_DESC_CHANGED + */ + public int getObjectFormatCode() { + switch (mEventCode) { + case MtpConstants.EVENT_OBJECT_PROP_DESC_CHANGED: + return mParameter2; + default: + throw new IllegalParameterAccess("objectFormatCode", mEventCode); + } + } + + private static class IllegalParameterAccess extends UnsupportedOperationException { + public IllegalParameterAccess(String propertyName, int eventCode) { + super("Cannot obtain " + propertyName + " for the event: " + eventCode + "."); + } + } } diff --git a/media/jni/android_mtp_MtpDevice.cpp b/media/jni/android_mtp_MtpDevice.cpp index 4aa12c2d6ffc..130dfe554f89 100644 --- a/media/jni/android_mtp_MtpDevice.cpp +++ b/media/jni/android_mtp_MtpDevice.cpp @@ -98,6 +98,9 @@ static jfieldID field_objectInfo_keywords; // MtpEvent fields static jfieldID field_event_eventCode; +static jfieldID field_event_parameter1; +static jfieldID field_event_parameter2; +static jfieldID field_event_parameter3; class JavaArrayWriter { public: @@ -573,13 +576,17 @@ static jobject android_mtp_MtpDevice_reap_event_request(JNIEnv *env, jobject thi env->ThrowNew(clazz_io_exception, ""); return NULL; } - const int eventCode = device->reapEventRequest(seq); + uint32_t parameters[3]; + const int eventCode = device->reapEventRequest(seq, ¶meters); if (eventCode <= 0) { env->ThrowNew(clazz_operation_canceled_exception, ""); return NULL; } jobject result = env->NewObject(clazz_event, constructor_event); env->SetIntField(result, field_event_eventCode, eventCode); + env->SetIntField(result, field_event_parameter1, static_cast<jint>(parameters[0])); + env->SetIntField(result, field_event_parameter2, static_cast<jint>(parameters[1])); + env->SetIntField(result, field_event_parameter3, static_cast<jint>(parameters[2])); return result; } @@ -832,6 +839,21 @@ int register_android_mtp_MtpDevice(JNIEnv *env) ALOGE("Can't find MtpObjectInfo.mEventCode"); return -1; } + field_event_parameter1 = env->GetFieldID(clazz, "mParameter1", "I"); + if (field_event_parameter1 == NULL) { + ALOGE("Can't find MtpObjectInfo.mParameter1"); + return -1; + } + field_event_parameter2 = env->GetFieldID(clazz, "mParameter2", "I"); + if (field_event_parameter2 == NULL) { + ALOGE("Can't find MtpObjectInfo.mParameter2"); + return -1; + } + field_event_parameter3 = env->GetFieldID(clazz, "mParameter3", "I"); + if (field_event_parameter3 == NULL) { + ALOGE("Can't find MtpObjectInfo.mParameter3"); + return -1; + } clazz_event = (jclass)env->NewGlobalRef(clazz); clazz = env->FindClass("android/mtp/MtpDevice"); diff --git a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpManagerTest.java b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpManagerTest.java index 49b48c5bb66d..dfde27c7c889 100644 --- a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpManagerTest.java +++ b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpManagerTest.java @@ -19,6 +19,8 @@ package com.android.mtp; import android.content.Context; import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbManager; +import android.mtp.MtpConstants; +import android.mtp.MtpEvent; import android.os.CancellationSignal; import android.os.OperationCanceledException; import android.os.SystemClock; @@ -85,6 +87,19 @@ public class MtpManagerTest extends InstrumentationTestCase { getInstrumentation().show(Arrays.toString(records[0].operationsSupported)); } + public void testEventObjectAdded() throws Exception { + while (true) { + getInstrumentation().show("Please take a photo by using connected MTP device."); + final CancellationSignal signal = new CancellationSignal(); + MtpEvent event = mManager.readEvent(mUsbDevice.getDeviceId(), signal); + if (event.getEventCode() != MtpConstants.EVENT_OBJECT_ADDED) { + continue; + } + assertTrue(event.getObjectHandle() != 0); + break; + } + } + private Context getContext() { return getInstrumentation().getContext(); } |