From d3849e10295d848cf3e040a446bcb6f139cfad30 Mon Sep 17 00:00:00 2001 From: Brian Stack Date: Mon, 7 Jan 2019 12:57:12 -0800 Subject: [PATCH] Stop Wake Lock thread if it is running If the Wake Lock thread is running, stop it whenever initialize() is called in order to prevent an invalid Wake Lock Queue from being read. Also disable all sensors whenever initialize() is called to ensure that stale sensor registrations are properly cleaned up. Bug: 122468928 Test: Sensors HAL 2.0 tests run without crashing Change-Id: I5fb55628545adbb481da6fcda157c78cff834134 --- sensors/2.0/default/Sensors.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sensors/2.0/default/Sensors.cpp b/sensors/2.0/default/Sensors.cpp index efc8b053b1..855e66ff19 100644 --- a/sensors/2.0/default/Sensors.cpp +++ b/sensors/2.0/default/Sensors.cpp @@ -86,6 +86,17 @@ Return Sensors::initialize( const sp& sensorsCallback) { Result result = Result::OK; + // Ensure that all sensors are disabled + for (auto sensor : mSensors) { + sensor.second->activate(false /* enable */); + } + + // Stop the Wake Lock thread if it is currently running + if (mReadWakeLockQueueRun.load()) { + mReadWakeLockQueueRun = false; + mWakeLockThread.join(); + } + // Save a reference to the callback mCallback = sensorsCallback;