Fix issue with upgrade running when not needed

If a touch event was generated while the application was running
it could be interpreted as a result of a I/O command. If that
happened when reading current firmware version, a new upgrade
would be triggered even if it was running the latest version.
This made the touch unresponsive for up to a minute.

Fix the issue by only accepting io responses with HID report
id 10.

BUG=b:65224683
TEST=Ran using udev-rule and manually with --recovery both with
touching and without touching the display.
Change-Id: I6eb1a2286944fd85d1f1763c7d2e716a1f204cae
Reviewed-on: https://chromium-review.googlesource.com/645811
Commit-Ready: Stefan Adolfsson <sadolfsson@chromium.org>
Tested-by: Zhongze Hu <frankhu@google.com>
Reviewed-by: Zhongze Hu <frankhu@google.com>
diff --git a/src/SiSTouchIO.h b/src/SiSTouchIO.h
index d63c6f9..1c61690 100644
--- a/src/SiSTouchIO.h
+++ b/src/SiSTouchIO.h
@@ -587,7 +587,7 @@
   int simple_io(int cmd, int sleepms = 0);
   int io_command(unsigned char *buf, int size, int sleepms = 0);
   int sis_usb_write(void *data, unsigned int size, int timeout);
-  int sis_usb_read(void *data, unsigned int size, int timeout);
+  int sis_usb_read(void *data, unsigned int size, int timeout, int report_id);
 
   void make_common_header(int cmd, int length);
   void generate_output_crc();
@@ -725,7 +725,7 @@
  protected:
   virtual int sis_usb_start();
   virtual int sis_usb_write(void *data, unsigned int size, int timeout);
-  virtual int sis_usb_read(void *data, unsigned int size, int timeout);
+  virtual int sis_usb_read(void *data, unsigned int size, int timeout, int report_id);
   virtual int simple_io_master(int cmd, int sleepms = 0,
                                int wTimeout = DEFAULT_TIMEOUT,
                                int rTimeout = DEFAULT_TIMEOUT);
@@ -748,7 +748,7 @@
 
  private:
   virtual int sis_usb_write(void *data, unsigned int size, int timeout);
-  virtual int sis_usb_read(void *data, unsigned int size, int timeout);
+  virtual int sis_usb_read(void *data, unsigned int size, int timeout, int report_id);
   virtual int simple_io_master(int cmd, int sleepms = 0,
                                int wTimeout = DEFAULT_TIMEOUT,
                                int rTimeout = DEFAULT_TIMEOUT);
diff --git a/src/sis_fw_updater.cc b/src/sis_fw_updater.cc
index 79636eb..232a1e4 100644
--- a/src/sis_fw_updater.cc
+++ b/src/sis_fw_updater.cc
@@ -3487,7 +3487,7 @@
     usleep(sleepms * 1000);
   }
 
-  ret = sis_usb_read(m_buffer, BUFFER_SIZE, rTimeout);
+  ret = sis_usb_read(m_buffer, BUFFER_SIZE, rTimeout, INPUT_REPORT_ID);
 
   if (m_verbose) dbg_print_buffer_hex(cmd, m_buffer, ret);
 
@@ -3517,7 +3517,7 @@
     usleep(sleepms * 1000);
   }
 
-  ret = sis_usb_read(m_buffer, BUFFER_SIZE, rTimeout);
+  ret = sis_usb_read(m_buffer, BUFFER_SIZE, rTimeout, INPUT_REPORT_ID);
 
   if (m_verbose) dbg_print_buffer_hex(cmd, m_buffer, ret);
 
@@ -3548,7 +3548,7 @@
     usleep(sleepms * 1000);
   }
 
-  ret = sis_usb_read(buf, BUFFER_SIZE, rTimeout);
+  ret = sis_usb_read(buf, BUFFER_SIZE, rTimeout, INPUT_REPORT_ID);
 
   if (m_verbose) dbg_print_buffer_hex(cmd, buf, ret);
 
@@ -3672,7 +3672,7 @@
 }
 
 int SiSTouch_Aegis_Multi::sis_usb_read(void* data, unsigned int size,
-                                       int timeout) {
+                                       int timeout, int report_id) {
   int ret = 0;
   unsigned char* buf = (unsigned char*)data;
 #ifdef VIA_IOCTL
@@ -3691,7 +3691,12 @@
   databuf[get_MAX_SIZE() + 6] = timeout >> 8 & 0xff;
   databuf[get_MAX_SIZE() + 7] = timeout & 0xff;
 
-  ret = read(m_fd, databuf, 72);
+  do {
+    ret = read(m_fd, databuf, 72);
+    if (ret > 0 && (buf[0] != report_id))
+      continue;
+    break;
+  } while(1);
 
   for (unsigned int i = 0; i < get_MAX_SIZE(); i++) {
     buf[i] = databuf[i];
@@ -4627,14 +4632,19 @@
 
 int SiSTouch_Aegis_Multi_FOR_NEW_DRIVER::sis_usb_read(void* data,
                                                       unsigned int size,
-                                                      int timeout) {
+                                                      int timeout,
+                                                      int report_id) {
   int ret = 0;
   unsigned char* buf = (unsigned char*)data;
 
 #ifdef VIA_IOCTL
 
-  ret = read(m_fd, buf, size);
-
+  do {
+    ret = read(m_fd, buf, size);
+    if (ret > 0 && (buf[0] != report_id))
+      continue;
+    break;
+  } while (1);
 #else
 
   ret = ERROR_NOT_SUPPORT;
@@ -4659,7 +4669,7 @@
     usleep(sleepms * 1000);
   }
 
-  ret = sis_usb_read(m_buffer, BUFFER_SIZE, rTimeout);
+  ret = sis_usb_read(m_buffer, BUFFER_SIZE, rTimeout, INPUT_REPORT_ID);
 
   /* close m_fd for remove /dev/hidraw =======================================*/
   if (cmd == 0x82 || cmd == 0x87) {