+
+#ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
+static void __suspend_dbus_signal_handler(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ struct appcore *ac = (struct appcore *)user_data;
+ gint suspend = APPCORE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
+ gint pid;
+ gint status;
+
+ if (g_strcmp0(signal_name, RESOURCED_FREEZER_SIGNAL) == 0) {
+ g_variant_get(parameters, "(ii)", &status, &pid);
+ if (pid == getpid() && status == 0) { /* thawed */
+ if (ac && !ac->allowed_bg && ac->suspended_state) {
+ __remove_suspend_timer(ac);
+ __sys_do(ac, &suspend, SE_SUSPENDED_STATE);
+ ac->suspended_state = false;
+ __add_suspend_timer(ac);
+ }
+ }
+ }
+}
+
+int __appcore_init_suspend_dbus_handler(void *data)
+{
+ GError *err = NULL;
+
+ if (__suspend_dbus_handler_initialized)
+ return 0;
+
+ if (!bus) {
+ bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+ if (!bus) {
+ _ERR("Failed to connect to the D-BUS daemon: %s",
+ err->message);
+ g_error_free(err);
+ return -1;
+ }
+ }
+
+ __suspend_dbus_handler_initialized = g_dbus_connection_signal_subscribe(
+ bus,
+ NULL,
+ RESOURCED_FREEZER_INTERFACE,
+ RESOURCED_FREEZER_SIGNAL,
+ RESOURCED_FREEZER_PATH,
+ NULL,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ __suspend_dbus_signal_handler,
+ data,
+ NULL);
+ if (__suspend_dbus_handler_initialized == 0) {
+ _ERR("g_dbus_connection_signal_subscribe() is failed.");
+ return -1;
+ }
+
+ _DBG("[__SUSPEND__] suspend signal initialized");
+
+ return 0;
+}
+
+void __appcore_fini_suspend_dbus_handler(void)
+{
+ if (bus == NULL)
+ return;
+
+ if (__suspend_dbus_handler_initialized) {
+ g_dbus_connection_signal_unsubscribe(bus,
+ __suspend_dbus_handler_initialized);
+ __suspend_dbus_handler_initialized = 0;
+ }
+
+ g_object_unref(bus);
+ bus = NULL;
+}
+#endif
+