power: Add setter for controlling doze source 96/299996/8 accepted/tizen/unified/20231115.024830
authorYoungjae Cho <y0.cho@samsung.com>
Fri, 13 Oct 2023 09:10:51 +0000 (18:10 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Thu, 9 Nov 2023 08:48:22 +0000 (17:48 +0900)
 Doze is going to replace the event-lock, that is, short-living power
lock. The purpose of doze is for keeping user applications in sleep
while the underneath system is awake, doing something for a moment. In
other words, it can be utilized for short wakeup without notifying it
to the whole applications, especially for jobs related to the real-time
clock. The system stays awake when there is at least a doze source.
 Currently, only two type of doze sources are allowed, power key and
bluetooth key. Those key presses should measure their time lapse with
real-time clock for testing longkey so the system must be awake at
that moment.

Change-Id: I91bdf11e34d18c170deb5d2c4a6a67e7e9565371
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/power/resource-power.c

index 6b44cd2c6eedb42759265816e709e571dff19540..dbecd9f792a1a35a91f032a3baa9df3494574c3a 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <stdint.h>
 
+#include <linux/input.h>
 #include <libsyscommon/resource-manager.h>
 #include <libsyscommon/resource-type.h>
 #include <system/syscommon-plugin-deviced-power.h>
@@ -28,6 +29,7 @@
 
 #include "power.h"
 #include "power-suspend.h"
+#include "power-event-lock.h"
 
 typedef union {
        int32_t i32;
@@ -163,6 +165,30 @@ static int set_power_attr_data(int resource_id,
                        vital_state_changed(mode);
                }
                break;
+       case DEVICED_POWER_ATTR_INT_ADD_DOZE_SOURCE:
+       case DEVICED_POWER_ATTR_INT_REMOVE_DOZE_SOURCE:
+               {
+                       int doze_source_id = *(const int *) data;
+                       enum eventlock_type type;
+
+                       /* currently only allow 2 type of source */
+                       switch (doze_source_id) {
+                       case KEY_POWER:
+                               type = EL_KEY_POWER;
+                               break;
+                       case KEY_BLUETOOTH:
+                               type = EL_KEY_BLUETOOTH;
+                               break;
+                       default:
+                               return -EINVAL;
+                       }
+
+                       if (attr->id == DEVICED_POWER_ATTR_INT_ADD_DOZE_SOURCE)
+                               event_wake_lock(type);
+                       else /* DEVICED_POWER_ATTR_INT_REMOVE_DOZE_SOURCE */
+                               event_wake_unlock(type);
+               }
+               break;
        default:
                return -EINVAL;
        }
@@ -270,6 +296,24 @@ static const struct syscommon_resman_resource_attribute power_attrs[] = {
                        .set_2_tuple = set_tuple2_power_attr_data,
                        .is_supported = syscommon_resman_resource_attr_supported_always,
                },
+       }, {
+               .name = "DEVICED_POWER_ATTR_INT_ADD_DOZE_SOURCE",
+               .id = DEVICED_POWER_ATTR_INT_ADD_DOZE_SOURCE,
+               .type = SYSCOMMON_RESMAN_DATA_TYPE_INT,
+               .flag = SYSCOMMON_RESMAN_RESOURCE_FLAG_PUBLIC,
+               .ops = {
+                       .set = set_power_attr_data,
+                       .is_supported = syscommon_resman_resource_attr_supported_always,
+               },
+       }, {
+               .name = "DEVICED_POWER_ATTR_INT_REMOVE_DOZE_SOURCE",
+               .id = DEVICED_POWER_ATTR_INT_REMOVE_DOZE_SOURCE,
+               .type = SYSCOMMON_RESMAN_DATA_TYPE_INT,
+               .flag = SYSCOMMON_RESMAN_RESOURCE_FLAG_PUBLIC,
+               .ops = {
+                       .set = set_power_attr_data,
+                       .is_supported = syscommon_resman_resource_attr_supported_always,
+               },
        }
 };