display: Add display attribute representing current state 07/297107/2
authorYoungjae Cho <y0.cho@samsung.com>
Wed, 9 Aug 2023 11:22:00 +0000 (20:22 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Mon, 14 Aug 2023 04:17:37 +0000 (13:17 +0900)
New attribute:
 - id: DEVICED_DISPLAY_ATTR_INT_GET_CURRENT_STATE
 - type: SYSCOMMON_RESMAN_DATA_TYPE_INT
 - setter: X
 - getter: O

Plugins and other core modules has replaced get_pm_cur_state()
with resource-manager API that accessing the attribute.

Change-Id: Iacb01f00c6909f313d32575f424646a8b4de3a96
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
plugins/iot-headed/display/key-filter.c
plugins/mobile/display/key-filter.c
plugins/tv/display/key-filter.c
src/display/resource-display.c

index c32723b..5248142 100644 (file)
@@ -25,7 +25,9 @@
 #include <vconf.h>
 #include <sys/types.h>
 #include <libsyscommon/libgdbus.h>
+#include <libsyscommon/resource-manager.h>
 #include <system/syscommon-plugin-deviced-common-interface.h>
+#include <system/syscommon-plugin-deviced-display-interface.h>
 #include <linux/input.h>
 
 #include "ambient-mode.h"
@@ -104,15 +106,30 @@ static int booting_check = true;
 
 static inline int current_state_in_on(void)
 {
-       return ((get_pm_cur_state() == DEVICED_DISPLAY_STATE_DIM) || (get_pm_cur_state() == DEVICED_DISPLAY_STATE_ON));
+       int ret;
+       enum deviced_display_state current;
+
+       ret = syscommon_resman_get_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
+               DEVICED_DISPLAY_ATTR_INT_GET_CURRENT_STATE, (int32_t *) &current);
+       if (ret < 0)
+               return 0;
+
+       return ((current == DEVICED_DISPLAY_STATE_DIM) || (current == DEVICED_DISPLAY_STATE_ON));
 }
 
 static inline void restore_custom_brightness(void)
 {
        bool custom_status;
+       int ret;
+       enum deviced_display_state current;
+
+       ret = syscommon_resman_get_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
+               DEVICED_DISPLAY_ATTR_INT_GET_CURRENT_STATE, (int32_t *) &current);
+       if (ret < 0)
+               return;
 
        display_backlight_get_custom_status(&custom_status);
-       if ((get_pm_cur_state() == DEVICED_DISPLAY_STATE_DIM) && custom_status)
+       if (current == DEVICED_DISPLAY_STATE_DIM && custom_status)
                display_backlight_update_by_custom_brightness();
 }
 
@@ -639,6 +656,8 @@ static void check_key_filter(struct timeval time, unsigned short type, unsigned
        };
        int ignore = true;
        static int code, value;
+       int ret;
+       enum deviced_display_state current;
 
        assert(pinput);
 
@@ -673,10 +692,15 @@ static void check_key_filter(struct timeval time, unsigned short type, unsigned
 
                break;
        case EV_REL:
-               if ((get_pm_cur_state() == DEVICED_DISPLAY_STATE_OFF) && bezel_wakeup) {
+               ret = syscommon_resman_get_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
+                       DEVICED_DISPLAY_ATTR_INT_GET_CURRENT_STATE, (int32_t *) &current);
+               if (ret < 0)
+                       break;
+
+               if (current == DEVICED_DISPLAY_STATE_OFF && bezel_wakeup) {
                        switch_on_lcd(LCD_ON_BY_BEZEL);
                        ignore = false;
-               } else if (get_pm_cur_state() != DEVICED_DISPLAY_STATE_OFF)
+               } else if (current != DEVICED_DISPLAY_STATE_OFF)
                        ignore = false;
                break;
        case EV_ABS:
index 95abf08..3530cf5 100644 (file)
@@ -25,7 +25,9 @@
 #include <vconf.h>
 #include <sys/types.h>
 #include <libsyscommon/libgdbus.h>
+#include <libsyscommon/resource-manager.h>
 #include <system/syscommon-plugin-deviced-common-interface.h>
+#include <system/syscommon-plugin-deviced-display-interface.h>
 #include <linux/input.h>
 
 #include "ambient-mode.h"
@@ -105,15 +107,30 @@ static int booting_check = true;
 
 static inline int current_state_in_on(void)
 {
-       return ((get_pm_cur_state() == DEVICED_DISPLAY_STATE_DIM) || (get_pm_cur_state() == DEVICED_DISPLAY_STATE_ON));
+       int ret;
+       enum deviced_display_state current;
+
+       ret = syscommon_resman_get_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
+               DEVICED_DISPLAY_ATTR_INT_GET_CURRENT_STATE, (int32_t *) &current);
+       if (ret < 0)
+               return 0;
+
+       return ((current == DEVICED_DISPLAY_STATE_DIM) || (current == DEVICED_DISPLAY_STATE_ON));
 }
 
 static inline void restore_custom_brightness(void)
 {
        bool custom_status;
+       int ret;
+       enum deviced_display_state current;
+
+       ret = syscommon_resman_get_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
+               DEVICED_DISPLAY_ATTR_INT_GET_CURRENT_STATE, (int32_t *) &current);
+       if (ret < 0)
+               return;
 
        display_backlight_get_custom_status(&custom_status);
-       if ((get_pm_cur_state() == DEVICED_DISPLAY_STATE_DIM) && custom_status)
+       if (current == DEVICED_DISPLAY_STATE_DIM && custom_status)
                display_backlight_update_by_custom_brightness();
 }
 
@@ -671,6 +688,8 @@ static void check_key_filter(struct timeval time, unsigned short type, unsigned
        };
        int ignore = true;
        static int code, value;
+       int ret;
+       enum deviced_display_state current;
 
        assert(pinput);
 
@@ -699,10 +718,15 @@ static void check_key_filter(struct timeval time, unsigned short type, unsigned
 
                break;
        case EV_REL:
-               if ((get_pm_cur_state() == DEVICED_DISPLAY_STATE_OFF) && bezel_wakeup) {
+               ret = syscommon_resman_get_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
+                       DEVICED_DISPLAY_ATTR_INT_GET_CURRENT_STATE, (int32_t *) &current);
+               if (ret < 0)
+                       break;
+
+               if (current == DEVICED_DISPLAY_STATE_OFF && bezel_wakeup) {
                        switch_on_lcd(LCD_ON_BY_BEZEL);
                        ignore = false;
-               } else if (get_pm_cur_state() != DEVICED_DISPLAY_STATE_OFF)
+               } else if (current != DEVICED_DISPLAY_STATE_OFF)
                        ignore = false;
                break;
        case EV_ABS:
index c21f628..7708ff3 100644 (file)
@@ -25,7 +25,9 @@
 #include <vconf.h>
 #include <sys/types.h>
 #include <libsyscommon/libgdbus.h>
+#include <libsyscommon/resource-manager.h>
 #include <system/syscommon-plugin-deviced-common-interface.h>
+#include <system/syscommon-plugin-deviced-display-interface.h>
 #include <linux/input.h>
 
 #include "ambient-mode.h"
@@ -103,15 +105,30 @@ static int booting_check = true;
 
 static inline int current_state_in_on(void)
 {
-       return ((get_pm_cur_state() == DEVICED_DISPLAY_STATE_DIM) || (get_pm_cur_state() == DEVICED_DISPLAY_STATE_ON));
+       int ret;
+       enum deviced_display_state current;
+
+       ret = syscommon_resman_get_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
+               DEVICED_DISPLAY_ATTR_INT_GET_CURRENT_STATE, (int32_t *) &current);
+       if (ret < 0)
+               return 0;
+
+       return ((current == DEVICED_DISPLAY_STATE_DIM) || (current == DEVICED_DISPLAY_STATE_ON));
 }
 
 static inline void restore_custom_brightness(void)
 {
        bool custom_status;
+       int ret;
+       enum deviced_display_state current;
+
+       ret = syscommon_resman_get_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
+               DEVICED_DISPLAY_ATTR_INT_GET_CURRENT_STATE, (int32_t *) &current);
+       if (ret < 0)
+               return;
 
        display_backlight_get_custom_status(&custom_status);
-       if ((get_pm_cur_state() == DEVICED_DISPLAY_STATE_DIM) && custom_status)
+       if (current == DEVICED_DISPLAY_STATE_DIM && custom_status)
                display_backlight_update_by_custom_brightness();
 }
 
@@ -638,6 +655,8 @@ static void check_key_filter(struct timeval time, unsigned short type, unsigned
        };
        int ignore = true;
        static int code, value;
+       int ret;
+       enum deviced_display_state current;
 
        assert(pinput);
 
@@ -666,10 +685,15 @@ static void check_key_filter(struct timeval time, unsigned short type, unsigned
 
                break;
        case EV_REL:
-               if ((get_pm_cur_state() == DEVICED_DISPLAY_STATE_OFF) && bezel_wakeup) {
+               ret = syscommon_resman_get_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
+                       DEVICED_DISPLAY_ATTR_INT_GET_CURRENT_STATE, (int32_t *) &current);
+               if (ret < 0)
+                       break;
+
+               if (current == DEVICED_DISPLAY_STATE_OFF && bezel_wakeup) {
                        switch_on_lcd(LCD_ON_BY_BEZEL);
                        ignore = false;
-               } else if (get_pm_cur_state() != DEVICED_DISPLAY_STATE_OFF)
+               } else if (current != DEVICED_DISPLAY_STATE_OFF)
                        ignore = false;
                break;
        case EV_ABS:
index 34c268c..c5c3265 100644 (file)
 #include "display-state-transition.h"
 #include "display-backlight.h"
 
-static int get_max_brightness(int resource_id,
+typedef union {
+       int32_t i32;
+       int64_t i64;
+       uint32_t u32;
+       uint64_t u64;
+       double d;
+       void* p;
+       bool b;
+} resource_attr_data_t;
+
+static int get_display_attr_data(int resource_id,
        const struct syscommon_resman_resource_attribute *attr, void *data)
 {
-       int brightness = 0;
        int ret = 0;
+       resource_attr_data_t attr_data = { 0, };
 
        if (!data)
                return -EINVAL;
 
-       ret = display_backlight_get_max_brightness(&brightness);
+       switch (attr->id) {
+       case DEVICED_DISPLAY_ATTR_INT_GET_MAX_BRIGHTNESS:
+               ret = display_backlight_get_max_brightness(&attr_data.i32);
+               break;
+       case DEVICED_DISPLAY_ATTR_INT_GET_CURRENT_STATE:
+               ret = display_state_get_current((enum deviced_display_state *) &attr_data.i32);
+               break;
+       default:
+               ret = -EINVAL;
+               break;
+       }
+
        if (ret < 0)
                return ret;
 
-       *(int *) data = brightness;
+       switch (attr->type) {
+       case SYSCOMMON_RESMAN_DATA_TYPE_INT:
+               *(int32_t *) data = attr_data.i32;
+               break;
+       case SYSCOMMON_RESMAN_DATA_TYPE_INT64:
+               *(int64_t *) data = attr_data.i64;
+               break;
+       case SYSCOMMON_RESMAN_DATA_TYPE_UINT:
+               *(uint32_t *) data = attr_data.u32;
+               break;
+       case SYSCOMMON_RESMAN_DATA_TYPE_UINT64:
+               *(uint64_t *) data = attr_data.u64;
+               break;
+       case SYSCOMMON_RESMAN_DATA_TYPE_DOUBLE:
+               *(double *) data = attr_data.d;
+               break;
+       case SYSCOMMON_RESMAN_DATA_TYPE_PTR:
+               *(void **) data = attr_data.p;
+               break;
+       case SYSCOMMON_RESMAN_DATA_TYPE_BOOLEAN:
+               *(bool *) data = attr_data.b;
+               break;
+       default:
+               return -EINVAL;
+       }
 
        return 0;
 }
@@ -53,8 +98,17 @@ static const struct syscommon_resman_resource_attribute display_attrs[] = {
                .type = SYSCOMMON_RESMAN_DATA_TYPE_INT,
                .flag = SYSCOMMON_RESMAN_RESOURCE_FLAG_PUBLIC,
                .ops = {
-                       .get = get_max_brightness,
-                       .is_supported = syscommon_resman_resource_attr_supported_always
+                       .get = get_display_attr_data,
+                       .is_supported = syscommon_resman_resource_attr_supported_always,
+               },
+       }, {
+               .name = "DEVICED_DISPLAY_ATTR_INT_GET_CURRENT_STATE",
+               .id = DEVICED_DISPLAY_ATTR_INT_GET_CURRENT_STATE,
+               .type = SYSCOMMON_RESMAN_DATA_TYPE_INT,
+               .flag = SYSCOMMON_RESMAN_RESOURCE_FLAG_PUBLIC,
+               .ops = {
+                       .get = get_display_attr_data,
+                       .is_supported = syscommon_resman_resource_attr_supported_always,
                },
        },
 };