power: add getter wakeup reason 82/285682/1
authorTaeminYeom <taemin.yeom@samsung.com>
Thu, 1 Dec 2022 08:59:14 +0000 (17:59 +0900)
committerTaemin Yeom <taemin.yeom@samsung.com>
Fri, 16 Dec 2022 08:59:17 +0000 (08:59 +0000)
Add function to get wakeup reason by calling hal api function
and save wakup reason.

Add dbus method to delliver saved wakeup reason to device API.

"wakeup reason" is the power transition state reason of sleep to normal.
There are several reasons why the device wakeup and
sometimes it Is needed to get the reason.

added dbus method:
dbus_power_get_wakeup_reason
  path: "/Org/Tizen/System/DeviceD/Power"
  interace: "org.tizen.system.deviced.Power"
  member: "PowerGetWakeupReason"
  paremeter: "(i)", enum transition reason to get.
  return: "(i)", 0 on success, negative on error.

Change-Id: I2f96fecb3bc1308afc712421e3b2f6c8a7efefea
Signed-off-by: TaeminYeom <taemin.yeom@samsung.com>
(cherry picked from commit 5f262d9d915ec4b49e6a78a0bec04bfb30f3fdfd)

src/power/power-dbus.c
src/power/power-suspend.c
src/power/power-suspend.h

index 4c5a292..79bd067 100644 (file)
@@ -453,6 +453,13 @@ static GVariant *dbus_power_get_state(GDBusConnection *conn,
        return g_variant_new("(t)", mapping_device_state[index]);
 }
 
+static GVariant *dbus_power_get_wakeup_reason(GDBusConnection *conn,
+       const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
+       GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
+{
+       return g_variant_new("(i)", power_get_wakeup_reason());
+}
+
 static const dbus_method_s dbus_methods[] = {
        { "LockCpu",                         "i",   "i",  dbus_power_lock_cpu },
        { "UnlockCpu",                       NULL,  "i",  dbus_power_unlock_cpu },
@@ -463,6 +470,7 @@ static const dbus_method_s dbus_methods[] = {
        { "ConfirmChangeStateWait",          "t",   "i",  dbus_power_confirm_change_state_wait },
        { "PowerChangeState",                "t",   "i",  dbus_power_change_state },
        { "PowerGetState",                   NULL,  "t",  dbus_power_get_state },
+       { "PowerGetWakeupReason",            NULL,  "i",  dbus_power_get_wakeup_reason },
        /* Add methods here */
 };
 
index f7cf357..c50bcfd 100644 (file)
@@ -16,7 +16,6 @@
  * limitations under the License.
  */
 
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdbool.h>
@@ -49,6 +48,7 @@ static int mainlock_status = POWER_UNLOCK;
 static int vital_service;
 static bool vital_sleep;
 static int vital_support = -2;
+static enum hal_device_power_transition_reason wakeup_reason = HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN;
 
 #ifdef ENABLE_PM_LOG
 
@@ -148,6 +148,11 @@ static int vital_mode_support(void)
        return vital_support;
 }
 
+static int update_wakeup_reason(void)
+{
+       return hal_device_power_get_wakeup_reason(&wakeup_reason);
+}
+
 int suspend_other_process(int type)
 {
        int ret = 0;
@@ -209,6 +214,14 @@ int pm_suspend(void)
        _I("system suspend");
        ret_val = sys_set_str(POWER_STATE_PATH, "mem");
        _I("System resume: %d", ret_val);
+
+       ret_val = update_wakeup_reason();
+       if (ret_val < 0) {
+               _E("Failed to update wakeup reason");
+               wakeup_reason = HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN;
+               return ret_val;
+       }
+
        return 0;
 }
 
@@ -274,6 +287,11 @@ int power_release_wakelock(void)
        return sys_set_str(POWER_UNLOCK_PATH, "mainlock");
 }
 
+enum hal_device_power_transition_reason power_get_wakeup_reason(void)
+{
+       return wakeup_reason;
+}
+
 int check_wakeup_src(void)
 {
        /*  TODO if nedded.
index a14b9d0..16a02e3 100644 (file)
@@ -20,6 +20,7 @@
 #define __DEVICED_POWER_SUSPEND_H__
 
 #include "display/core.h"
+#include <hal/device/hal-device-power.h>
 
 #define POWER_AUTOSLEEP_PATH    "/sys/power/autosleep"
 #define POWER_LOCK_PATH         "/sys/power/wake_lock"
@@ -81,6 +82,7 @@ int power_acquire_wakelock(void);
 int power_release_wakelock(void);
 int pm_get_power_lock(void);
 int pm_get_power_lock_support(void);
+enum hal_device_power_transition_reason power_get_wakeup_reason(void);
 int check_wakeup_src(void);
 int get_wakeup_count(int *cnt);
 int set_wakeup_count(int cnt);