MTP: Only send events to host if we have an open session.
Change-Id: I7b2d0c88c2d2ae0490247703d0fb1b862154db92
Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/media/mtp/MtpServer.cpp b/media/mtp/MtpServer.cpp
index 163c05b..adfe3a9 100644
--- a/media/mtp/MtpServer.cpp
+++ b/media/mtp/MtpServer.cpp
@@ -245,21 +245,25 @@
}
void MtpServer::sendObjectAdded(MtpObjectHandle handle) {
- LOGD("sendObjectAdded %d\n", handle);
- mEvent.setEventCode(MTP_EVENT_OBJECT_ADDED);
- mEvent.setTransactionID(mRequest.getTransactionID());
- mEvent.setParameter(1, handle);
- int ret = mEvent.write(mFD);
- LOGD("mEvent.write returned %d\n", ret);
+ if (mSessionOpen) {
+ LOGD("sendObjectAdded %d\n", handle);
+ mEvent.setEventCode(MTP_EVENT_OBJECT_ADDED);
+ mEvent.setTransactionID(mRequest.getTransactionID());
+ mEvent.setParameter(1, handle);
+ int ret = mEvent.write(mFD);
+ LOGD("mEvent.write returned %d\n", ret);
+ }
}
void MtpServer::sendObjectRemoved(MtpObjectHandle handle) {
- LOGD("sendObjectRemoved %d\n", handle);
- mEvent.setEventCode(MTP_EVENT_OBJECT_REMOVED);
- mEvent.setTransactionID(mRequest.getTransactionID());
- mEvent.setParameter(1, handle);
- int ret = mEvent.write(mFD);
- LOGD("mEvent.write returned %d\n", ret);
+ if (mSessionOpen) {
+ LOGD("sendObjectRemoved %d\n", handle);
+ mEvent.setEventCode(MTP_EVENT_OBJECT_REMOVED);
+ mEvent.setTransactionID(mRequest.getTransactionID());
+ mEvent.setParameter(1, handle);
+ int ret = mEvent.write(mFD);
+ LOGD("mEvent.write returned %d\n", ret);
+ }
}
void MtpServer::initObjectProperties() {