diff --git a/vibrator/cs40l26/Vibrator.cpp b/vibrator/cs40l26/Vibrator.cpp index bd88ed4..06eba39 100644 --- a/vibrator/cs40l26/Vibrator.cpp +++ b/vibrator/cs40l26/Vibrator.cpp @@ -1335,6 +1335,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..eab9461 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; 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);