power: Add setter for DEVICED_POWER_ATTR_INT_VITAL_MODE 40/301640/2
authorYoungjae Cho <y0.cho@samsung.com>
Thu, 12 Oct 2023 02:30:09 +0000 (11:30 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Tue, 21 Nov 2023 07:36:34 +0000 (16:36 +0900)
Instead of notitfying DEVICED_NOTIFIER_VITAL_STATE, it directly sets
power attribute DEVICED_POWER_ATTR_INT_VITAL_MODE to change vital state.

Change-Id: I9ab5ff6101f38fb3cba3be2606306b46e5d0dce6
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
plugins/mobile/display/key-filter.c
plugins/tv/display/key-filter.c
plugins/wearable/display/key-filter.c
src/display/display.c
src/power/power-suspend.c
src/power/power-suspend.h
src/power/resource-power.c

index 9d41af9..01f787a 100644 (file)
@@ -595,8 +595,6 @@ static void process_hardkey_backlight(struct input_event *pinput)
 
 static void update_vital_state(struct input_event *pinput)
 {
-       int type;
-
        /* Change vital state to  SYSCOMMON_DEVICED_VITAL_EXIT only if vital mode is active */
        if (!vital_mode())
                return;
@@ -605,8 +603,8 @@ static void update_vital_state(struct input_event *pinput)
        if (pinput->type == EV_ABS || (pinput->type == EV_KEY &&
            pinput->value == KEY_RELEASED && pinput->code == KEY_MENU)) {
                /* Enable all services upon receiving user input, else maintain same state */
-               type = SYSCOMMON_DEVICED_VITAL_EXIT;
-               syscommon_notifier_emit_notify(DEVICED_NOTIFIER_VITAL_STATE, &type);
+               syscommon_resman_set_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_POWER),
+                       DEVICED_POWER_ATTR_INT_VITAL_MODE, SYSCOMMON_DEVICED_VITAL_EXIT);
        }
 }
 
index 68cd570..0ec50c8 100644 (file)
@@ -563,8 +563,6 @@ static void process_hardkey_backlight(struct input_event *pinput)
 
 static void update_vital_state(struct input_event *pinput)
 {
-       int type;
-
        /* Change vital state to  SYSCOMMON_DEVICED_VITAL_EXIT only if vital mode is active */
        if (!vital_mode())
                return;
@@ -573,8 +571,8 @@ static void update_vital_state(struct input_event *pinput)
        if (pinput->type == EV_ABS || (pinput->type == EV_KEY &&
            pinput->value == KEY_RELEASED && pinput->code == KEY_MENU)) {
                /* Enable all services upon receiving user input, else maintain same state */
-               type = SYSCOMMON_DEVICED_VITAL_EXIT;
-               syscommon_notifier_emit_notify(DEVICED_NOTIFIER_VITAL_STATE, &type);
+               syscommon_resman_set_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_POWER),
+                       DEVICED_POWER_ATTR_INT_VITAL_MODE, SYSCOMMON_DEVICED_VITAL_EXIT);
        }
 }
 
index 294e80c..3f22780 100644 (file)
@@ -25,6 +25,7 @@
 #include <vconf.h>
 #include <sys/types.h>
 #include <libsyscommon/libgdbus.h>
+#include <libsyscommon/resource-manager.h>
 #include <libsyscommon/log.h>
 #include <system/syscommon-plugin-deviced-common-interface.h>
 #include <linux/input.h>
@@ -508,8 +509,6 @@ static int process_screenlock_key(struct input_event *pinput)
 
 static void update_vital_state(struct input_event *pinput)
 {
-       int type;
-
        /* Change vital state to  SYSCOMMON_DEVICED_VITAL_EXIT only if vital mode is active */
        if (!vital_mode())
                return;
@@ -518,8 +517,8 @@ static void update_vital_state(struct input_event *pinput)
        if (pinput->type == EV_ABS || (pinput->type == EV_KEY &&
            pinput->value == KEY_RELEASED && pinput->code == KEY_MENU)) {
                /* Enable all services upon receiving user input, else maintain same state */
-               type = SYSCOMMON_DEVICED_VITAL_EXIT;
-               syscommon_notifier_emit_notify(DEVICED_NOTIFIER_VITAL_STATE, &type);
+               syscommon_resman_set_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_POWER),
+                       DEVICED_POWER_ATTR_INT_VITAL_MODE, SYSCOMMON_DEVICED_VITAL_EXIT);
        }
 }
 
index 2e3c1a2..6e9c9b9 100644 (file)
@@ -584,8 +584,6 @@ static void display_init(void *data)
        if (timeout_enable)
                display_initialize_display_state_timeout_from_setting();
 
-       syscommon_notifier_subscribe_notify(DEVICED_NOTIFIER_VITAL_STATE, vital_state_changed);
-
        _I("input init");
        ret = input_init_handler();
        pm_lock_detector_init();
@@ -709,7 +707,6 @@ static void display_exit(void *data)
        if (!check_default(ops))
                ops->start(NORMAL_MODE);
 
-       syscommon_notifier_unsubscribe_notify(DEVICED_NOTIFIER_VITAL_STATE, vital_state_changed);
        syscommon_notifier_unsubscribe_notify(DEVICED_NOTIFIER_DELAYED_INIT, delayed_init_done);
        syscommon_notifier_unsubscribe_notify(DEVICED_NOTIFIER_APPLICATION_BACKGROUND, display_app_background);
        syscommon_notifier_unsubscribe_notify(DEVICED_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground);
index e95370e..b5f6b97 100644 (file)
@@ -241,14 +241,9 @@ int suspend_other_process(int type)
        return ret;
 }
 
-int vital_state_changed(void *data)
+int vital_state_changed(int mode)
 {
-       int type;
-
-       assert(data);
-
-       type = *(int *)data;
-       if (type == SYSCOMMON_DEVICED_VITAL_EXIT)
+       if (mode == SYSCOMMON_DEVICED_VITAL_EXIT)
                suspend_other_process(SYSCOMMON_DEVICED_VITAL_EXIT);
 
        return 0;
index 0bcbdc3..21cae16 100644 (file)
@@ -46,7 +46,7 @@ void pm_history_save(enum syscommon_deviced_power_log_type log_type, int code);
 void pm_history_print(int fd, int count);
 #endif
 bool vital_mode(void);
-int vital_state_changed(void *data);
+int vital_state_changed(int mode);
 int power_init_autosleep(void);
 int power_exit_autosleep(void);
 int power_acquire_wakelock(void);
index ad521f9..6b44cd2 100644 (file)
@@ -149,6 +149,27 @@ static int get_power_attr_data(int resource_id,
        return 0;
 }
 
+static int set_power_attr_data(int resource_id,
+       const struct syscommon_resman_resource_attribute *attr,
+       const void *data, int count)
+{
+       if (!data)
+               return -EINVAL;
+
+       switch (attr->id) {
+       case DEVICED_POWER_ATTR_INT_VITAL_MODE:
+               {
+                       int mode = *(const int *) data;
+                       vital_state_changed(mode);
+               }
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 /**
  * FIXME: After developing the power abstraction layer, this attribute should
  * be fixed. Because the suspend-to-ram supports both echo-mem and wakelock
@@ -237,6 +258,7 @@ static const struct syscommon_resman_resource_attribute power_attrs[] = {
                .flag = SYSCOMMON_RESMAN_RESOURCE_FLAG_PUBLIC,
                .ops = {
                        .get = get_power_attr_data,
+                       .set = set_power_attr_data,
                        .is_supported = syscommon_resman_resource_attr_supported_always,
                },
        }, {