#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>
#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 */
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)
/* 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;
}
return haptic_module_load();
}
-static guint id_sig_pwr_off_state;
-
void haptic_init(void)
{
int r;
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;
}
_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);