Apply new poweroff handler 73/275673/1 accepted/tizen_6.5_unified accepted/tizen/6.5/unified/20220602.131935 submit/tizen_6.5/20220531.085836
authorYoungjae Cho <y0.cho@samsung.com>
Thu, 26 May 2022 03:06:55 +0000 (12:06 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Mon, 30 May 2022 02:17:05 +0000 (02:17 +0000)
Change-Id: I6ca6fc17ddcc2c16e98b939604cf93f89e4d8817
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
(cherry picked from commit 2e2e22fad41efb3d6212005319fa450d6de22b59)

src/core/haptic.c

index e644f1c..4fea07d 100644 (file)
@@ -24,6 +24,8 @@
 #include <vconf.h>
 #include <time.h>
 #include <string.h>
+#include <inttypes.h>
+#include <device/power-internal.h>
 #include <libsyscommon/libgdbus.h>
 #include <libsyscommon/list.h>
 #include <libsyscommon/ini-parser.h>
@@ -39,7 +41,6 @@
 #define VIBRATION_CONF_PATH        FEEDBACK_BASE_PATH"vibration.conf"
 
 #define HAPTIC_CONF_PATH                "/etc/feedbackd/haptic.conf"
-#define SIGNAL_POWEROFF_STATE           "ChangeState"
 #define SIGNAL_VIBRATOR_INITIATED       "InitiateVibrator"
 
 /* hardkey vibration variable */
@@ -1133,27 +1134,12 @@ exit:
        return g_variant_new("(i)", ret);
 }
 
-static void haptic_poweroff_cb(GDBusConnection  *conn,
-       const gchar      *sender,
-       const gchar      *path,
-       const gchar      *iface,
-       const gchar      *name,
-       GVariant         *param,
-       gpointer          data)
+static void haptic_poweroff_cb(const struct device_change_state_info *info, void *udata)
 {
-       int type = POWER_OFF_NONE;
        int ret, level;
        struct timespec time = {0,};
 
-       if (!g_variant_get_safe(param, "(i)", &type)) {
-               _E("Failed to get params from gvariant. expected:%s, type:%s", "(i)", g_variant_get_type_string(param));
-               return;
-       }
-
-       if (type != POWER_OFF_DIRECT && type != POWER_OFF_RESTART)
-               return;
-
-       _D("Poweroff: %d", type);
+       _D("Poweroff: %"PRIx64, info->next_state);
 
        if (hal_device_haptic_check_backend() < 0) {
                if (haptic_module_load() < 0)
@@ -1185,6 +1171,9 @@ static void haptic_poweroff_cb(GDBusConnection  *conn,
        /* sleep for vibration */
        time.tv_nsec = POWER_OFF_VIB_DURATION * NANO_SECOND_MULTIPLIER;
        nanosleep(&time, NULL);
+
+       device_power_change_state_wait_done(info->id);
+
        return;
 }
 
@@ -1301,8 +1290,6 @@ int haptic_probe(void)
        return haptic_module_load();
 }
 
-static guint id_sig_pwr_off_state;
-
 void haptic_init(void)
 {
        int r;
@@ -1319,15 +1306,10 @@ void haptic_init(void)
        if (r < 0)
                _E("Failed to init hdbus interface and method: %d", r);
 
-       id_sig_pwr_off_state = gdbus_signal_subscribe(NULL,
-                       DEVICED_PATH_POWEROFF,
-                       DEVICED_INTERFACE_POWEROFF,
-                       SIGNAL_POWEROFF_STATE,
-                       haptic_poweroff_cb,
-                       NULL,
-                       NULL);
-       if (id_sig_pwr_off_state <= 0) {
-               _E("Failed to register signal handler: %d", r);
+       r = device_power_add_change_state_wait_callback(POWER_STATE_POWEROFF | POWER_STATE_REBOOT,
+               haptic_poweroff_cb, NULL);
+       if (r < 0) {
+               _E("Failed to register poweroff handler: %d", r);
                return;
        }
 
@@ -1360,8 +1342,7 @@ void haptic_exit(void)
                        _W("Remove watch for VCONFKEY_RECORDER_STATE failed.");
        }
 
-       /* unregister notifier for below each event */
-       gdbus_signal_unsubscribe(NULL, id_sig_pwr_off_state);
+       device_power_remove_change_state_wait_callback(POWER_STATE_POWEROFF | POWER_STATE_REBOOT);
 
        /* release haptic data memory */
        safe_free(haptic_conf.level_arr);