Bug 802029 - When PollSensors() found one of its event type is SENSOR_UNKNOWN, don't create a SensorRunnable. r=mwu, a=blocking-basecamp
authorAlan Huang <ahuang@mozilla.com>
Wed, 31 Oct 2012 15:03:19 +0800
changeset 116698 4a62e0864b5d9443cd97dd8226793ef8183e8688
parent 116697 8e94d84fd6e39e03dc5ae0ee99a20ac8a8720da6
child 116699 0588345cd9aa982a1a9479bcf2d740d4e7594388
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmwu, blocking-basecamp
bugs802029
milestone18.0a2
Bug 802029 - When PollSensors() found one of its event type is SENSOR_UNKNOWN, don't create a SensorRunnable. r=mwu, a=blocking-basecamp
hal/gonk/GonkSensor.cpp
--- a/hal/gonk/GonkSensor.cpp
+++ b/hal/gonk/GonkSensor.cpp
@@ -27,16 +27,17 @@
 
 #undef LOG
 
 #include <android/log.h>
 
 using namespace mozilla::hal;
 
 #define LOGE(args...)  __android_log_print(ANDROID_LOG_ERROR, "GonkSensor" , ## args)
+#define LOGW(args...)  __android_log_print(ANDROID_LOG_WARN, "GonkSensor" , ## args)
 
 namespace mozilla {
 
 // The value from SensorDevice.h (Android)
 #define DEFAULT_DEVICE_POLL_RATE 200000000 /*200ms*/
 
 double radToDeg(double a) {
   return a * (180.0 / M_PI);
@@ -107,21 +108,16 @@ SensorseventStatus(const sensors_event_t
 }
 
 class SensorRunnable : public nsRunnable
 {
 public:
   SensorRunnable(const sensors_event_t& data, const sensor_t* sensors, ssize_t size)
   {
     mSensorData.sensor() = HardwareSensorToHalSensor(data.type);
-    if (mSensorData.sensor() == SENSOR_UNKNOWN) {
-      // Emulator is broken and gives us events without types set
-      if (data.sensor < size)
-        mSensorData.sensor() = HardwareSensorToHalSensor(sensors[data.sensor].type);
-    }
     mSensorData.accuracy() = HardwareStatusToHalAccuracy(SensorseventStatus(data));
     mSensorData.timestamp() = data.timestamp;
     if (mSensorData.sensor() == SENSOR_GYROSCOPE) {
       // libhardware returns gyro as rad.  convert.
       mSensorValues.AppendElement(radToDeg(data.data[0]));
       mSensorValues.AppendElement(radToDeg(data.data[1]));
       mSensorValues.AppendElement(radToDeg(data.data[2]));
     } else if (mSensorData.sensor() == SENSOR_PROXIMITY) {
@@ -180,16 +176,30 @@ PollSensors()
       break;
     }
 
     for (int i = 0; i < n; ++i) {
       // FIXME: bug 802004, add proper support for the magnetic field sensor.
       if (buffer[i].type == SENSOR_TYPE_MAGNETIC_FIELD)
         continue;
 
+      if (buffer[i].sensor >= size) {
+        LOGW("buffer type is hal sensor type SENSOR_UNKNOWN, and buffer sensor is not in a valid range");
+        continue;
+      }
+
+      if (HardwareSensorToHalSensor(buffer[i].type) == SENSOR_UNKNOWN) {
+        // Emulator is broken and gives us events without types set
+        if (HardwareSensorToHalSensor(sensors[buffer[i].sensor].type) != SENSOR_UNKNOWN) {
+          buffer[i].type = sensors[buffer[i].sensor].type;
+        } else {
+          continue;
+        }
+      }
+
       NS_DispatchToMainThread(new SensorRunnable(buffer[i], sensors, size));
     }
   } while (true);
 }
 
 static void
 SwitchSensor(bool aActivate, sensor_t aSensor, pthread_t aThreadId)
 {