From: taeyoung Date: Thu, 27 Oct 2016 04:37:06 +0000 (+0900) Subject: power: launch popup for user to notice the battery comsumption X-Git-Tag: submit/tizen_3.0/20161122.133614^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e570769e60c39b1568bb00d4bdb34b5d78c13c44;p=platform%2Fcore%2Fapi%2Fdevice.git power: launch popup for user to notice the battery comsumption - After timeout of the permanant power lock, capi-system-device asks to deviced whether or not the power lock needs to be released. Change-Id: I8766280ef49b0f60ce81cd72e8b8e3f9c38ac8b2 Signed-off-by: taeyoung --- diff --git a/src/dbus.c b/src/dbus.c index dcfde8d..15e7051 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "common.h" #include "dbus.h" diff --git a/src/power.c b/src/power.c index 2f6f713..34e3731 100644 --- a/src/power.c +++ b/src/power.c @@ -19,6 +19,8 @@ #include #include #include +#include +#include #ifdef TIZEN_FEATURE_TRACKER #include @@ -73,6 +75,9 @@ static guint off_lock_timeout; static guint padding_timeout; static int prev_count; + +static GList *request_id_list; + #endif static struct _lock_timeout { @@ -117,6 +122,84 @@ static void remove_padding_timeout(void) } } +static void notice_lock_expired_done(void *data, GVariant *result, GError *err) +{ + int val, ret; + GList *l, *l_next; + char *id, *elem; + size_t len; + + if (!result) + return; + + g_variant_get(result, "(si)", &id, &val); + + len = strlen(id) + 1; + for (l = request_id_list, l_next = g_list_next(l); + l && (elem = l->data) != NULL; + l = l_next, l_next = g_list_next(l), elem = NULL) { + if (!strncmp(id, elem, len)) + break; + } + if (!elem) + return; + + request_id_list = g_list_remove(request_id_list, elem); + free(elem); + + if (val == 0) { /* Allow to lock cpu */ + _I("Continue Power Lock"); + return; + } else if (val == 1) { /* Release cpu lock */ + ret = device_power_release_lock(POWER_LOCK_CPU); + if (ret != DEVICE_ERROR_NONE) + _E("Failed to release power(CPU) (%d)", ret); + } +} + +static char *get_new_request_id(pid_t pid) +{ + char id[64]; + snprintf(id, sizeof(id), "%d_%lu", pid, time(NULL)); + return strdup(id); +} + +static int notice_power_lock_expired(void) +{ + int ret; + pid_t pid; + char *req_id; + char *param[1]; + + pid = getpid(); + + req_id = get_new_request_id(pid); + if (!req_id) { + _E("Failed to get request id"); + return ret; + } + + param[0] = req_id; + ret = dbus_method_async_with_reply( + DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "LockTimeoutExpired", + "s", param, + notice_lock_expired_done, + -1, + NULL); + if (ret < 0) { + _E("Failed to notice power lock expired (%d)", ret); + return ret; + } + + request_id_list = g_list_append(request_id_list, req_id); + _I("request ID %s is added", req_id); + + return 0; +} + static gboolean padding_timeout_expired(gpointer data) { int ret, ref; @@ -150,11 +233,13 @@ static gboolean padding_timeout_expired(gpointer data) } out: - remove_off_lock_timeout(); + ret = notice_power_lock_expired(); + if (ret < 0) { + _E("Failed to launch power lock expired popup (%d)", ret); + return G_SOURCE_CONTINUE; + } - ret = device_power_release_lock(POWER_LOCK_CPU); - if (ret != DEVICE_ERROR_NONE) - _E("Failed to lock power(CPU) again(%d)", ret); + remove_off_lock_timeout(); return G_SOURCE_REMOVE; }