diff --git a/wmserver/include/remote_animation.h b/wmserver/include/remote_animation.h index 12f3285bd39f591ad73cb65f57b4d69d7f003820..3fc7aa709c1bfdaa5f322d9b3afeca28e2f900b6 100644 --- a/wmserver/include/remote_animation.h +++ b/wmserver/include/remote_animation.h @@ -101,6 +101,7 @@ private: static std::weak_ptr wmsTaskHandler_; static wptr windowController_; static bool animationFirst_; + static std::atomic allocationId_; }; } // Rosen } // OHOS diff --git a/wmserver/src/remote_animation.cpp b/wmserver/src/remote_animation.cpp index 8ff1e2000319fe8328288b7a493e4619972a6818..3ecb7ee045dbb875587355076b51cffb18828e9e 100644 --- a/wmserver/src/remote_animation.cpp +++ b/wmserver/src/remote_animation.cpp @@ -32,9 +32,11 @@ namespace OHOS { namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "RemoteAnimation"}; + const std::string ANIMATION_TIME_OUT_TASK = "remote_animation_time_out_task"; + constexpr int64_t ANIMATION_TIME_OUT_MILLISECONDS = 3000; // 3000 is max time } bool RemoteAnimation::isRemoteAnimationEnable_ = true; - +std::atomic RemoteAnimation::allocationId_ = 0; sptr RemoteAnimation::windowAnimationController_ = nullptr; std::weak_ptr RemoteAnimation::wmsTaskHandler_; wptr RemoteAnimation::windowRoot_; @@ -728,8 +730,14 @@ void RemoteAnimation::ProcessNodeStateTask(sptr& node) WLOGFI("node is nullptr!"); return; } - node->stateMachine_.UpdateAnimationTaskCount(false); int32_t taskCount = node->stateMachine_.GetAnimationCount(); + if (taskCount <= 0) { // no animation task but finishCallback come + WLOGFE("ProcessNodeStateTask failed with windowId: %{public}u, name:%{public}s taskCount:%{public}d", + node->GetWindowId(), node->GetWindowName().c_str(), taskCount); + return; + } + node->stateMachine_.UpdateAnimationTaskCount(false); + taskCount = node->stateMachine_.GetAnimationCount(); WLOGFI("ProcessNodeStateTask windowId: %{public}u, name:%{public}s state: %{public}u, taskCount:%{public}d", node->GetWindowId(), node->GetWindowName().c_str(), static_cast(node->stateMachine_.GetCurrentState()), taskCount); @@ -871,15 +879,24 @@ sptr RemoteAnimation::CreateAnimationFinished WLOGFE("callback is null!"); return nullptr; } - auto func = [callback]() { + auto currentId = allocationId_.fetch_add(1); + std::string timeOutTaskName = ANIMATION_TIME_OUT_TASK + std::to_string(currentId); + auto func = [callback, timeOutTaskName]() { auto handler = wmsTaskHandler_.lock(); if (handler != nullptr) { + handler->RemoveTask(timeOutTaskName); + WLOGFD("remove task %{public}s since animationCallback Come", timeOutTaskName.c_str()); handler->PostTask(callback, AppExecFwk::EventQueue::Priority::IMMEDIATE); } else { WLOGFW("callback execute not on main wms thread since handler is null!"); callback(); } }; + auto handlerSptr = wmsTaskHandler_.lock(); + if (handlerSptr != nullptr) { + handlerSptr->PostTask(func, timeOutTaskName, ANIMATION_TIME_OUT_MILLISECONDS); + WLOGFD("PostTask task %{public}s", timeOutTaskName.c_str()); + } sptr finishCallback = new(std::nothrow) RSWindowAnimationFinishedCallback( func); if (finishCallback == nullptr) {