From 059c446fbffd88802b051b846ce09e6a403c99aa Mon Sep 17 00:00:00 2001 From: Andreas Huber <> Date: Fri, 27 Mar 2009 15:36:43 -0700 Subject: [PATCH] AI 143244: am: CL 142801 am: CL 142799 Ensure thread exit resets mThread to null (synchronized with sListeners) If sensors_data_poll failed the sensor thread would exit leaving mThread non-null, hence SensorManager would never again attempt to start the thread because it assumes that it's still running, compromising future sensor notifications. Original author: andih Merged from: //branches/cupcake/... Original author: android-build Merged from: //branches/donutburger/... Automated import of CL 143244 --- core/java/android/hardware/SensorManager.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/core/java/android/hardware/SensorManager.java b/core/java/android/hardware/SensorManager.java index e232c2cee0435..7fbb3a7580572 100644 --- a/core/java/android/hardware/SensorManager.java +++ b/core/java/android/hardware/SensorManager.java @@ -304,6 +304,9 @@ public class SensorManager extends IRotationWatcher.Stub if (mSensorDataFd == null) { Log.e(TAG, "mSensorDataFd == NULL, exiting"); + synchronized (sListeners) { + mThread = null; + } return; } // this thread is guaranteed to be unique @@ -321,17 +324,16 @@ public class SensorManager extends IRotationWatcher.Stub // wait for an event final int sensor = sensors_data_poll(values, status, timestamp); - if (sensor == -1) { - // we lost the connection to the event stream. this happens - // when the last listener is removed. - Log.d(TAG, "_sensors_data_poll() failed, we bail out."); - break; - } - int accuracy = status[0]; synchronized (sListeners) { - if (sListeners.isEmpty()) { - // we have no more listeners, terminate the thread + if (sensor == -1 || sListeners.isEmpty()) { + if (sensor == -1) { + // we lost the connection to the event stream. this happens + // when the last listener is removed. + Log.d(TAG, "_sensors_data_poll() failed, we bail out."); + } + + // we have no more listeners or polling failed, terminate the thread sensors_data_close(); mThread = null; break;