Bug 802029 - When PollSensors() found one of its event type is SENSOR_UNKNOWN, don't create a SensorRunnable. r=mwu
authorAlan Huang <ahuang@mozilla.com>
Wed, 31 Oct 2012 15:03:19 +0800
changeset 112292 e8f94aee02aa390f50a287acfd182a5eb34f3bf9
parent 112291 cecff590fcd642d57ecc77018457373bf2dd027b
child 112293 18da095f136a610fb23198c35304fdbb68023faf
push id23809
push useremorley@mozilla.com
push dateMon, 05 Nov 2012 15:24:12 +0000
treeherdermozilla-central@358c9830d166 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmwu
bugs802029
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 802029 - When PollSensors() found one of its event type is SENSOR_UNKNOWN, don't create a SensorRunnable. r=mwu
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)
 {