diff --git a/vibrator/cs40l26/Vibrator.cpp b/vibrator/cs40l26/Vibrator.cpp index bd88ed4..787700d 100644 --- a/vibrator/cs40l26/Vibrator.cpp +++ b/vibrator/cs40l26/Vibrator.cpp @@ -203,7 +203,6 @@ enum vibe_state { VIBE_STATE_ASP, }; -std::mutex mActiveId_mutex; // protects mActiveId class DspMemChunk { private: @@ -1335,6 +1334,17 @@ static void incrementIndex(int *index) { *index += 1; } +Vibrator::~Vibrator() { + if (isUnderExternalControl()) { + ALOGD("Disabling external control"); + setExternalControl(false); + } + ALOGD("Turning off the vibrator"); + off(); + ALOGD("Waiting for mAsyncHandle to complete"); + mAsyncHandle.wait(); +} + ndk::ScopedAStatus Vibrator::composePwle(const std::vector &composite, const std::shared_ptr &callback) { ATRACE_NAME("Vibrator::composePwle"); diff --git a/vibrator/cs40l26/Vibrator.h b/vibrator/cs40l26/Vibrator.h index b576501..b8e31de 100644 --- a/vibrator/cs40l26/Vibrator.h +++ b/vibrator/cs40l26/Vibrator.h @@ -153,6 +153,7 @@ class Vibrator : public BnVibrator { Vibrator(std::unique_ptr hwApiDefault, std::unique_ptr hwCalDefault, std::unique_ptr hwApiDual, std::unique_ptr hwCalDual, std::unique_ptr hwgpio); + virtual ~Vibrator(); // BnVibrator APIs ndk::ScopedAStatus getCapabilities(int32_t *_aidl_return) override; @@ -255,6 +256,7 @@ class Vibrator : public BnVibrator { bool mConfigHapticAlsaDeviceDone{false}; bool mGPIOStatus; bool mIsDual{false}; + std::mutex mActiveId_mutex; // protects mActiveId }; } // namespace vibrator diff --git a/vibrator/cs40l26/tests/test-vibrator.cpp b/vibrator/cs40l26/tests/test-vibrator.cpp index 7c68c86..dbce7c5 100644 --- a/vibrator/cs40l26/tests/test-vibrator.cpp +++ b/vibrator/cs40l26/tests/test-vibrator.cpp @@ -335,7 +335,9 @@ TEST_F(VibratorTest, Constructor) { EXPECT_CALL(*mMockApi, destructor()).WillOnce(DoDefault()); EXPECT_CALL(*mMockCal, destructor()).WillOnce(DoDefault()); EXPECT_CALL(*mMockGpio, destructor()).WillOnce(DoDefault()); - + // Mock calls for the VIbrator destructor. + EXPECT_CALL(*mMockApi, recordEvent(_, _)).WillRepeatedly(DoDefault()); + EXPECT_CALL(*mMockApi, setFFGain(_, ON_GLOBAL_SCALE)).WillOnce(DoDefault()); deleteVibrator(false); createMock(&mockapi, &mockcal, &mockgpio);