From 65945cfb150ee6f046daa472b4ce71729ee69f1b Mon Sep 17 00:00:00 2001 From: Anthony Stange Date: Fri, 12 Jul 2019 17:55:30 -0400 Subject: [PATCH] Verify mPollThread is joinable before detaching If HidlSetUp() bails before startPollingThread() is called (which can happen if the HAL isn't implemented on the given device), mPollThread will initialize with the default constructor resulting in joinable() returning false which means calling detach() throws an exception. Checking joinable() before detaching allows the test suite to be skipped successfully. Fixes: 136736906 Test: Run vts-tradefed on VtsHalSensorsV1_0Target and verify that it is skipped successfully on a device that doesn't support HAL 1.0 Change-Id: Ie685ae2dc314edb8df2f3cc7112141a2f5e46008 --- sensors/common/vts/utils/SensorsHidlEnvironmentBase.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sensors/common/vts/utils/SensorsHidlEnvironmentBase.cpp b/sensors/common/vts/utils/SensorsHidlEnvironmentBase.cpp index affdf8b6b3..fa0e2e9bf0 100644 --- a/sensors/common/vts/utils/SensorsHidlEnvironmentBase.cpp +++ b/sensors/common/vts/utils/SensorsHidlEnvironmentBase.cpp @@ -29,7 +29,9 @@ void SensorsHidlEnvironmentBase::HidlSetUp() { void SensorsHidlEnvironmentBase::HidlTearDown() { mStopThread = true; - mPollThread.detach(); + if (mPollThread.joinable()) { + mPollThread.detach(); + } } void SensorsHidlEnvironmentBase::catEvents(std::vector* output) {