#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"
int val_ = -1;
};
-class AppCoreBase::Impl {
+class AppCoreBase::Impl : public SuspendEvent::IEventListener {
public:
explicit Impl(AppCoreBase* parent) : parent_(parent) {}
void AppendLangs(const std::string& lang, std::vector<std::string>* lang_set,
std::map<std::string, std::set<std::string>>* table);
void ChangeLang();
- void HandleThawEvent();
+ void OnFreezerSignal();
template <class T>
void InvokeCallback(T event, IEvent::Type type) {
}
}
+ 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);
IMainLoop* loop_delegator_ = nullptr;
guint signal_handler_source_ = 0;
std::unique_ptr<AppCorePlugin> plugin_;
+ std::unique_ptr<SuspendEvent> suspend_event_;
};
AppCoreBase::EventBase::EventBase(Type type)
impl_->InvokeCallback(event, type);
}
-void AppCoreBase::Impl::HandleThawEvent() {
+void AppCoreBase::Impl::OnFreezerSignal() {
if (!allowed_bg_ && suspended_state_) {
parent_->RemoveSuspendTimer();
InvokeCallback(SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND,
}
}
+void AppCoreBase::Impl::InitSuspend() {
+ suspend_event_.reset(new SuspendEvent(this));
+}
+
gboolean AppCoreBase::Impl::InvokeLangChangeCb(gpointer data) {
AppCoreBase* base = reinterpret_cast<AppCoreBase*>(data);
base->impl_->sid_ = 0;
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<AppCoreBase*>(user_data);
if (base->impl_->sid_) {
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);
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;
--- /dev/null
+/*
+ * 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<SuspendEvent*>(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<SuspendEvent*>(user_data);
+ event->listener_->OnSuspend(pid, status);
+}
+
+} // namespace tizen_cpp
--- /dev/null
+/*
+ * 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 <gio/gio.h>
+#include <glib.h>
+#include <sys/types.h>
+
+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_