From ba23ef0c127fc808c7ba6c5ad2d6b2b548009e4d Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 5 Feb 2024 16:20:39 +0900 Subject: [PATCH] Remove suspend event handler To remove dbus dependency, this patch removes the suspend handler. The application manager daemon sends the APP_THAW event to the running process for handling the thawed event. Requires: - https://review.tizen.org/gerrit/#/c/platform/core/appfw/aul-1/+/305557/ - https://review.tizen.org/gerrit/#/c/platform/core/appfw/amd/+/305567/ Change-Id: I4088e44547348a4cd5599abb98cb02e202a40534 Signed-off-by: Hwankyu Jhun --- tizen-cpp/app-core-cpp/app_core_base.cc | 23 ++---- tizen-cpp/app-core-cpp/suspend_event_private.cc | 96 ------------------------- tizen-cpp/app-core-cpp/suspend_event_private.hh | 55 -------------- 3 files changed, 7 insertions(+), 167 deletions(-) delete mode 100644 tizen-cpp/app-core-cpp/suspend_event_private.cc delete mode 100644 tizen-cpp/app-core-cpp/suspend_event_private.hh diff --git a/tizen-cpp/app-core-cpp/app_core_base.cc b/tizen-cpp/app-core-cpp/app_core_base.cc index d7a854f..be5275c 100644 --- a/tizen-cpp/app-core-cpp/app_core_base.cc +++ b/tizen-cpp/app-core-cpp/app_core_base.cc @@ -53,7 +53,6 @@ #include "app-core-cpp/app_core_plugin_private.hh" #include "app-core-cpp/exit_handler_private.hh" #include "app-core-cpp/sigterm_handler_private.hh" -#include "app-core-cpp/suspend_event_private.hh" #include "common/glib_private.hh" #include "common/log_private.hh" #include "common/log_tracer.hh" @@ -84,7 +83,7 @@ class AppCoreBase::EventBase::Impl { int val_ = -1; }; -class AppCoreBase::Impl : public SuspendEvent::IEventListener { +class AppCoreBase::Impl { public: explicit Impl(AppCoreBase* parent) : parent_(parent) {} @@ -101,7 +100,7 @@ class AppCoreBase::Impl : public SuspendEvent::IEventListener { void AppendLangs(const std::string& lang, std::vector* lang_set, std::map>* table); void ChangeLang(); - void OnFreezerSignal(); + void HandleThawEvent(); template void InvokeCallback(T event, IEvent::Type type) { @@ -118,8 +117,6 @@ class AppCoreBase::Impl : public SuspendEvent::IEventListener { } } - void InitSuspend(); - void OnSuspend(pid_t pid, int status) override; static gboolean InvokeLangChangeCb(gpointer data); static void OnLowBatteryCb(keynode_t* key, void* data); static void OnTimeZoneChangedCb(keynode_t* key, void* data); @@ -150,7 +147,6 @@ class AppCoreBase::Impl : public SuspendEvent::IEventListener { IMainLoop* loop_delegator_ = nullptr; guint signal_handler_source_ = 0; std::unique_ptr plugin_; - std::unique_ptr suspend_event_; }; AppCoreBase::EventBase::EventBase(Type type) @@ -219,7 +215,7 @@ void AppCoreBase::RaiseEvent(const std::string& event, IEvent::Type type) { impl_->InvokeCallback(event, type); } -void AppCoreBase::Impl::OnFreezerSignal() { +void AppCoreBase::Impl::HandleThawEvent() { if (!allowed_bg_ && suspended_state_) { parent_->RemoveSuspendTimer(); InvokeCallback(SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND, @@ -229,10 +225,6 @@ void AppCoreBase::Impl::OnFreezerSignal() { } } -void AppCoreBase::Impl::InitSuspend() { - suspend_event_.reset(new SuspendEvent(this)); -} - gboolean AppCoreBase::Impl::InvokeLangChangeCb(gpointer data) { AppCoreBase* base = reinterpret_cast(data); base->impl_->sid_ = 0; @@ -240,10 +232,6 @@ gboolean AppCoreBase::Impl::InvokeLangChangeCb(gpointer data) { return G_SOURCE_REMOVE; } -void AppCoreBase::Impl::OnSuspend(pid_t pid, int status) { - if (pid == getpid() && status == 0) OnFreezerSignal(); -} - void AppCoreBase::Impl::LanguageChangeCb(keynode_t* key, void* user_data) { AppCoreBase* base = reinterpret_cast(user_data); if (base->impl_->sid_) { @@ -383,6 +371,10 @@ int AppCoreBase::OnReceive(aul_type type, tizen_base::Bundle b) { FlushMemory(); } break; + case AUL_THAW: + _D("[APP %d] AUL event: AUL_THAW", getpid()); + impl_->HandleThawEvent(); + break; case AUL_UPDATE_REQUESTED: _D("[APP %d] AUL event: AUL_UPDATE_REQUESTED", getpid()); impl_->InvokeCallback(0, IEvent::Type::UPDATE_REQUESTED); @@ -941,7 +933,6 @@ void AppCoreBase::Init(int argc, char** argv) { impl_->PluginInit(argc, argv); traceEnd(TTRACE_TAG_APPLICATION_MANAGER); - impl_->InitSuspend(); traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:SET_SYSTEM_EVENT"); if (!impl_->dirty_) { impl_->dirty_ = true; diff --git a/tizen-cpp/app-core-cpp/suspend_event_private.cc b/tizen-cpp/app-core-cpp/suspend_event_private.cc deleted file mode 100644 index c2378a8..0000000 --- a/tizen-cpp/app-core-cpp/suspend_event_private.cc +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "app-core-cpp/suspend_event_private.hh" - -#include "common/log_private.hh" - -namespace { - -constexpr const char RESOURCED_FREEZER_PATH[] = - "/Org/Tizen/ResourceD/Freezer"; -constexpr const char RESOURCED_FREEZER_INTERFACE[] = - "org.tizen.resourced.freezer"; -constexpr const char RESOURCED_FREEZER_SIGNAL[] = - "FreezerState"; - -} // namespace - -namespace tizen_cpp { - -SuspendEvent::SuspendEvent(IEventListener* listener) : listener_(listener) { - cancellable_ = g_cancellable_new(); - if (cancellable_ == nullptr) { - _E("g_cancellable_new() is failed"); - return; - } - - g_bus_get(G_BUS_TYPE_SYSTEM, cancellable_, GAsyncReadyCb, this); -} - -SuspendEvent::~SuspendEvent() { - if (source_ != 0) - g_dbus_connection_signal_unsubscribe(conn_, source_); - - if (conn_ != nullptr) - g_object_unref(conn_); - - if (cancellable_ != nullptr) { - g_cancellable_cancel(cancellable_); - g_object_unref(cancellable_); - } -} - -void SuspendEvent::GAsyncReadyCb(GObject* source_object, GAsyncResult* res, - gpointer user_data) { - auto* event = static_cast(user_data); - GError* error = nullptr; - event->conn_ = g_bus_get_finish(res, &error); - if (event->conn_ == nullptr) { - _E("g_bus_get_finish() is failed. error(%s)", error ? error->message : ""); - g_clear_error(&error); - return; - } - - event->source_ = g_dbus_connection_signal_subscribe( - event->conn_, nullptr, RESOURCED_FREEZER_INTERFACE, - RESOURCED_FREEZER_SIGNAL, RESOURCED_FREEZER_PATH, nullptr, - G_DBUS_SIGNAL_FLAGS_NONE, GDBusSignalCb, user_data, nullptr); - if (event->source_ == 0) { - _E("g_dbus_connection_signal_subscribe() is failed"); - return; - } - - _D("Suspend signal subscribed"); -} - -void SuspendEvent::GDBusSignalCb(GDBusConnection* conn, - const gchar* sender_name, - const gchar* object_path, - const gchar* interface_name, - const gchar* signal_name, GVariant* parameters, - gpointer user_data) { - if (g_strcmp0(signal_name, RESOURCED_FREEZER_SIGNAL) != 0) - return; - - gint pid = -1; - gint status = 0; - g_variant_get(parameters, "(ii)", &status, &pid); - auto* event = static_cast(user_data); - event->listener_->OnSuspend(pid, status); -} - -} // namespace tizen_cpp diff --git a/tizen-cpp/app-core-cpp/suspend_event_private.hh b/tizen-cpp/app-core-cpp/suspend_event_private.hh deleted file mode 100644 index 46cbe3e..0000000 --- a/tizen-cpp/app-core-cpp/suspend_event_private.hh +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef TIZEN_CPP_APP_CORE_CPP_SUSPEND_EVENT_PRIVATE_HH_ -#define TIZEN_CPP_APP_CORE_CPP_SUSPEND_EVENT_PRIVATE_HH_ - -#include -#include -#include - -namespace tizen_cpp { - -class SuspendEvent { - public: - class IEventListener { - public: - virtual ~IEventListener() = default; - virtual void OnSuspend(pid_t pid, int status) = 0; - }; - - explicit SuspendEvent(IEventListener* listener); - ~SuspendEvent(); - - private: - static void GAsyncReadyCb(GObject* source_object, GAsyncResult* res, - gpointer user_data); - static void GDBusSignalCb(GDBusConnection* conn, const gchar* sender_name, - const gchar* object_path, - const gchar* interface_name, - const gchar* signal_name, GVariant* parameters, - gpointer user_data); - - private: - IEventListener* listener_; - GDBusConnection* conn_ = nullptr; - GCancellable* cancellable_ = nullptr; - guint source_ = 0; -}; - -} // namespace tizen_cpp - -#endif // TIZEN_CPP_APP_CORE_CPP_SUSPEND_EVENT_PRIVATE_HH_ -- 2.7.4