From 20d8eca927909d8c885c95c95453b21cc6d9a0db Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 2 May 2022 21:19:47 +0900 Subject: [PATCH] Fix Ecore Handler Setting Ecore events is separated from Init() method to prevent a crash issue. If the ecore_wl2_shutdown() is called before app_terminate_cb() call, the application will be crashed by that. While calling the ecore_wl2_shutdown(), resources related to the wayland are released. Currently, the indicator application has crashed when calling the tzsh_indicator_service_destroy(). Because, it's released by the EcoreHandler::Fini(). The EcoreHandler::SetEvents() and the EcoreHandler::UnsetEvents() are added. Change-Id: Ic153709518b24e4083688d1ccffb37e44c835a66 Signed-off-by: Hwankyu Jhun --- .../app_core_multi_window_base.cc | 36 +++++++++++----------- tizen-cpp/app-core-ui-cpp/app_core_ui_base.cc | 7 +++-- .../app-core-ui-cpp/wayland_handler_private.cc | 13 ++++---- tizen-cpp/common/ecore_handler.cc | 30 ++++++++++-------- tizen-cpp/common/ecore_handler.hh | 2 ++ 5 files changed, 49 insertions(+), 39 deletions(-) diff --git a/tizen-cpp/app-core-multi-window-cpp/app_core_multi_window_base.cc b/tizen-cpp/app-core-multi-window-cpp/app_core_multi_window_base.cc index df107e5..6f3e89c 100644 --- a/tizen-cpp/app-core-multi-window-cpp/app_core_multi_window_base.cc +++ b/tizen-cpp/app-core-multi-window-cpp/app_core_multi_window_base.cc @@ -190,23 +190,6 @@ AppCoreMultiWindowBase::FindByWindowId(int win_id) { } void AppCoreMultiWindowBase::Run(int argc, char** argv) { - AppCoreBase::Run(argc, argv); -} - -void AppCoreMultiWindowBase::Dispose() { - for (auto& i : impl_->contexts_) { - i->Exit(); - } - impl_->contexts_.clear(); - impl_->factory_map_.clear(); - if (impl_->handler_.get() != nullptr) - impl_->handler_->Fini(); - AppCoreBase::Dispose(); -} - -int AppCoreMultiWindowBase::OnCreate() { - AppCoreBase::OnCreate(); - class Trimmer : public EcoreHandler::ITrim { public: bool IsTrimmable() { @@ -224,9 +207,26 @@ int AppCoreMultiWindowBase::OnCreate() { }; impl_->trim_ = std::unique_ptr(new Trimmer(this)); - impl_->handler_ = std::make_shared(this, impl_->trim_.get()); impl_->handler_->Init(); + + AppCoreBase::Run(argc, argv); +} + +void AppCoreMultiWindowBase::Dispose() { + for (auto& i : impl_->contexts_) { + i->Exit(); + } + impl_->contexts_.clear(); + impl_->factory_map_.clear(); + impl_->handler_->UnsetEvents(); + AppCoreBase::Dispose(); + impl_->handler_->Fini(); +} + +int AppCoreMultiWindowBase::OnCreate() { + impl_->handler_->SetEvents(); + AppCoreBase::OnCreate(); return 0; } diff --git a/tizen-cpp/app-core-ui-cpp/app_core_ui_base.cc b/tizen-cpp/app-core-ui-cpp/app_core_ui_base.cc index ab32f25..0683982 100644 --- a/tizen-cpp/app-core-ui-cpp/app_core_ui_base.cc +++ b/tizen-cpp/app-core-ui-cpp/app_core_ui_base.cc @@ -402,6 +402,8 @@ void AppCoreUiBase::DoRun(int argc, char** argv) { SetCoreUiDelegator(nullptr); SetWindowDelegator(this); impl_->plugin_delegator_.reset(); + + impl_->handler_->Init(); impl_->PluginInit(argc, argv); char appid[PATH_MAX] = {0, }; @@ -409,7 +411,6 @@ void AppCoreUiBase::DoRun(int argc, char** argv) { if (ret != 0) _E("Fail to get appid. pid(%d)", getpid()); - impl_->handler_->Init(); impl_->state_ = Impl::AS_NONE; impl_->w_status_ = Impl::WS_NONE; impl_->appid_ = std::string(appid); @@ -486,13 +487,14 @@ void AppCoreUiBase::Exit() { } void AppCoreUiBase::Dispose() { - impl_->handler_->Fini(); + impl_->handler_->UnsetEvents(); impl_->FiniWl(); impl_->appid_.clear(); AppCoreBase::Dispose(); impl_->PluginFini(); + impl_->handler_->Fini(); } std::unique_ptr AppCoreUiBase::CreateTask() { @@ -693,6 +695,7 @@ int AppCoreUiBase::OnReceive(aul_type type, tizen_base::Bundle b) { } int AppCoreUiBase::OnCreate() { + impl_->handler_->SetEvents(); AppCoreBase::OnCreate(); impl_->state_ = Impl::AS_CREATED; LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:create:done]", diff --git a/tizen-cpp/app-core-ui-cpp/wayland_handler_private.cc b/tizen-cpp/app-core-ui-cpp/wayland_handler_private.cc index 7eb953f..3d89b70 100644 --- a/tizen-cpp/app-core-ui-cpp/wayland_handler_private.cc +++ b/tizen-cpp/app-core-ui-cpp/wayland_handler_private.cc @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include @@ -34,7 +35,11 @@ int WaylandHandler::Init() { if (__builtin_expect(initialized_, 1)) return 0; - dsp_ = wl_display_connect(nullptr); + auto* wl2_dsp = ecore_wl2_connected_display_get(nullptr); + if (wl2_dsp == nullptr) + wl2_dsp = ecore_wl2_display_connect(nullptr); + + dsp_ = ecore_wl2_display_get(wl2_dsp); if (dsp_ == nullptr) { _E("wl_display_connect() is failed"); return -1; @@ -74,11 +79,7 @@ void WaylandHandler::Fini() { reg_ = nullptr; } - if (dsp_) { - wl_display_disconnect(dsp_); - dsp_ = nullptr; - } - + dsp_ = nullptr; initialized_ = false; } diff --git a/tizen-cpp/common/ecore_handler.cc b/tizen-cpp/common/ecore_handler.cc index f95e1f2..a2f725d 100644 --- a/tizen-cpp/common/ecore_handler.cc +++ b/tizen-cpp/common/ecore_handler.cc @@ -120,6 +120,22 @@ void EcoreHandler::Init() { ecore_wl2_display_connect(nullptr); traceEnd(TTRACE_TAG_APPLICATION_MANAGER); + initialized_ = true; +} + +void EcoreHandler::Fini() { + if (!initialized_) + return; + + RemoveFlushTimer(); + + _E("Disconnect Wayland display"); + ecore_wl2_display_disconnect(ecore_wl2_connected_display_get(nullptr)); + ecore_wl2_shutdown(); + initialized_ = false; +} + +void EcoreHandler::SetEvents() { hshow_ = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_SHOW, StubShowCb, this); if (hshow_ == nullptr) @@ -149,16 +165,9 @@ void EcoreHandler::Init() { StubAuxMessageCb, this); if (hauxmsg_ == nullptr) _E("Failed to add ECORE_WL2_EVENT_AUX_MESSAGE event"); - - initialized_ = true; } -void EcoreHandler::Fini() { - if (!initialized_) - return; - - RemoveFlushTimer(); - +void EcoreHandler::UnsetEvents() { if (hshow_) { ecore_event_handler_del(hshow_); hshow_ = nullptr; @@ -188,11 +197,6 @@ void EcoreHandler::Fini() { ecore_event_handler_del(hauxmsg_); hauxmsg_ = nullptr; } - - _E("Disconnect Wayland display"); - ecore_wl2_display_disconnect(ecore_wl2_connected_display_get(nullptr)); - ecore_wl2_shutdown(); - initialized_ = false; } void EcoreHandler::RaiseWin(unsigned int win_id) { diff --git a/tizen-cpp/common/ecore_handler.hh b/tizen-cpp/common/ecore_handler.hh index 04e641d..203f8e3 100644 --- a/tizen-cpp/common/ecore_handler.hh +++ b/tizen-cpp/common/ecore_handler.hh @@ -39,6 +39,8 @@ class EcoreHandler { void Init(); void Fini(); + void SetEvents(); + void UnsetEvents(); void RaiseWin(unsigned int win_id); void PauseWin(unsigned int win_id); ITrim* GetTrim(); -- 2.7.4