From 2ed56134f3a2696d742ee719ce7ee0c9c01f2688 Mon Sep 17 00:00:00 2001 From: z30053720 Date: Mon, 28 Oct 2024 09:15:16 +0800 Subject: [PATCH] fix timepicker Memory leak Signed-off-by: z30053720 --- .../entrance/timepicker/timepicker_haptic_controller.cpp | 5 +++++ .../entrance/timepicker/timepicker_haptic_controller.h | 1 + .../ohos/entrance/timepicker/timepicker_haptic_impl.cpp | 7 +++++++ adapter/ohos/entrance/timepicker/timepicker_haptic_impl.h | 1 + adapter/ohos/entrance/timepicker/timepicker_haptic_stub.h | 1 + .../pattern/time_picker/timepicker_column_pattern.cpp | 1 + .../pattern/time_picker/timepicker_haptic_interface.h | 1 + 7 files changed, 17 insertions(+) diff --git a/adapter/ohos/entrance/timepicker/timepicker_haptic_controller.cpp b/adapter/ohos/entrance/timepicker/timepicker_haptic_controller.cpp index d3dedd6c824..1438285c3d1 100644 --- a/adapter/ohos/entrance/timepicker/timepicker_haptic_controller.cpp +++ b/adapter/ohos/entrance/timepicker/timepicker_haptic_controller.cpp @@ -207,6 +207,11 @@ void TimePickerHapticController::HandleDelta(double dy) } } +void TimePickerHapticController::ClearVelocityInfo() +{ + velocityTracker_.Reset(); +} + double TimePickerHapticController::ConvertPxToMillimeters(double px) const { auto& manager = ScreenSystemManager::GetInstance(); diff --git a/adapter/ohos/entrance/timepicker/timepicker_haptic_controller.h b/adapter/ohos/entrance/timepicker/timepicker_haptic_controller.h index f4b815a9993..87ca9eac695 100644 --- a/adapter/ohos/entrance/timepicker/timepicker_haptic_controller.h +++ b/adapter/ohos/entrance/timepicker/timepicker_haptic_controller.h @@ -48,6 +48,7 @@ public: void PlayOnce() override; void Stop() override; void HandleDelta(double dy) override; + void ClearVelocityInfo() override; private: void ThreadLoop(); diff --git a/adapter/ohos/entrance/timepicker/timepicker_haptic_impl.cpp b/adapter/ohos/entrance/timepicker/timepicker_haptic_impl.cpp index 4a7a5c030a6..9b9c2f4df55 100644 --- a/adapter/ohos/entrance/timepicker/timepicker_haptic_impl.cpp +++ b/adapter/ohos/entrance/timepicker/timepicker_haptic_impl.cpp @@ -50,4 +50,11 @@ void TimepickerAudioHapticImpl::HandleDelta(double dy) } } +void TimepickerAudioHapticImpl::ClearVelocityInfo() +{ + if (handler_) { + handler_->ClearVelocityInfo(); + } +} + } // namespace OHOS::Ace::NG diff --git a/adapter/ohos/entrance/timepicker/timepicker_haptic_impl.h b/adapter/ohos/entrance/timepicker/timepicker_haptic_impl.h index fed275d1a90..b63c1bd3637 100644 --- a/adapter/ohos/entrance/timepicker/timepicker_haptic_impl.h +++ b/adapter/ohos/entrance/timepicker/timepicker_haptic_impl.h @@ -28,6 +28,7 @@ public: void PlayOnce() override; void Stop() override; void HandleDelta(double dy) override; + void ClearVelocityInfo() override; private: std::unique_ptr handler_ = nullptr; }; diff --git a/adapter/ohos/entrance/timepicker/timepicker_haptic_stub.h b/adapter/ohos/entrance/timepicker/timepicker_haptic_stub.h index 99249772edb..3606b462c97 100644 --- a/adapter/ohos/entrance/timepicker/timepicker_haptic_stub.h +++ b/adapter/ohos/entrance/timepicker/timepicker_haptic_stub.h @@ -27,6 +27,7 @@ public: void PlayOnce() {} void Stop() {} void HandleDelta(double dy) {} + void ClearVelocityInfo() {} }; } // namespace OHOS::Ace::NG #endif // FOUNDATION_ACE_ENGINE_ADAPTER_OHOS_TIMEPICKER_AUDIO_HAPTIC_STUB_H diff --git a/frameworks/core/components_ng/pattern/time_picker/timepicker_column_pattern.cpp b/frameworks/core/components_ng/pattern/time_picker/timepicker_column_pattern.cpp index b7830e14c55..bff6c793ec2 100644 --- a/frameworks/core/components_ng/pattern/time_picker/timepicker_column_pattern.cpp +++ b/frameworks/core/components_ng/pattern/time_picker/timepicker_column_pattern.cpp @@ -870,6 +870,7 @@ void TimePickerColumnPattern::HandleDragEnd() { if (hapticController_) { hapticController_->Stop(); + hapticController_->ClearVelocityInfo(); } pressed_ = false; CHECK_NULL_VOID(GetHost()); diff --git a/frameworks/core/components_ng/pattern/time_picker/timepicker_haptic_interface.h b/frameworks/core/components_ng/pattern/time_picker/timepicker_haptic_interface.h index f782beb9abb..47063f0a655 100644 --- a/frameworks/core/components_ng/pattern/time_picker/timepicker_haptic_interface.h +++ b/frameworks/core/components_ng/pattern/time_picker/timepicker_haptic_interface.h @@ -26,6 +26,7 @@ public: virtual void PlayOnce() = 0; virtual void Stop() = 0; virtual void HandleDelta(double dy) = 0; + virtual void ClearVelocityInfo() = 0; }; } // namespace OHOS::Ace::NG #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TIME_PICKER_AUDIO_HAPTIC_INTERFACE_H