CameraITS: start enforcing sensor fusion test

Bug: 29120073
Change-Id: I88395be3368318bfa20a40a9ed646b94cc355f21
diff --git a/apps/CameraITS/pymodules/its/device.py b/apps/CameraITS/pymodules/its/device.py
index b465211..54bd0ad 100644
--- a/apps/CameraITS/pymodules/its/device.py
+++ b/apps/CameraITS/pymodules/its/device.py
@@ -331,9 +331,12 @@
         cmd = {}
         cmd["cmdName"] = "getSensorEvents"
         self.sock.send(json.dumps(cmd) + "\n")
+        timeout = self.SOCK_TIMEOUT + self.EXTRA_SOCK_TIMEOUT
+        self.sock.settimeout(timeout)
         data,_ = self.__read_response_from_socket()
         if data['tag'] != 'sensorEvents':
             raise its.error.Error('Invalid command response')
+        self.sock.settimeout(self.SOCK_TIMEOUT)
         return data['objValue']
 
     def get_camera_ids(self):
diff --git a/apps/CameraITS/tests/sensor_fusion/test_sensor_fusion.py b/apps/CameraITS/tests/sensor_fusion/test_sensor_fusion.py
index e6fe4c2..2f358d0 100644
--- a/apps/CameraITS/tests/sensor_fusion/test_sensor_fusion.py
+++ b/apps/CameraITS/tests/sensor_fusion/test_sensor_fusion.py
@@ -15,6 +15,7 @@
 import its.image
 import its.device
 import its.objects
+import its.caps
 import time
 import math
 import pylab
@@ -323,11 +324,15 @@
         frames: List of RGB images as numpy arrays.
     """
     with its.device.ItsSession() as cam:
+        props = cam.get_camera_properties()
+        its.caps.skip_unless(its.caps.sensor_fusion(props) and
+                             its.caps.manual_sensor(props))
+
         print "Starting sensor event collection"
         cam.start_sensor_events()
 
         # Sleep a few seconds for gyro events to stabilize.
-        time.sleep(5)
+        time.sleep(2)
 
         # TODO: Ensure that OIS is disabled; set to DISABLE and wait some time.
 
diff --git a/apps/CameraITS/tools/run_all_tests.py b/apps/CameraITS/tools/run_all_tests.py
index 7239c9a..52780eb 100644
--- a/apps/CameraITS/tools/run_all_tests.py
+++ b/apps/CameraITS/tools/run_all_tests.py
@@ -45,12 +45,15 @@
         "scene2":[],
         "scene3":[],
         "scene4":[],
-        "scene5":[]
+        "scene5":[],
+        "sensor_fusion":[]
     }
 
     # Get all the scene0 and scene1 tests, which can be run using the same
     # physical setup.
-    scenes = ["scene0", "scene1", "scene2", "scene3", "scene4", "scene5"]
+    scenes = ["scene0", "scene1", "scene2", "scene3", "scene4", "scene5",
+              "sensor_fusion"]
+
     scene_req = {
         "scene0" : None,
         "scene1" : "A grey card covering at least the middle 30% of the scene",
@@ -60,7 +63,14 @@
                    "middle 50% of the scene. See CameraITS.pdf section 2.3.4 "
                    "for more details",
         "scene5" : "Capture images with a diffuser attached to the camera. See "
-                   "CameraITS.pdf section 2.3.4 for more details"
+                   "CameraITS.pdf section 2.3.4 for more details",
+        "sensor_fusion" : "Rotating checkboard pattern. See "
+                          "sensor_fusion/SensorFusion.pdf for detailed "
+                          "instructions. Note that this test will be skipped "
+                          "on devices not supporting REALTIME camera timestamp."
+                          "If that is the case, no scene setup is required and "
+                          "you can just answer Y when being asked if the scene "
+                          "is okay"
     }
     scene_extra_args = {
         "scene5" : ["doAF=False"]
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/camera/its/ItsService.java b/apps/CtsVerifier/src/com/android/cts/verifier/camera/its/ItsService.java
index d528604..747302a 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/camera/its/ItsService.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/camera/its/ItsService.java
@@ -564,6 +564,7 @@
             // Each command is a serialized JSON object.
             try {
                 JSONObject cmdObj = new JSONObject(cmd);
+                Logt.i(TAG, "Start processing command" + cmdObj.getString("cmdName"));
                 if ("open".equals(cmdObj.getString("cmdName"))) {
                     int cameraId = cmdObj.getInt("cameraId");
                     openCameraDevice(cameraId);
@@ -588,6 +589,7 @@
                 } else {
                     throw new ItsException("Unknown command: " + cmd);
                 }
+                Logt.i(TAG, "Finish processing command" + cmdObj.getString("cmdName"));
             } catch (org.json.JSONException e) {
                 Logt.e(TAG, "Invalid command: ", e);
             }
@@ -642,6 +644,7 @@
 
         public void sendResponse(LinkedList<MySensorEvent> events)
                 throws ItsException {
+            Logt.i(TAG, "Sending " + events.size() + " sensor events");
             try {
                 JSONArray accels = new JSONArray();
                 JSONArray mags = new JSONArray();
@@ -668,6 +671,7 @@
             } catch (org.json.JSONException e) {
                 throw new ItsException("JSON error: ", e);
             }
+            Logt.i(TAG, "Sent sensor events");
         }
 
         public void sendResponse(CameraCharacteristics props)