power: launch popup for user to notice the battery comsumption 01/98601/3 accepted/tizen/3.0/common/20161123.140950 accepted/tizen/3.0/ivi/20161123.083949 accepted/tizen/3.0/mobile/20161123.083850 accepted/tizen/3.0/tv/20161123.083914 accepted/tizen/3.0/wearable/20161123.083932 submit/tizen_3.0/20161122.133614
authortaeyoung <ty317.kim@samsung.com>
Thu, 27 Oct 2016 04:37:06 +0000 (13:37 +0900)
committertaeyoung <ty317.kim@samsung.com>
Mon, 21 Nov 2016 10:43:31 +0000 (19:43 +0900)
- 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 <ty317.kim@samsung.com>
src/dbus.c
src/power.c

index dcfde8d..15e7051 100644 (file)
@@ -21,6 +21,7 @@
 #include <stdlib.h>
 #include <stdint.h>
 #include <errno.h>
+#include <stdarg.h>
 
 #include "common.h"
 #include "dbus.h"
index 2f6f713..34e3731 100644 (file)
@@ -19,6 +19,8 @@
 #include <stdlib.h>
 #include <stdbool.h>
 #include <errno.h>
+#include <glib.h>
+#include <limits.h>
 
 #ifdef TIZEN_FEATURE_TRACKER
 #include <tracker.h>
@@ -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;
 }