OSDN Git Service

[sensorservice] Fix inconsistent states in SensorDevice
authorPeng Xu <pengxu@google.com>
Mon, 26 Sep 2016 18:28:32 +0000 (11:28 -0700)
committerAndrew Rossignol <aarossig@google.com>
Mon, 26 Sep 2016 23:48:19 +0000 (23:48 +0000)
This CL avoids inconsistent disabled client list when sensorservice
is in restricted mode and a restricted sensor event connection is
destroyed.

The inconsistency can cause registerLister error in sensor CTS.

Also removed the additional logging message since they are no longer
necessary.

Bug: 28533594

Test: Running "cts-tradefed run singleCommand cts-dev --module
CtsHardwareTestCases --test android.hardware.cts.SensorBatchingTests"
continuously while keep registering and unregistering sensor listener
in a separate app (e.g. enable BreakIt mode in SensorLogger).

Change-Id: I601aea87c88511f5543a80c4921ee4822cb89dff

services/sensorservice/SensorDevice.cpp
services/sensorservice/SensorDevice.h
services/sensorservice/SensorService.cpp

index 4fbaa50..ac03742 100644 (file)
@@ -475,6 +475,11 @@ ssize_t SensorDevice::Info::removeBatchParamsForIdent(void* ident) {
     return idx;
 }
 
+void SensorDevice::notifyConnectionDestroyed(void* ident) {
+    Mutex::Autolock _l(mLock);
+    mDisabledClients.remove(ident);
+}
+
 // ---------------------------------------------------------------------------
 }; // namespace android
 
index 68bb853..d340da3 100644 (file)
@@ -51,6 +51,7 @@ public:
     void enableAllSensors();
     void autoDisable(void *ident, int handle);
     status_t injectSensorData(const sensors_event_t *event);
+    void notifyConnectionDestroyed(void *ident);
 
     // Dumpable
     virtual std::string dump() const;
index 2930637..99da2c4 100644 (file)
@@ -995,6 +995,9 @@ void SensorService::cleanupConnection(SensorEventConnection* c) {
     if (c->needsWakeLock()) {
         checkWakeLockStateLocked();
     }
+
+    SensorDevice& dev(SensorDevice::getInstance());
+    dev.notifyConnectionDestroyed(c);
 }
 
 sp<SensorInterface> SensorService::getSensorInterfaceFromHandle(int handle) const {