Fix Ecore Handler 64/274564/4
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 2 May 2022 12:19:47 +0000 (21:19 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 2 May 2022 23:31:53 +0000 (08:31 +0900)
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 <h.jhun@samsung.com>
tizen-cpp/app-core-multi-window-cpp/app_core_multi_window_base.cc
tizen-cpp/app-core-ui-cpp/app_core_ui_base.cc
tizen-cpp/app-core-ui-cpp/wayland_handler_private.cc
tizen-cpp/common/ecore_handler.cc
tizen-cpp/common/ecore_handler.hh

index df107e5..6f3e89c 100644 (file)
@@ -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<EcoreHandler::ITrim>(new Trimmer(this));
-
   impl_->handler_ = std::make_shared<EcoreHandler>(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;
 }
 
index ab32f25..0683982 100644 (file)
@@ -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<AppCoreTaskBase> 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]",
index 7eb953f..3d89b70 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <Ecore_Wl2.h>
 #include <sys/types.h>
 #include <unistd.h>
 
@@ -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;
 }
 
index f95e1f2..a2f725d 100644 (file)
@@ -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) {
index 04e641d..203f8e3 100644 (file)
@@ -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();