From 2f68b9a15c55f8a3eac6546497995cbc51ad00c8 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Wed, 14 Jun 2023 20:08:52 +0900 Subject: [PATCH] display: Relocate display_on/off_by_reason() display_on/off_by_reason() is used by dbus_changestatebyreason call. 1. Set display on/off reason to the flag. 2. Check if it is possible to go to lcd_on/off procedure. If possible, go to the lcd on/off procedure. 3. After that, update current, before display state and do action about S_NORMAL/S_LCDOFF. For relocating these, the string of device operation declaration has also been moved to shared/devices.h There is no reason for the same string to exist in all plugins. New functions are added below display-panel. - int display_panel_display_turn_on_by_reason(const char *reason, int timeout); - int display_panel_display_turn_off_by_reason(const char *reason); -> These replace display_on/off_by_reason() Change-Id: Ia22ee6295fa138c3742be62c3bbc2c357716caf5 Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 88 +------------------------------- plugins/mobile/display/core.c | 88 +------------------------------- plugins/tv/display/core.c | 88 +------------------------------- plugins/wearable/display/core.c | 14 +---- src/display/core.h | 2 - src/display/display-panel.c | 80 +++++++++++++++++++++++++++++ src/display/display-panel.h | 2 + src/display/display-plugin.c | 20 ++++++++ src/display/display-plugin.h | 4 ++ src/display/plugin-common/display-dbus.c | 4 +- src/shared/devices.h | 12 +++++ 11 files changed, 128 insertions(+), 274 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 2a19bcc..486a973 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -80,15 +80,6 @@ #define LOCK_SCREEN_CONTROL_TIMEOUT 5000 -#define GESTURE_STR "gesture" -#define POWER_KEY_STR "powerkey" -#define TOUCH_STR "touch" -#define EVENT_STR "event" -#define TIMEOUT_STR "timeout" -#define PROXI_STR "proximity" -#define PALM_STR "palm" -#define UNKNOWN_STR "unknown" - extern void init_save_userlock(void); static struct display_plugin *disp_plgn; @@ -184,83 +175,6 @@ static const char* __device_flags_to_string(enum device_flags flags) return UNKNOWN_STR; } -int display_on_by_reason(const char *reason, int timeout) -{ - struct state *st; - int flag; - int str_len; - - str_len = strlen(reason); - - if (!strncmp(reason, GESTURE_STR, str_len)) - flag = LCD_ON_BY_GESTURE; - else if (!strncmp(reason, EVENT_STR, str_len)) - flag = LCD_ON_BY_EVENT; - else { - _E("Reason is unknown(%s)", reason); - return -EINVAL; - } - - if (timeout <= 0) { - _E("Cannot setting timeout %d", timeout); - return -EINVAL; - } - - if (display_panel_get_dpms_cached_state() != DPMS_ON) - display_panel_lcd_on_direct(flag); - - _I("platform lcd on by %s (%d ms)", reason, timeout); - if (set_custom_lcdon_timeout(timeout) == true) - display_state_transition_update_display_state_timeout_by_priority(); - - /* state transition */ - set_pm_old_state(get_pm_cur_state()); - set_pm_cur_state(S_NORMAL); - st = &states[get_pm_cur_state()]; - - display_state_transition_do_state_action(st->timeout); - - return 0; -} - -int display_off_by_reason(const char *reason) -{ - struct state *st; - int flag; - int str_len; - - str_len = strlen(reason); - - if (!strncmp(reason, GESTURE_STR, str_len)) { - if (display_lock_is_state_locked(S_NORMAL) || display_lock_is_state_locked(S_LCDDIM)) { - _I("skip platform lcd off by gesture"); - return -ECANCELED; - } - flag = LCD_OFF_BY_GESTURE; - } else if (!strncmp(reason, PALM_STR, str_len)) { - display_lock_release_lock_all(S_NORMAL); - display_lock_release_lock_all(S_LCDDIM); - - flag = LCD_OFF_BY_PALM; - } else { - _E("Reason is unknown(%s)", reason); - return -EINVAL; - } - - _I("platform lcd off by %s", reason); - if (display_panel_get_dpms_cached_state() == DPMS_ON) - display_panel_lcd_off_procedure(flag); - - /* state transition */ - set_pm_old_state(get_pm_cur_state()); - set_pm_cur_state(S_LCDOFF); - st = &states[get_pm_cur_state()]; - - display_state_transition_do_state_action(st->timeout); - - return 0; -} - static void default_proc_change_state_action(enum state_t next, int timeout) { struct state *st; @@ -860,6 +774,8 @@ static int display_probe(void *data) dp->lcd_off_procedure = NULL; dp->custom_lcd_on = NULL; dp->custom_lcd_off = NULL; + dp->display_on_by_reason = NULL; + dp->display_off_by_reason = NULL; setup_display_plugin_backlight_ops(dp); /* check display feature */ diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index e7cc52d..aaf075d 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -81,15 +81,6 @@ #define LOCK_SCREEN_CONTROL_TIMEOUT 5000 -#define GESTURE_STR "gesture" -#define POWER_KEY_STR "powerkey" -#define TOUCH_STR "touch" -#define EVENT_STR "event" -#define TIMEOUT_STR "timeout" -#define PROXI_STR "proximity" -#define PALM_STR "palm" -#define UNKNOWN_STR "unknown" - extern void init_save_userlock(void); static struct display_plugin *disp_plgn; @@ -191,83 +182,6 @@ static const char* __device_flags_to_string(enum device_flags flags) return UNKNOWN_STR; } -int display_on_by_reason(const char *reason, int timeout) -{ - struct state *st; - int flag; - int str_len; - - str_len = strlen(reason); - - if (!strncmp(reason, GESTURE_STR, str_len)) - flag = LCD_ON_BY_GESTURE; - else if (!strncmp(reason, EVENT_STR, str_len)) - flag = LCD_ON_BY_EVENT; - else { - _E("Reason is unknown(%s)", reason); - return -EINVAL; - } - - if (timeout <= 0) { - _E("Cannot setting timeout %d", timeout); - return -EINVAL; - } - - if (display_panel_get_dpms_cached_state() != DPMS_ON) - display_panel_lcd_on_direct(flag); - - _I("platform lcd on by %s (%d ms)", reason, timeout); - if (set_custom_lcdon_timeout(timeout) == true) - display_state_transition_update_display_state_timeout_by_priority(); - - /* state transition */ - set_pm_old_state(get_pm_cur_state()); - set_pm_cur_state(S_NORMAL); - st = &states[get_pm_cur_state()]; - - display_state_transition_do_state_action(st->timeout); - - return 0; -} - -int display_off_by_reason(const char *reason) -{ - struct state *st; - int flag; - int str_len; - - str_len = strlen(reason); - - if (!strncmp(reason, GESTURE_STR, str_len)) { - if (display_lock_is_state_locked(S_NORMAL) || display_lock_is_state_locked(S_LCDDIM)) { - _I("skip platform lcd off by gesture"); - return -ECANCELED; - } - flag = LCD_OFF_BY_GESTURE; - } else if (!strncmp(reason, PALM_STR, str_len)) { - display_lock_release_lock_all(S_NORMAL); - display_lock_release_lock_all(S_LCDDIM); - - flag = LCD_OFF_BY_PALM; - } else { - _E("Reason is unknown(%s)", reason); - return -EINVAL; - } - - _I("platform lcd off by %s", reason); - if (display_panel_get_dpms_cached_state() == DPMS_ON) - display_panel_lcd_off_procedure(flag); - - /* state transition */ - set_pm_old_state(get_pm_cur_state()); - set_pm_cur_state(S_LCDOFF); - st = &states[get_pm_cur_state()]; - - display_state_transition_do_state_action(st->timeout); - - return 0; -} - static void default_proc_change_state_action(enum state_t next, int timeout) { struct state *st; @@ -869,6 +783,8 @@ static int display_probe(void *data) dp->lcd_off_procedure = NULL; dp->custom_lcd_on = NULL; dp->custom_lcd_off = NULL; + dp->display_on_by_reason = NULL; + dp->display_off_by_reason = NULL; setup_display_plugin_backlight_ops(dp); /** diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 4630590..6a14386 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -79,15 +79,6 @@ #define LOCK_SCREEN_CONTROL_TIMEOUT 5000 -#define GESTURE_STR "gesture" -#define POWER_KEY_STR "powerkey" -#define TOUCH_STR "touch" -#define EVENT_STR "event" -#define TIMEOUT_STR "timeout" -#define PROXI_STR "proximity" -#define PALM_STR "palm" -#define UNKNOWN_STR "unknown" - extern void init_save_userlock(void); static struct display_plugin *disp_plgn; @@ -184,83 +175,6 @@ static const char* __device_flags_to_string(enum device_flags flags) return UNKNOWN_STR; } -int display_on_by_reason(const char *reason, int timeout) -{ - struct state *st; - int flag; - int str_len; - - str_len = strlen(reason); - - if (!strncmp(reason, GESTURE_STR, str_len)) - flag = LCD_ON_BY_GESTURE; - else if (!strncmp(reason, EVENT_STR, str_len)) - flag = LCD_ON_BY_EVENT; - else { - _E("Reason is unknown(%s)", reason); - return -EINVAL; - } - - if (timeout <= 0) { - _E("Cannot setting timeout %d", timeout); - return -EINVAL; - } - - if (display_panel_get_dpms_cached_state() != DPMS_ON) - display_panel_lcd_on_direct(flag); - - _I("platform lcd on by %s (%d ms)", reason, timeout); - if (set_custom_lcdon_timeout(timeout) == true) - display_state_transition_update_display_state_timeout_by_priority(); - - /* state transition */ - set_pm_old_state(get_pm_cur_state()); - set_pm_cur_state(S_NORMAL); - st = &states[get_pm_cur_state()]; - - display_state_transition_do_state_action(st->timeout); - - return 0; -} - -int display_off_by_reason(const char *reason) -{ - struct state *st; - int flag; - int str_len; - - str_len = strlen(reason); - - if (!strncmp(reason, GESTURE_STR, str_len)) { - if (display_lock_is_state_locked(S_NORMAL) || display_lock_is_state_locked(S_LCDDIM)) { - _I("skip platform lcd off by gesture"); - return -ECANCELED; - } - flag = LCD_OFF_BY_GESTURE; - } else if (!strncmp(reason, PALM_STR, str_len)) { - display_lock_release_lock_all(S_NORMAL); - display_lock_release_lock_all(S_LCDDIM); - - flag = LCD_OFF_BY_PALM; - } else { - _E("Reason is unknown(%s)", reason); - return -EINVAL; - } - - _I("platform lcd off by %s", reason); - if (display_panel_get_dpms_cached_state() == DPMS_ON) - display_panel_lcd_off_procedure(flag); - - /* state transition */ - set_pm_old_state(get_pm_cur_state()); - set_pm_cur_state(S_LCDOFF); - st = &states[get_pm_cur_state()]; - - display_state_transition_do_state_action(st->timeout); - - return 0; -} - static void default_proc_change_state_action(enum state_t next, int timeout) { struct state *st; @@ -860,6 +774,8 @@ static int display_probe(void *data) dp->lcd_off_procedure = NULL; dp->custom_lcd_on = NULL; dp->custom_lcd_off = NULL; + dp->display_on_by_reason = NULL; + dp->display_off_by_reason = NULL; setup_display_plugin_backlight_ops(dp); /** diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index dcf753d..fd0d559 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -88,18 +88,6 @@ #define LOCK_SCREEN_CONTROL_TIMEOUT 5000 #define LATE_LCD_TRANSIT 1 -#define GESTURE_STR "gesture" -#define POWER_KEY_STR "powerkey" -#define BACK_KEY_STR "backkey" -#define TOUCH_STR "touch" -#define EVENT_STR "event" -#define BEZEL_STR "bezel" -#define TIMEOUT_STR "timeout" -#define PROXI_STR "proximity" -#define PALM_STR "palm" -#define DISPLAY_DETACH_STR "display_detach" -#define UNKNOWN_STR "unknown" - extern void init_save_userlock(void); static struct display_plugin *disp_plgn; @@ -1404,6 +1392,8 @@ static int display_probe(void *data) dp->lcd_off_procedure = lcd_off_procedure; dp->custom_lcd_on = custom_lcdon; dp->custom_lcd_off = custom_lcdoff; + dp->display_on_by_reason = display_on_by_reason; + dp->display_off_by_reason = display_off_by_reason; setup_display_plugin_backlight_ops(dp); /** diff --git a/src/display/core.h b/src/display/core.h index bdb9726..cb6ef6a 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -120,8 +120,6 @@ void set_lock_screen_bg_state(bool state); /* core.c */ int delete_condition(enum state_t state); int custom_lcdoff(enum device_flags flag); -int display_on_by_reason(const char *reason, int timeout); -int display_off_by_reason(const char *reason); int set_lcd_timeout(int on, int dim, const char *name); void broadcast_lcd_off_late(enum device_flags flags); diff --git a/src/display/display-panel.c b/src/display/display-panel.c index ffed685..fbc615e 100644 --- a/src/display/display-panel.c +++ b/src/display/display-panel.c @@ -405,6 +405,86 @@ int display_panel_custom_lcd_off(enum device_flags flag) return 0; } +/** FIXME: handling method should be considered later, + * because the handling is too similar for the same lcd on/off procedure, display state transition. +*/ +int display_panel_display_turn_on_by_reason(const char *reason, int timeout) +{ + int flag; + int str_len; + + if (dipslay_plugin_display_on_by_reason(reason, timeout) == 0) + return 0; + + if (!reason) + return -EINVAL; + + str_len = strlen(reason); + + if (!strncmp(reason, GESTURE_STR, str_len)) { + flag = LCD_ON_BY_GESTURE; + } else if (!strncmp(reason, EVENT_STR, str_len)) { + flag = LCD_ON_BY_EVENT; + } else { + _E("Reason is unknown(%s)", reason); + return -EINVAL; + } + + if (timeout <= 0) { + _E("Cannot setting timeout %d", timeout); + return -EINVAL; + } + + if (display_panel_get_dpms_cached_state() != DPMS_ON) + display_panel_lcd_on_direct(flag); + + _I("platform lcd on by %s (%d ms)", reason, timeout); + if (set_custom_lcdon_timeout(timeout) == true) + display_state_transition_update_display_state_timeout_by_priority(); + + display_state_updated_to_next_and_do_action(S_NORMAL); + + return 0; +} + +int display_panel_display_turn_off_by_reason(const char *reason) +{ + int flag; + int str_len; + + if (display_plugin_display_off_by_reason(reason) == 0) + return 0; + + if (!reason) + return -EINVAL; + + str_len = strlen(reason); + + if (!strncmp(reason, GESTURE_STR, str_len)) { + if (display_lock_is_state_locked(S_NORMAL) || display_lock_is_state_locked(S_LCDDIM)) { + _I("skip platform lcd off by gesture"); + return -ECANCELED; + } + flag = LCD_OFF_BY_GESTURE; + } else if (!strncmp(reason, PALM_STR, str_len)) { + display_lock_release_lock_all(S_NORMAL); + display_lock_release_lock_all(S_LCDDIM); + + flag = LCD_OFF_BY_PALM; + } else { + _E("Reason is unknown(%s)", reason); + return -EINVAL; + } + + _I("platform lcd off by %s", reason); + if (display_panel_get_dpms_cached_state() == DPMS_ON) + display_panel_lcd_off_procedure(flag); + + display_state_updated_to_next_and_do_action(S_LCDOFF); + + return 0; +} + bool display_panel_is_lcd_on_state_broadcasted(void) { return lcd_on_broadcasted; diff --git a/src/display/display-panel.h b/src/display/display-panel.h index 4b39c72..1cee8c7 100644 --- a/src/display/display-panel.h +++ b/src/display/display-panel.h @@ -37,6 +37,8 @@ void display_panel_lcd_off_procedure(enum device_flags flag); void display_panel_lcd_on_direct(enum device_flags flags); int display_panel_custom_lcd_on(int timeout); int display_panel_custom_lcd_off(enum device_flags flag); +int display_panel_display_turn_on_by_reason(const char *reason, int timeout); +int display_panel_display_turn_off_by_reason(const char *reason); bool display_panel_is_lcd_on_state_broadcasted(void); void display_panel_update_lcd_on_timeval(void); int display_panel_calculate_diff_time_between_lcd_on_direct_and_state_action(int *diff_time); diff --git a/src/display/display-plugin.c b/src/display/display-plugin.c index 8ed7335..5ce4b5e 100644 --- a/src/display/display-plugin.c +++ b/src/display/display-plugin.c @@ -139,6 +139,26 @@ int display_plugin_custom_lcd_off(enum device_flags flag) return -EOPNOTSUPP; } +int dipslay_plugin_display_on_by_reason(const char *reason, int timeout) +{ + if (g_display_plugin.display_on_by_reason) { + g_display_plugin.display_on_by_reason(reason, timeout); + return 0; + } + + return -EOPNOTSUPP; +} + +int display_plugin_display_off_by_reason(const char *reason) +{ + if (g_display_plugin.display_off_by_reason) { + g_display_plugin.display_off_by_reason(reason); + return 0; + } + + return -EOPNOTSUPP; +} + int display_plugin_backlight_get_lcd_power(void) { if (g_display_plugin.backlight && g_display_plugin.backlight->get_lcd_power) diff --git a/src/display/display-plugin.h b/src/display/display-plugin.h index 73e69b3..95470d0 100644 --- a/src/display/display-plugin.h +++ b/src/display/display-plugin.h @@ -71,6 +71,8 @@ struct display_plugin { void (*lcd_off_procedure) (enum device_flags flag); int (*custom_lcd_on) (int timeout); int (*custom_lcd_off) (enum device_flags flag); + int (*display_on_by_reason) (const char *reason, int timeout); + int (*display_off_by_reason) (const char *reason); struct display_config *config; struct display_backlight_ops *backlight; @@ -94,6 +96,8 @@ int display_plugin_lcd_on_procedure(int state, enum device_flags flag); int display_plugin_lcd_off_procedure(enum device_flags flag); int display_plugin_custom_lcd_on(int timeout); int display_plugin_custom_lcd_off(enum device_flags flag); +int dipslay_plugin_display_on_by_reason(const char *reason, int timeout); +int display_plugin_display_off_by_reason(const char *reason); int display_plugin_backlight_get_lcd_power(void); int display_plugin_backlight_set_brightness(int brightness); diff --git a/src/display/plugin-common/display-dbus.c b/src/display/plugin-common/display-dbus.c index 76c3b5c..4f58cf1 100644 --- a/src/display/plugin-common/display-dbus.c +++ b/src/display/plugin-common/display-dbus.c @@ -889,10 +889,10 @@ static GVariant *dbus_changestatebyreason(GDBusConnection *conn, if (next_state == DISPLAY_STATE_NORMAL) { state = "S_LCDON"; - ret = display_on_by_reason(reason, timeout); + ret = display_panel_display_turn_on_by_reason(reason, timeout); } else if (next_state == DISPLAY_STATE_SCREEN_OFF) { state = "S_LCDOFF"; - ret = display_off_by_reason(reason); + ret = display_panel_display_turn_off_by_reason(reason); } else if (next_state == DISPLAY_STATE_SCREEN_DIM) { state = "S_LCDDIM"; ret = -EINVAL; diff --git a/src/shared/devices.h b/src/shared/devices.h index b0feb6a..eb99835 100644 --- a/src/shared/devices.h +++ b/src/shared/devices.h @@ -28,6 +28,18 @@ #define DEVICE_PRIORITY_NORMAL 0 #define DEVICE_PRIORITY_HIGH 1 +#define GESTURE_STR "gesture" +#define POWER_KEY_STR "powerkey" +#define BACK_KEY_STR "backkey" +#define TOUCH_STR "touch" +#define EVENT_STR "event" +#define BEZEL_STR "bezel" +#define TIMEOUT_STR "timeout" +#define PROXI_STR "proximity" +#define PALM_STR "palm" +#define DISPLAY_DETACH_STR "display_detach" +#define UNKNOWN_STR "unknown" + enum device_flags { NORMAL_MODE = 0x00000001, AMBIENT_MODE = 0x00000002, -- 2.7.4