From c1a1bb7351084c7cf1331774f5ae54d6ad6d2c1a Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Thu, 8 Jun 2023 15:33:16 +0900 Subject: [PATCH 01/16] display: state-transition: Add break statement Add missing break statement for code improvement, It is reported by svace/coverity code analysis. Change-Id: If73d9b09de7cd6f2885be38938a80213c62e4c53 Signed-off-by: Yunhee Seo --- src/display/display-state-transition.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/display/display-state-transition.c b/src/display/display-state-transition.c index 002f838..126d77b 100644 --- a/src/display/display-state-transition.c +++ b/src/display/display-state-transition.c @@ -131,8 +131,10 @@ int display_state_transition_set_custom_timeout(enum state_t state, unsigned int switch (state) { case S_NORMAL: custom_normal_timeout = timeout; + break; case S_LCDDIM: custom_dim_timeout = timeout; + break; default: display_plugin_state_get_name(state, &state_name); _W("%s state has no custom timeout", state_name); @@ -151,8 +153,10 @@ int display_state_transition_get_custom_timeout(enum state_t state, unsigned int switch (state) { case S_NORMAL: *timeout = custom_normal_timeout; + break; case S_LCDDIM: *timeout = custom_dim_timeout; + break; default: *timeout = 0; display_plugin_state_get_name(state, &state_name); -- 2.7.4 From 4b06e6d1a7b7359869425567d4b5dbfbcb8521d5 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Thu, 8 Jun 2023 17:16:47 +0900 Subject: [PATCH 02/16] display: Remove unused macros There are many macros that have not been deleted when certain functions or codes are deleted before. Thus, remove unsed macros in the display plugins. Change-Id: I9a4e2b3b03082bae9fe57021281886651a107444 Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 10 ---------- plugins/iot-headed/display/device-interface.c | 18 ------------------ plugins/iot-headed/display/key-filter.c | 11 ----------- plugins/mobile/display/core.c | 10 ---------- plugins/mobile/display/device-interface.c | 16 ---------------- plugins/mobile/display/key-filter.c | 10 ---------- plugins/tv/display/core.c | 10 ---------- plugins/tv/display/device-interface.c | 18 ------------------ plugins/tv/display/key-filter.c | 11 ----------- plugins/wearable/display/core.c | 10 ---------- plugins/wearable/display/device-interface.c | 20 -------------------- plugins/wearable/display/key-filter.c | 10 ---------- src/display/plugin-common/auto-brightness.c | 13 ------------- src/display/plugin-common/display-dbus.c | 5 ----- src/display/plugin-common/poll.c | 8 -------- 15 files changed, 180 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index a0f1c85..fcbafea 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -127,18 +127,8 @@ static struct state states[S_END] = { { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, }; -#define SHIFT_UNLOCK 4 -#define SHIFT_CHANGE_STATE 7 -#define CHANGE_STATE_BIT 0xF00 /* 1111 0000 0000 */ -#define SHIFT_LOCK_FLAG 16 -#define SHIFT_CHANGE_TIMEOUT 20 -#define CUSTOM_TIMEOUT_BIT 0x1 -#define CUSTOM_HOLDKEY_BIT 0x2 -#define HOLD_KEY_BLOCK_BIT 0x1 #define TIMEOUT_NONE (-1) -#define S_COVER_TIMEOUT 8000 -#define GET_HOLDKEY_BLOCK_STATE(x) ((x >> SHIFT_LOCK_FLAG) & HOLD_KEY_BLOCK_BIT) #define DELAYED_INIT_WATING_TIME 60000 /* 1 minute */ #define LOCK_SCREEN_WATING_TIME 300 /* 0.3 second */ diff --git a/plugins/iot-headed/display/device-interface.c b/plugins/iot-headed/display/device-interface.c index 95a4e79..245b5d0 100644 --- a/plugins/iot-headed/display/device-interface.c +++ b/plugins/iot-headed/display/device-interface.c @@ -46,24 +46,6 @@ #include "display-backlight.h" #include "display-panel.h" -#define TOUCH_ON 1 -#define TOUCH_OFF 0 - -#define LCD_PHASED_MAX_BRIGHTNESS 100 - -#define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" - -#define GESTURE_STR "gesture" -#define POWERKEY_STR "powerkey" -#define EVENT_STR "event" -#define TOUCH_STR "touch" -#define TIMEOUT_STR "timeout" -#define PROXIMITY_STR "proximity" -#define PALM_STR "palm" -#define UNKNOWN_STR "unknown" - -#define FREEZER_VITAL_WAKEUP_CGROUP "/sys/fs/cgroup/freezer/vital_wakeup/freezer.state" - static struct display_backlight_ops backlight_ops; static bool display_dev_available = false; static const struct display_config *display_conf; diff --git a/plugins/iot-headed/display/key-filter.c b/plugins/iot-headed/display/key-filter.c index 35a18b3..b8ef405 100644 --- a/plugins/iot-headed/display/key-filter.c +++ b/plugins/iot-headed/display/key-filter.c @@ -56,11 +56,7 @@ #define SW_GLOVE 0x16 #endif -#define PREDEF_LEAVESLEEP "leavesleep" -#define POWEROFF_ACT "poweroff" -#define PWROFF_POPUP_ACT "pwroff_popup" #define USEC_PER_SEC 1000000 -#define CSC_CONFIG_MODE_RUNNING 1 #define CAPTURE_COMBINATION_INTERVAL 0.5 /* 0.5 second */ #define TORCH_COMBINATION_INTERVAL 0.1 /* 0.1 second */ @@ -68,17 +64,10 @@ #define LONGKEY_PRESSED_TIME 4 /* 4 second */ -#define KEY_MAX_DELAY_TIME 700 /* ms */ - #define SIGNAL_CHANGE_HARDKEY "ChangeHardkey" #define SIGNAL_LCDON_BY_POWERKEY "LCDOnByPowerkey" #define SIGNAL_LCDOFF_BY_POWERKEY "LCDOffByPowerkey" -#define NORMAL_POWER 0 -#define KEY_TEST_MODE_POWER 2 - -#define GLOVE_MODE 1 - enum key_combination_flags { KEY_COMBINATION_STOP = 0, KEY_COMBINATION_POWERKEY = BIT(0), diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index fda90ef..9545fac 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -129,18 +129,8 @@ static struct state states[S_END] = { { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, }; -#define SHIFT_UNLOCK 4 -#define SHIFT_CHANGE_STATE 7 -#define CHANGE_STATE_BIT 0xF00 /* 1111 0000 0000 */ -#define SHIFT_LOCK_FLAG 16 -#define SHIFT_CHANGE_TIMEOUT 20 -#define CUSTOM_TIMEOUT_BIT 0x1 -#define CUSTOM_HOLDKEY_BIT 0x2 -#define HOLD_KEY_BLOCK_BIT 0x1 #define TIMEOUT_NONE (-1) -#define S_COVER_TIMEOUT 8000 -#define GET_HOLDKEY_BLOCK_STATE(x) ((x >> SHIFT_LOCK_FLAG) & HOLD_KEY_BLOCK_BIT) #define DELAYED_INIT_WATING_TIME 60000 /* 1 minute */ #define LOCK_SCREEN_WATING_TIME 300 /* 0.3 second */ diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index aa1bc85..7900c9e 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -47,22 +47,6 @@ #include "power/power-boot.h" #include "power/power-suspend.h" -#define TOUCH_ON 1 -#define TOUCH_OFF 0 - -#define LCD_PHASED_MAX_BRIGHTNESS 100 - -#define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" - -#define GESTURE_STR "gesture" -#define POWERKEY_STR "powerkey" -#define EVENT_STR "event" -#define TOUCH_STR "touch" -#define TIMEOUT_STR "timeout" -#define PROXIMITY_STR "proximity" -#define PALM_STR "palm" -#define UNKNOWN_STR "unknown" - static struct display_backlight_ops backlight_ops; static bool display_dev_available = false; static const struct display_config *display_conf; diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index e05a94b..180262d 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -56,11 +56,8 @@ #define SW_GLOVE 0x16 #endif -#define PREDEF_LEAVESLEEP "leavesleep" -#define POWEROFF_ACT "poweroff" #define USEC_PER_SEC 1000000 #define USEC_PER_MSEC 1000 -#define CSC_CONFIG_MODE_RUNNING 1 #define CAPTURE_COMBINATION_INTERVAL 0.5 /* 0.5 second */ #define TORCH_COMBINATION_INTERVAL 0.1 /* 0.1 second */ @@ -68,17 +65,10 @@ #define LONGKEY_PRESSED_TIME 4 /* 4 second */ -#define KEY_MAX_DELAY_TIME 700 /* ms */ - #define SIGNAL_CHANGE_HARDKEY "ChangeHardkey" #define SIGNAL_LCDON_BY_POWERKEY "LCDOnByPowerkey" #define SIGNAL_LCDOFF_BY_POWERKEY "LCDOffByPowerkey" -#define NORMAL_POWER 0 -#define KEY_TEST_MODE_POWER 2 - -#define GLOVE_MODE 1 - enum key_combination_flags { KEY_COMBINATION_STOP = 0, KEY_COMBINATION_POWERKEY = BIT(0), diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 1d735d0..49e70e3 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -127,18 +127,8 @@ static struct state states[S_END] = { { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, }; -#define SHIFT_UNLOCK 4 -#define SHIFT_CHANGE_STATE 7 -#define CHANGE_STATE_BIT 0xF00 /* 1111 0000 0000 */ -#define SHIFT_LOCK_FLAG 16 -#define SHIFT_CHANGE_TIMEOUT 20 -#define CUSTOM_TIMEOUT_BIT 0x1 -#define CUSTOM_HOLDKEY_BIT 0x2 -#define HOLD_KEY_BLOCK_BIT 0x1 #define TIMEOUT_NONE (-1) -#define S_COVER_TIMEOUT 8000 -#define GET_HOLDKEY_BLOCK_STATE(x) ((x >> SHIFT_LOCK_FLAG) & HOLD_KEY_BLOCK_BIT) #define DELAYED_INIT_WATING_TIME 60000 /* 1 minute */ #define LOCK_SCREEN_WATING_TIME 300 /* 0.3 second */ diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index c9d13b7..4fc311b 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -46,24 +46,6 @@ #include "power/power-suspend.h" #include "display-lock.h" -#define TOUCH_ON 1 -#define TOUCH_OFF 0 - -#define LCD_PHASED_MAX_BRIGHTNESS 100 - -#define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" - -#define GESTURE_STR "gesture" -#define POWERKEY_STR "powerkey" -#define EVENT_STR "event" -#define TOUCH_STR "touch" -#define TIMEOUT_STR "timeout" -#define PROXIMITY_STR "proximity" -#define PALM_STR "palm" -#define UNKNOWN_STR "unknown" - -#define FREEZER_VITAL_WAKEUP_CGROUP "/sys/fs/cgroup/freezer/vital_wakeup/freezer.state" - static struct display_backlight_ops backlight_ops; static bool display_dev_available = false; static const struct display_config *display_conf; diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index 424e4a1..64628d6 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -56,11 +56,7 @@ #define SW_GLOVE 0x16 #endif -#define PREDEF_LEAVESLEEP "leavesleep" -#define POWEROFF_ACT "poweroff" -#define PWROFF_POPUP_ACT "pwroff_popup" #define USEC_PER_SEC 1000000 -#define CSC_CONFIG_MODE_RUNNING 1 #define CAPTURE_COMBINATION_INTERVAL 0.5 /* 0.5 second */ #define TORCH_COMBINATION_INTERVAL 0.1 /* 0.1 second */ @@ -68,17 +64,10 @@ #define LONGKEY_PRESSED_TIME 4 /* 4 second */ -#define KEY_MAX_DELAY_TIME 700 /* ms */ - #define SIGNAL_CHANGE_HARDKEY "ChangeHardkey" #define SIGNAL_LCDON_BY_POWERKEY "LCDOnByPowerkey" #define SIGNAL_LCDOFF_BY_POWERKEY "LCDOffByPowerkey" -#define NORMAL_POWER 0 -#define KEY_TEST_MODE_POWER 2 - -#define GLOVE_MODE 1 - enum key_combination_flags { KEY_COMBINATION_STOP = 0, KEY_COMBINATION_POWERKEY = BIT(0), diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 2c6d570..b0a7d33 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -140,18 +140,8 @@ static struct state states[S_END] = { { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, }; -#define SHIFT_UNLOCK 4 -#define SHIFT_CHANGE_STATE 7 -#define CHANGE_STATE_BIT 0xF00 /* 1111 0000 0000 */ -#define SHIFT_LOCK_FLAG 16 -#define SHIFT_CHANGE_TIMEOUT 20 -#define CUSTOM_TIMEOUT_BIT 0x1 -#define CUSTOM_HOLDKEY_BIT 0x2 -#define HOLD_KEY_BLOCK_BIT 0x1 #define TIMEOUT_NONE (-1) -#define S_COVER_TIMEOUT 8000 -#define GET_HOLDKEY_BLOCK_STATE(x) ((x >> SHIFT_LOCK_FLAG) & HOLD_KEY_BLOCK_BIT) #define DELAYED_INIT_WATING_TIME 60000 /* 1 minute */ #define LOCK_SCREEN_WATING_TIME 300 /* 0.3 second */ diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 2e06e43..018cfe5 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -50,26 +50,6 @@ #include "power/power-suspend.h" #include "shared/plugin.h" -#define TOUCH_ON 1 -#define TOUCH_OFF 0 - -#define LCD_PHASED_MAX_BRIGHTNESS 100 - -#define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" - -#define GESTURE_STR "gesture" -#define POWERKEY_STR "powerkey" -#define EVENT_STR "event" -#define TOUCH_STR "touch" -#define BEZEL_STR "bezel" -#define TIMEOUT_STR "timeout" -#define PROXIMITY_STR "proximity" -#define PALM_STR "palm" -#define UNKNOWN_STR "unknown" - -#define FREEZER_VITAL_WAKEUP_CGROUP "/sys/fs/cgroup/freezer/vital_wakeup/freezer.state" - - static struct display_backlight_ops backlight_ops; static struct battery_plugin *battery_plgn; static bool display_dev_available = false; diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index 635dfba..8c1bd60 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -55,11 +55,8 @@ #define SW_GLOVE 0x16 #endif -#define PREDEF_LEAVESLEEP "leavesleep" -#define POWEROFF_ACT "poweroff" #define USEC_PER_SEC 1000000 #define USEC_PER_MSEC 1000 -#define CSC_CONFIG_MODE_RUNNING 1 #define CAPTURE_COMBINATION_INTERVAL 0.5 /* 0.5 second */ #define TORCH_COMBINATION_INTERVAL 0.1 /* 0.1 second */ @@ -67,17 +64,10 @@ #define LONGKEY_PRESSED_TIME 4 /* 4 second */ -#define KEY_MAX_DELAY_TIME 700 /* ms */ - #define SIGNAL_CHANGE_HARDKEY "ChangeHardkey" #define SIGNAL_LCDON_BY_POWERKEY "LCDOnByPowerkey" #define SIGNAL_LCDOFF_BY_POWERKEY "LCDOffByPowerkey" -#define NORMAL_POWER 0 -#define KEY_TEST_MODE_POWER 2 - -#define GLOVE_MODE 1 - enum key_combination_flags { KEY_COMBINATION_STOP = 0, KEY_COMBINATION_POWERKEY = BIT(0), diff --git a/src/display/plugin-common/auto-brightness.c b/src/display/plugin-common/auto-brightness.c index 847970a..64b4251 100644 --- a/src/display/plugin-common/auto-brightness.c +++ b/src/display/plugin-common/auto-brightness.c @@ -39,12 +39,6 @@ #include "shared/device-notifier.h" #include -#define METHOD_CHECK_SUPPORTED "CheckSupported" - -#define DISP_FORCE_SHIFT 12 -#define DISP_FORCE_CMD(prop, force) (((force) << DISP_FORCE_SHIFT) | prop) - -#define SAMPLING_INTERVAL 1 /* 1 sec */ #define MAX_SAMPLING_COUNT 3 #define MAX_FAULT 5 #define DEFAULT_AUTOMATIC_BRT 5 @@ -56,13 +50,6 @@ #define WORKING_ANGLE_MIN 0 #define WORKING_ANGLE_MAX 20 -#define BOARD_CONF_FILE "/etc/deviced/display.conf" - -#define ON_LUX -1 -#define OFF_LUX -1 -#define ON_COUNT 1 -#define OFF_COUNT 1 - static int (*_default_action) (int); static guint alc_timeout_id = 0; static guint update_timeout; diff --git a/src/display/plugin-common/display-dbus.c b/src/display/plugin-common/display-dbus.c index 1994bc4..78fb314 100644 --- a/src/display/plugin-common/display-dbus.c +++ b/src/display/plugin-common/display-dbus.c @@ -56,11 +56,6 @@ #define APP_CHANGE_STATE "AppStatusChange" #define APP_TERMINATED "AppTerminated" -#define TELEPHONY_PATH "/org/tizen/telephony" -#define TELEPHONY_INTERFACE_SIM "org.tizen.telephony.Manager" -#define SIGNAL_SIM_STATUS "SimInserted" -#define SIM_CARD_NOT_PRESENT (0x0) - #ifndef VCONFKEY_LCD_BRIGHTNESS_INIT #define VCONFKEY_LCD_BRIGHTNESS_INIT "db/private/deviced/lcd_brightness_init" #endif diff --git a/src/display/plugin-common/poll.c b/src/display/plugin-common/poll.c index 1fa0b48..769c6d4 100644 --- a/src/display/plugin-common/poll.c +++ b/src/display/plugin-common/poll.c @@ -32,14 +32,6 @@ #include "display-plugin.h" #include "shared/plugin.h" -#define SHIFT_UNLOCK 4 -#define SHIFT_UNLOCK_PARAMETER 12 -#define SHIFT_CHANGE_STATE 8 -#define SHIFT_CHANGE_TIMEOUT 20 -#define LOCK_FLAG_SHIFT 16 -#define __HOLDKEY_BLOCK_BIT 0x1 -#define HOLDKEY_BLOCK_BIT (__HOLDKEY_BLOCK_BIT << LOCK_FLAG_SHIFT) - static PMMsg recv_data; int check_dimstay(int next_state, int flag) -- 2.7.4 From 78d970139203c91f225e2afcc52151777fab6136 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Wed, 7 Jun 2023 17:34:39 +0900 Subject: [PATCH 03/16] display: state-transition: Relocate update_lcdoff_source() update_lcdoff_source() is used for setting lcdoff reason. This function is called when the display state goes to lcdoff state. Same code was copied and used in all plugins. Thus, this function is added below display-state-transition int display_state_transition_update_lcdoff_reason(int source); -> This function sets the lcdoff reason to VCONFKEY_PM_LCDOFF_SOURCE. Change-Id: Idc857d4b52502612eaccb01373d984815806a153 Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 22 +--------------------- plugins/iot-headed/display/key-filter.c | 5 +++-- plugins/mobile/display/core.c | 22 +--------------------- plugins/mobile/display/key-filter.c | 5 +++-- plugins/tv/display/core.c | 22 +--------------------- plugins/tv/display/key-filter.c | 5 +++-- plugins/wearable/display/core.c | 22 +--------------------- plugins/wearable/display/key-filter.c | 5 +++-- src/display/core.h | 1 - src/display/display-state-transition.c | 24 ++++++++++++++++++++++++ src/display/display-state-transition.h | 1 + src/display/plugin-common/display-dbus.c | 3 ++- 12 files changed, 43 insertions(+), 94 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index fcbafea..b1c68b1 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -714,26 +714,6 @@ static int proc_condition(PMMsg *data) return 0; } -void update_lcdoff_source(int source) -{ - int ret; - - switch (source) { - case VCONFKEY_PM_LCDOFF_BY_TIMEOUT: - _I("LCD OFF by timeout."); - break; - case VCONFKEY_PM_LCDOFF_BY_POWERKEY: - _I("LCD OFF by powerkey."); - break; - default: - _E("Invalid value(%d).", source); - return; - } - ret = vconf_set_int(VCONFKEY_PM_LCDOFF_SOURCE, source); - if (ret < 0) - _E("Failed to set vconf value for lcd off source: %d", vconf_get_ext_errno()); -} - /* SIGHUP signal handler * For debug... print info to syslog */ @@ -808,7 +788,7 @@ static int default_trans(int evt) /* enter action */ if (st->action) { if (get_pm_cur_state() == S_LCDOFF) - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDOFF)) if (set_custom_lcdon_timeout(0) == true) diff --git a/plugins/iot-headed/display/key-filter.c b/plugins/iot-headed/display/key-filter.c index b8ef405..5361e0e 100644 --- a/plugins/iot-headed/display/key-filter.c +++ b/plugins/iot-headed/display/key-filter.c @@ -37,6 +37,7 @@ #include "display-backlight.h" #include "display-ops.h" #include "display-config.h" +#include "display-state-transition.h" #include "shared/common.h" #include "shared/devices.h" #include "shared/device-notifier.h" @@ -394,7 +395,7 @@ static int lcdoff_powerkey(void) switch_off_lcd(); delete_condition(S_NORMAL); delete_condition(S_LCDDIM); - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_POWERKEY); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); if (disp_plgn->pm_change_internal) disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); } @@ -508,7 +509,7 @@ static int process_screenlock_key(struct input_event *pinput) if (!check_holdkey_block(S_NORMAL) && !check_holdkey_block(S_LCDDIM)) { delete_condition(S_NORMAL); delete_condition(S_LCDDIM); - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_POWERKEY); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); /* LCD off forcly */ if (disp_plgn->pm_change_internal) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 9545fac..464d3d4 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -724,26 +724,6 @@ static int proc_condition(PMMsg *data) return 0; } -void update_lcdoff_source(int source) -{ - int ret; - - switch (source) { - case VCONFKEY_PM_LCDOFF_BY_TIMEOUT: - _I("LCD OFF by timeout."); - break; - case VCONFKEY_PM_LCDOFF_BY_POWERKEY: - _I("LCD OFF by powerkey."); - break; - default: - _E("Invalid value(%d).", source); - return; - } - ret = vconf_set_int(VCONFKEY_PM_LCDOFF_SOURCE, source); - if (ret < 0) - _E("Failed to set vconf value for lcd off source: %d", vconf_get_ext_errno()); -} - /* SIGHUP signal handler * For debug... print info to syslog */ @@ -818,7 +798,7 @@ static int default_trans(int evt) /* enter action */ if (st->action) { if (get_pm_cur_state() == S_LCDOFF) - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDOFF)) if (set_custom_lcdon_timeout(0) == true) diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index 180262d..65a0de2 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -37,6 +37,7 @@ #include "display-backlight.h" #include "display-ops.h" #include "display-config.h" +#include "display-state-transition.h" #include "shared/common.h" #include "shared/devices.h" #include "shared/device-notifier.h" @@ -384,7 +385,7 @@ static int lcdoff_powerkey(void) switch_off_lcd(); delete_condition(S_NORMAL); delete_condition(S_LCDDIM); - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_POWERKEY); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); if (disp_plgn->pm_change_internal) disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); } @@ -541,7 +542,7 @@ static int process_screenlock_key(struct input_event *pinput) if (!check_holdkey_block(S_NORMAL) && !check_holdkey_block(S_LCDDIM)) { delete_condition(S_NORMAL); delete_condition(S_LCDDIM); - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_POWERKEY); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); /* LCD off forcly */ if (disp_plgn->pm_change_internal) diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 49e70e3..b986639 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -714,26 +714,6 @@ static int proc_condition(PMMsg *data) return 0; } -void update_lcdoff_source(int source) -{ - int ret; - - switch (source) { - case VCONFKEY_PM_LCDOFF_BY_TIMEOUT: - _I("LCD OFF by timeout."); - break; - case VCONFKEY_PM_LCDOFF_BY_POWERKEY: - _I("LCD OFF by powerkey."); - break; - default: - _E("Invalid value(%d).", source); - return; - } - ret = vconf_set_int(VCONFKEY_PM_LCDOFF_SOURCE, source); - if (ret < 0) - _E("Failed to set vconf value for lcd off source: %d", vconf_get_ext_errno()); -} - /* SIGHUP signal handler * For debug... print info to syslog */ @@ -808,7 +788,7 @@ static int default_trans(int evt) /* enter action */ if (st->action) { if (get_pm_cur_state() == S_LCDOFF) - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDOFF)) if (set_custom_lcdon_timeout(0) == true) diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index 64628d6..6a44187 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -37,6 +37,7 @@ #include "display-backlight.h" #include "display-ops.h" #include "display-config.h" +#include "display-state-transition.h" #include "shared/common.h" #include "shared/devices.h" #include "shared/device-notifier.h" @@ -394,7 +395,7 @@ static int lcdoff_powerkey(void) switch_off_lcd(); delete_condition(S_NORMAL); delete_condition(S_LCDDIM); - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_POWERKEY); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); if (disp_plgn->pm_change_internal) disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); } @@ -508,7 +509,7 @@ static int process_screenlock_key(struct input_event *pinput) if (!check_holdkey_block(S_NORMAL) && !check_holdkey_block(S_LCDDIM)) { delete_condition(S_NORMAL); delete_condition(S_LCDDIM); - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_POWERKEY); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); /* LCD off forcly */ if (disp_plgn->pm_change_internal) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index b0a7d33..9e61e52 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -1049,26 +1049,6 @@ static int proc_condition(PMMsg *data) return 0; } -void update_lcdoff_source(int source) -{ - int ret; - - switch (source) { - case VCONFKEY_PM_LCDOFF_BY_TIMEOUT: - _I("LCD OFF by timeout."); - break; - case VCONFKEY_PM_LCDOFF_BY_POWERKEY: - _I("LCD OFF by powerkey."); - break; - default: - _E("Invalid value(%d).", source); - return; - } - ret = vconf_set_int(VCONFKEY_PM_LCDOFF_SOURCE, source); - if (ret < 0) - _E("Failed to set vconf value for lcd off source: %d", vconf_get_ext_errno()); -} - /* SIGHUP signal handler * For debug... print info to syslog */ @@ -1151,7 +1131,7 @@ static int default_trans(int evt) /* enter action */ if (st->action) { if (get_pm_cur_state() == S_LCDOFF) - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDOFF)) if (set_custom_lcdon_timeout(0) == true) diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index 8c1bd60..2658612 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -37,6 +37,7 @@ #include "display-panel.h" #include "display-backlight.h" #include "display-config.h" +#include "display-state-transition.h" #include "shared/common.h" #include "shared/devices.h" #include "shared/device-notifier.h" @@ -391,7 +392,7 @@ static int lcdoff_powerkey(void) switch_off_lcd(); delete_condition(S_NORMAL); delete_condition(S_LCDDIM); - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_POWERKEY); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); if (disp_plgn->pm_change_internal) disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); } @@ -505,7 +506,7 @@ static int process_screenlock_key(struct input_event *pinput) if (!check_holdkey_block(S_NORMAL) && !check_holdkey_block(S_LCDDIM)) { delete_condition(S_NORMAL); delete_condition(S_LCDDIM); - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_POWERKEY); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); /* LCD off forcly */ if (disp_plgn->pm_change_internal) diff --git a/src/display/core.h b/src/display/core.h index ae7ea33..6a11082 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -125,7 +125,6 @@ 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); -void update_lcdoff_source(int source); int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name); int custom_lcdon(int timeout); void lcd_on_direct(enum device_flags flags); diff --git a/src/display/display-state-transition.c b/src/display/display-state-transition.c index 126d77b..bc06af4 100644 --- a/src/display/display-state-transition.c +++ b/src/display/display-state-transition.c @@ -280,4 +280,28 @@ int display_state_transition_check_state_transition_condition(enum state_t cur_s } return 0; /* transitable */ +} + +int display_state_transition_update_lcdoff_reason(int source) +{ + int ret; + + switch (source) { + case VCONFKEY_PM_LCDOFF_BY_TIMEOUT: + _I("LCD OFF by timeout."); + break; + case VCONFKEY_PM_LCDOFF_BY_POWERKEY: + _I("LCD OFF by powerkey."); + break; + default: + _E("Invalid value(%d).", source); + return -EINVAL; + } + ret = vconf_set_int(VCONFKEY_PM_LCDOFF_SOURCE, source); + if (ret < 0) { + _E("Failed to set vconf value for lcd off source: %d", vconf_get_ext_errno()); + return -EPERM; + } + + return 0; } \ No newline at end of file diff --git a/src/display/display-state-transition.h b/src/display/display-state-transition.h index caed462..7193a7f 100644 --- a/src/display/display-state-transition.h +++ b/src/display/display-state-transition.h @@ -38,5 +38,6 @@ int display_state_transition_set_lock_screen_timeout(int timeout); int display_state_transition_get_lock_screen_timeout(int *timeout); void display_state_transition_update_display_state_timeout_by_priority(void); int display_state_transition_check_state_transition_condition(enum state_t cur_state, enum state_t next_state); +int display_state_transition_update_lcdoff_reason(int source); #endif /* __DISPLAY_STATE_TRANSITION_H__ */ \ No newline at end of file diff --git a/src/display/plugin-common/display-dbus.c b/src/display/plugin-common/display-dbus.c index 78fb314..24eb2ff 100644 --- a/src/display/plugin-common/display-dbus.c +++ b/src/display/plugin-common/display-dbus.c @@ -47,6 +47,7 @@ #include "display-lock.h" #include "display-panel.h" #include "display-config.h" +#include "display-state-transition.h" //#include "display/display.h" #include "display-backlight.h" #include "display-misc.h" @@ -361,7 +362,7 @@ static GVariant *dbus_changestate(GDBusConnection *conn, ret = disp_plgn->pm_change_internal(pid, state); if (!ret && state == LCD_OFF) - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); out: g_free(state_str); return g_variant_new("(i)", ret); -- 2.7.4 From eb461067bfcbafae868b141cf2163a612bf4a386 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Thu, 8 Jun 2023 10:49:19 +0900 Subject: [PATCH 04/16] display: state-transition: Relocate check_lcdoff_direct() check_lcdoff_direct() is used to check if display state can go to S_LCDOFF. All plugins follows same policy of this function. Thus, this function is added below display-state-transition. - bool display_state_transition_is_possible_to_go_lcdoff(void); -> This replaces check_lcdoff_direct(). Also, new function is added below display-plugin. - int display_plugin_config_get_dimming(int *dimming); -> It gets dimming config value from the conf file. To confirm going to S_LCDOFF state, dimming value must also be checked. So, display_plugin_config_get_dimming() is added too. Change-Id: I19545fa1d6e7592a938a24e0b130302d88d81e02 Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 35 +------------------------------ plugins/mobile/display/core.c | 35 +------------------------------ plugins/tv/display/core.c | 35 +------------------------------ plugins/wearable/display/core.c | 35 +------------------------------ src/display/display-plugin.c | 13 ++++++++++++ src/display/display-plugin.h | 1 + src/display/display-state-transition.c | 38 ++++++++++++++++++++++++++++++++++ src/display/display-state-transition.h | 1 + 8 files changed, 57 insertions(+), 136 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index b1c68b1..6eb4dd4 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -724,39 +724,6 @@ static void sig_hup(int signo) pm_save_logdump(); } -int check_lcdoff_direct(void) -{ - int ret, lock, cradle; - int hdmi_state; - - if (get_pm_old_state() != S_NORMAL) - return false; - - if (get_pm_cur_state() != S_LCDDIM) - return false; - - if (!display_conf.dimming) - return true; - - lock = __get_lock_screen_state(); - if (lock != VCONFKEY_IDLE_LOCK) - return false; - - hdmi_state = extcon_get_status(EXTCON_CABLE_HDMI); - if (hdmi_state) - return false; - - ret = vconf_get_int(VCONFKEY_SYSMAN_CRADLE_STATUS, &cradle); - if (ret >= 0 && cradle == DOCK_SOUND) - return false; - else if (ret < 0) - _E("Failed to get vconf value for cradle status: %d", vconf_get_ext_errno()); - - _D("Goto LCDOFF direct: lock(%d) hdmi(%d) cradle(%d).", lock, hdmi_state, cradle); - - return true; -} - /* * default transition function * 1. call check @@ -794,7 +761,7 @@ static int default_trans(int evt) if (set_custom_lcdon_timeout(0) == true) display_state_transition_update_display_state_timeout_by_priority(); - if (check_lcdoff_direct() == true) { + if (display_state_transition_is_possible_to_go_lcdoff()) { /* enter next state directly */ states[get_pm_cur_state()].trans(EVENT_TIMEOUT); } else { diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 464d3d4..ec49a57 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -734,39 +734,6 @@ static void sig_hup(int signo) pm_save_logdump(); } -int check_lcdoff_direct(void) -{ - int ret, lock, cradle; - int hdmi_state; - - if (get_pm_old_state() != S_NORMAL) - return false; - - if (get_pm_cur_state() != S_LCDDIM) - return false; - - if (!display_conf.dimming) - return true; - - lock = __get_lock_screen_state(); - if (lock != VCONFKEY_IDLE_LOCK) - return false; - - hdmi_state = extcon_get_status(EXTCON_CABLE_HDMI); - if (hdmi_state) - return false; - - ret = vconf_get_int(VCONFKEY_SYSMAN_CRADLE_STATUS, &cradle); - if (ret >= 0 && cradle == DOCK_SOUND) - return false; - else if (ret < 0) - _E("Failed to get vconf value for cradle status: %d", vconf_get_ext_errno()); - - _D("Goto LCDOFF direct: lock(%d) hdmi(%d) cradle(%d).", lock, hdmi_state, cradle); - - return true; -} - /* * default transition function * 1. call check @@ -804,7 +771,7 @@ static int default_trans(int evt) if (set_custom_lcdon_timeout(0) == true) display_state_transition_update_display_state_timeout_by_priority(); - if (check_lcdoff_direct() == true) { + if (display_state_transition_is_possible_to_go_lcdoff()) { /* enter next state directly */ states[get_pm_cur_state()].trans(EVENT_TIMEOUT); } else { diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index b986639..168041e 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -724,39 +724,6 @@ static void sig_hup(int signo) pm_save_logdump(); } -int check_lcdoff_direct(void) -{ - int ret, lock, cradle; - int hdmi_state; - - if (get_pm_old_state() != S_NORMAL) - return false; - - if (get_pm_cur_state() != S_LCDDIM) - return false; - - if (!display_conf.dimming) - return true; - - lock = __get_lock_screen_state(); - if (lock != VCONFKEY_IDLE_LOCK) - return false; - - hdmi_state = extcon_get_status(EXTCON_CABLE_HDMI); - if (hdmi_state) - return false; - - ret = vconf_get_int(VCONFKEY_SYSMAN_CRADLE_STATUS, &cradle); - if (ret >= 0 && cradle == DOCK_SOUND) - return false; - else if (ret < 0) - _E("Failed to get vconf value for cradle status: %d", vconf_get_ext_errno()); - - _D("Goto LCDOFF direct: lock(%d) hdmi(%d) cradle(%d).", lock, hdmi_state, cradle); - - return true; -} - /* * default transition function * 1. call check @@ -794,7 +761,7 @@ static int default_trans(int evt) if (set_custom_lcdon_timeout(0) == true) display_state_transition_update_display_state_timeout_by_priority(); - if (check_lcdoff_direct() == true) { + if (display_state_transition_is_possible_to_go_lcdoff()) { /* enter next state directly */ states[get_pm_cur_state()].trans(EVENT_TIMEOUT); } else { diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 9e61e52..de873cb 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -1059,39 +1059,6 @@ static void sig_hup(int signo) pm_save_logdump(); } -int check_lcdoff_direct(void) -{ - int ret, lock, cradle; - int hdmi_state; - - if (get_pm_old_state() != S_NORMAL) - return false; - - if (get_pm_cur_state() != S_LCDDIM) - return false; - - if (!display_conf.dimming) - return true; - - lock = __get_lock_screen_state(); - if (lock != VCONFKEY_IDLE_LOCK) - return false; - - hdmi_state = extcon_get_status(EXTCON_CABLE_HDMI); - if (hdmi_state) - return false; - - ret = vconf_get_int(VCONFKEY_SYSMAN_CRADLE_STATUS, &cradle); - if (ret >= 0 && cradle == DOCK_SOUND) - return false; - else if (ret < 0) - _E("Failed to get vconf value for cradle status: %d", vconf_get_ext_errno()); - - _D("Goto LCDOFF direct: lock(%d) hdmi(%d) cradle(%d).", lock, hdmi_state, cradle); - - return true; -} - /* * default transition function * 1. call check @@ -1137,7 +1104,7 @@ static int default_trans(int evt) if (set_custom_lcdon_timeout(0) == true) display_state_transition_update_display_state_timeout_by_priority(); - if (check_lcdoff_direct() == true) { + if (display_state_transition_is_possible_to_go_lcdoff()) { /* enter next state directly */ states[get_pm_cur_state()].trans(EVENT_TIMEOUT); } else { diff --git a/src/display/display-plugin.c b/src/display/display-plugin.c index 2e7ffac..176ab5d 100644 --- a/src/display/display-plugin.c +++ b/src/display/display-plugin.c @@ -255,6 +255,19 @@ int display_plugin_config_get_lcd_always_on(int *lcd_always_on) return -EOPNOTSUPP; } +int display_plugin_config_get_dimming(int *dimming) +{ + if (!dimming) + return -EINVAL; + + if (g_display_plugin.config) { + *dimming = g_display_plugin.config->dimming; + return 0; + } + + return -EOPNOTSUPP; +} + int display_plugin_set_dim_state(bool on) { if (g_display_plugin.set_dim_state) { diff --git a/src/display/display-plugin.h b/src/display/display-plugin.h index 09d8aa3..820cf0f 100644 --- a/src/display/display-plugin.h +++ b/src/display/display-plugin.h @@ -106,5 +106,6 @@ int display_plugin_state_get_state_by_state_index(int state_index, enum state_t int display_plugin_config_get_timeout_enable(bool *timeout_enable); int display_plugin_config_get_lcdoff_timeout(int *lcdoff_timeout); int display_plugin_config_get_lcd_always_on(int *lcd_always_on); +int display_plugin_config_get_dimming(int *dimming); #endif //__DISPLAY_PLUGIN_H__ diff --git a/src/display/display-state-transition.c b/src/display/display-state-transition.c index bc06af4..4836cac 100644 --- a/src/display/display-state-transition.c +++ b/src/display/display-state-transition.c @@ -21,10 +21,12 @@ * @brief This file has functions related to display state transition */ +#include "core/udev.h" #include "device-interface.h" #include "display-state-transition.h" #include "display-lock.h" #include "display-plugin.h" +#include "extcon/extcon.h" #include "power/power-suspend.h" #include "shared/log.h" @@ -304,4 +306,40 @@ int display_state_transition_update_lcdoff_reason(int source) } return 0; +} + +/* FIXME: In this function, extcon checking should be considered after relocating this. */ +bool display_state_transition_is_possible_to_go_lcdoff(void) +{ + int ret, lock, cradle; + int hdmi_state; + int dimming; + + if (get_pm_old_state() != S_NORMAL) + return false; + + if (get_pm_cur_state() != S_LCDDIM) + return false; + + display_plugin_config_get_dimming(&dimming); + if (!dimming) + return true; + + lock = __get_lock_screen_state(); + if (lock != VCONFKEY_IDLE_LOCK) + return false; + + hdmi_state = extcon_get_status(EXTCON_CABLE_HDMI); + if (hdmi_state) + return false; + + ret = vconf_get_int(VCONFKEY_SYSMAN_CRADLE_STATUS, &cradle); + if (ret >= 0 && cradle == DOCK_SOUND) + return false; + else if (ret < 0) + _E("Failed to get vconf value for cradle status: %d", vconf_get_ext_errno()); + + _D("Goto LCDOFF direct: lock(%d) hdmi(%d) cradle(%d).", lock, hdmi_state, cradle); + + return true; } \ No newline at end of file diff --git a/src/display/display-state-transition.h b/src/display/display-state-transition.h index 7193a7f..e114326 100644 --- a/src/display/display-state-transition.h +++ b/src/display/display-state-transition.h @@ -39,5 +39,6 @@ int display_state_transition_get_lock_screen_timeout(int *timeout); void display_state_transition_update_display_state_timeout_by_priority(void); int display_state_transition_check_state_transition_condition(enum state_t cur_state, enum state_t next_state); int display_state_transition_update_lcdoff_reason(int source); +bool display_state_transition_is_possible_to_go_lcdoff(void); #endif /* __DISPLAY_STATE_TRANSITION_H__ */ \ No newline at end of file -- 2.7.4 From 5f39ca0b4410cf4560bdae2992e48854d802dc7b Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Wed, 7 Jun 2023 16:29:32 +0900 Subject: [PATCH 05/16] display: state-transition: Relocate default_trans() default_trans() was used for display state transition. 1. It gets next display state and checks if the state transition is possible or not. 2. And then, it updates old/current display state. 3. Finally, it goes to next state transition or default_action if possible. These functions are added below display-state-transition. - int display_state_transition_do_state_transition(enum state_t state, int evt_type); -> This replaces default_trans() - bool display_state_transition_is_display_state_support_transition(enum state_t state); -> This function checks if state is support to do state transition related job. For example, 1. checking state transition condition 2. do state transition 3. do state action To check these, this function is added. Change-Id: Icc58965838e30fde2871c1c69596ffbed43e60f2 Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 81 ++++++---------------------------- plugins/mobile/display/core.c | 81 ++++++---------------------------- plugins/tv/display/core.c | 81 ++++++---------------------------- src/display/display-lock.c | 2 +- src/display/display-plugin.c | 9 ++++ src/display/display-plugin.h | 1 + src/display/display-state-transition.c | 70 ++++++++++++++++++++++++++--- src/display/display-state-transition.h | 2 + src/display/plugin-common/poll.c | 7 +-- 9 files changed, 124 insertions(+), 210 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 6eb4dd4..74eb8fd 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -111,7 +111,6 @@ static bool lcdon_broadcast = true; static bool touch_blocked = false; /* default transition, action fuctions */ -static int default_trans(int evt); static int default_action(int timeout); static int default_proc_change_state(unsigned int cond, pid_t pid); @@ -119,11 +118,11 @@ static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_cha static struct state states[S_END] = { { S_START, "S_START", NULL, NULL, NULL, NULL }, - { S_NORMAL, "S_NORMAL", default_trans, default_action, NULL, NULL }, - { S_LCDDIM, "S_LCDDIM", default_trans, default_action, NULL, NULL }, - { S_LCDOFF, "S_LCDOFF", default_trans, default_action, NULL, NULL }, + { S_NORMAL, "S_NORMAL", NULL, default_action, NULL, NULL }, + { S_LCDDIM, "S_LCDDIM", NULL, default_action, NULL, NULL }, + { S_LCDOFF, "S_LCDOFF", NULL, default_action, NULL, NULL }, { S_STANDBY, "S_STANDBY", NULL, NULL, NULL, NULL }, - { S_SLEEP, "S_SLEEP", default_trans, default_action, NULL, NULL }, + { S_SLEEP, "S_SLEEP", NULL, default_action, NULL, NULL }, { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, }; @@ -709,7 +708,7 @@ static int proc_condition(PMMsg *data) } if (!display_state_transition_is_there_state_transition_timer()) - states[get_pm_cur_state()].trans(EVENT_TIMEOUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT); return 0; } @@ -724,58 +723,6 @@ static void sig_hup(int signo) pm_save_logdump(); } -/* - * default transition function - * 1. call check - * 2. transition - * 3. call enter action function - */ -static int default_trans(int evt) -{ - struct state *st = &states[get_pm_cur_state()]; - enum state_t next_state; - int ret = 0; - - display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, evt); - - /* check conditions */ - ret = display_state_transition_check_state_transition_condition(get_pm_cur_state(), next_state); - if (ret < 0) { - /* There is a condition. */ - _I("%s locked. Trans to %s failed.", states[get_pm_cur_state()].name, - states[next_state].name); - return -1; - } - - /* state transition */ - set_pm_old_state(get_pm_cur_state()); - set_pm_cur_state(next_state); - st = &states[get_pm_cur_state()]; - - /* enter action */ - if (st->action) { - if (get_pm_cur_state() == S_LCDOFF) - display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); - - if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDOFF)) - if (set_custom_lcdon_timeout(0) == true) - display_state_transition_update_display_state_timeout_by_priority(); - - if (display_state_transition_is_possible_to_go_lcdoff()) { - /* enter next state directly */ - states[get_pm_cur_state()].trans(EVENT_TIMEOUT); - } else { - if ((get_pm_cur_state() == S_SLEEP) - && (is_emulator() == true || timeout_sleep_support == false)) - return 0; - - st->action(st->timeout); - } - } - - return 0; -} - static gboolean lcd_on_expired(void *data) { int lock_state, ret; @@ -952,7 +899,7 @@ go_suspend: go_lcd_off: if (!pm_get_power_lock_support()) { /* Resume !! */ - states[get_pm_cur_state()].trans(EVENT_DEVICE); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE); } return 0; } @@ -985,7 +932,7 @@ int poll_callback(int condition, PMMsg *data) if ((last_t != now) || (get_pm_cur_state() == S_LCDOFF) || (get_pm_cur_state() == S_SLEEP)) { - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); last_t = now; } } @@ -1007,7 +954,7 @@ static int update_setting(int key_idx, int val) switch (key_idx) { case SETTING_TO_NORMAL: display_state_transition_update_display_state_timeout_by_priority(); - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); break; case SETTING_LOW_BATT: if (display_misc_is_low_battery_state(val)) { @@ -1071,13 +1018,13 @@ static int update_setting(int key_idx, int val) stop_lock_timer(); display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); break; case SETTING_LOCK_SCREEN_BG: set_lock_screen_bg_state(val); display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); break; case SETTING_POWER_CUSTOM_BRIGHTNESS: if (val == VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON) @@ -1208,7 +1155,7 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) /* Apply new backlight time */ display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); if (holdkey_block) { display_lock_set_custom_holdkey_block(true); @@ -1266,7 +1213,7 @@ void reset_lcd_timeout(GDBusConnection *conn, display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); } static int delayed_init_done(void *data) @@ -1390,10 +1337,10 @@ static int power_resume_from_echomem_callback(void *data) system_wakeup_flag = true; if (check_wakeup_src() == EVENT_DEVICE) /* system waked up by devices */ - states[get_pm_cur_state()].trans(EVENT_DEVICE); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE); else /* system waked up by user input */ - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); return 0; } diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index ec49a57..6d1244d 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -113,7 +113,6 @@ static bool lcdon_broadcast = true; static bool touch_blocked = false; /* default transition, action fuctions */ -static int default_trans(int evt); static int default_action(int timeout); static int default_proc_change_state(unsigned int cond, pid_t pid); @@ -121,11 +120,11 @@ static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_cha static struct state states[S_END] = { { S_START, "S_START", NULL, NULL, NULL, NULL }, - { S_NORMAL, "S_NORMAL", default_trans, default_action, NULL, NULL }, - { S_LCDDIM, "S_LCDDIM", default_trans, default_action, NULL, NULL }, - { S_LCDOFF, "S_LCDOFF", default_trans, default_action, NULL, NULL }, + { S_NORMAL, "S_NORMAL", NULL, default_action, NULL, NULL }, + { S_LCDDIM, "S_LCDDIM", NULL, default_action, NULL, NULL }, + { S_LCDOFF, "S_LCDOFF", NULL, default_action, NULL, NULL }, { S_STANDBY, "S_STANDBY", NULL, NULL, NULL, NULL }, - { S_SLEEP, "S_SLEEP", default_trans, default_action, NULL, NULL }, + { S_SLEEP, "S_SLEEP", NULL, default_action, NULL, NULL }, { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, }; @@ -719,7 +718,7 @@ static int proc_condition(PMMsg *data) } if (!display_state_transition_is_there_state_transition_timer()) - states[get_pm_cur_state()].trans(EVENT_TIMEOUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT); return 0; } @@ -734,58 +733,6 @@ static void sig_hup(int signo) pm_save_logdump(); } -/* - * default transition function - * 1. call check - * 2. transition - * 3. call enter action function - */ -static int default_trans(int evt) -{ - struct state *st = &states[get_pm_cur_state()]; - enum state_t next_state; - int ret = 0; - - display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, evt); - - /* check conditions */ - ret = display_state_transition_check_state_transition_condition(get_pm_cur_state(), next_state); - if (ret < 0) { - /* There is a condition. */ - _I("%s locked. Trans to %s failed.", states[get_pm_cur_state()].name, - states[next_state].name); - return -1; - } - - /* state transition */ - set_pm_old_state(get_pm_cur_state()); - set_pm_cur_state(next_state); - st = &states[get_pm_cur_state()]; - - /* enter action */ - if (st->action) { - if (get_pm_cur_state() == S_LCDOFF) - display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); - - if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDOFF)) - if (set_custom_lcdon_timeout(0) == true) - display_state_transition_update_display_state_timeout_by_priority(); - - if (display_state_transition_is_possible_to_go_lcdoff()) { - /* enter next state directly */ - states[get_pm_cur_state()].trans(EVENT_TIMEOUT); - } else { - if ((get_pm_cur_state() == S_SLEEP) - && (is_emulator() == true || timeout_sleep_support == false)) - return 0; - - st->action(st->timeout); - } - } - - return 0; -} - static gboolean lcd_on_expired(void *data) { int lock_state, ret; @@ -962,7 +909,7 @@ go_suspend: go_lcd_off: if (!pm_get_power_lock_support()) { /* Resume !! */ - states[get_pm_cur_state()].trans(EVENT_DEVICE); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE); } return 0; } @@ -995,7 +942,7 @@ int poll_callback(int condition, PMMsg *data) if ((last_t != now) || (get_pm_cur_state() == S_LCDOFF) || (get_pm_cur_state() == S_SLEEP)) { - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); last_t = now; } } @@ -1017,7 +964,7 @@ static int update_setting(int key_idx, int val) switch (key_idx) { case SETTING_TO_NORMAL: display_state_transition_update_display_state_timeout_by_priority(); - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); break; case SETTING_LOW_BATT: if (display_misc_is_low_battery_state(val)) { @@ -1081,13 +1028,13 @@ static int update_setting(int key_idx, int val) stop_lock_timer(); display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); break; case SETTING_LOCK_SCREEN_BG: set_lock_screen_bg_state(val); display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); break; case SETTING_POWER_CUSTOM_BRIGHTNESS: if (val == VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON) @@ -1218,7 +1165,7 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) /* Apply new backlight time */ display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); if (holdkey_block) { display_lock_set_custom_holdkey_block(true); @@ -1276,7 +1223,7 @@ void reset_lcd_timeout(GDBusConnection *conn, display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); } static int delayed_init_done(void *data) @@ -1396,10 +1343,10 @@ static int power_resume_from_echomem_callback(void *data) system_wakeup_flag = true; if (check_wakeup_src() == EVENT_DEVICE) /* system waked up by devices */ - states[get_pm_cur_state()].trans(EVENT_DEVICE); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE); else /* system waked up by user input */ - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); return 0; } diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 168041e..33072ae 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -111,7 +111,6 @@ static bool lcdon_broadcast = true; static bool touch_blocked = false; /* default transition, action fuctions */ -static int default_trans(int evt); static int default_action(int timeout); static int default_proc_change_state(unsigned int cond, pid_t pid); @@ -119,11 +118,11 @@ static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_cha static struct state states[S_END] = { { S_START, "S_START", NULL, NULL, NULL, NULL }, - { S_NORMAL, "S_NORMAL", default_trans, default_action, NULL, NULL }, - { S_LCDDIM, "S_LCDDIM", default_trans, default_action, NULL, NULL }, - { S_LCDOFF, "S_LCDOFF", default_trans, default_action, NULL, NULL }, + { S_NORMAL, "S_NORMAL", NULL, default_action, NULL, NULL }, + { S_LCDDIM, "S_LCDDIM", NULL, default_action, NULL, NULL }, + { S_LCDOFF, "S_LCDOFF", NULL, default_action, NULL, NULL }, { S_STANDBY, "S_STANDBY", NULL, NULL, NULL, NULL }, - { S_SLEEP, "S_SLEEP", default_trans, default_action, NULL, NULL }, + { S_SLEEP, "S_SLEEP", NULL, default_action, NULL, NULL }, { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, }; @@ -709,7 +708,7 @@ static int proc_condition(PMMsg *data) } if (!display_state_transition_is_there_state_transition_timer()) - states[get_pm_cur_state()].trans(EVENT_TIMEOUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT); return 0; } @@ -724,58 +723,6 @@ static void sig_hup(int signo) pm_save_logdump(); } -/* - * default transition function - * 1. call check - * 2. transition - * 3. call enter action function - */ -static int default_trans(int evt) -{ - struct state *st = &states[get_pm_cur_state()]; - enum state_t next_state; - int ret = 0; - - display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, evt); - - /* check conditions */ - ret = display_state_transition_check_state_transition_condition(get_pm_cur_state(), next_state); - if (ret < 0) { - /* There is a condition. */ - _I("%s locked. Trans to %s failed.", states[get_pm_cur_state()].name, - states[next_state].name); - return -1; - } - - /* state transition */ - set_pm_old_state(get_pm_cur_state()); - set_pm_cur_state(next_state); - st = &states[get_pm_cur_state()]; - - /* enter action */ - if (st->action) { - if (get_pm_cur_state() == S_LCDOFF) - display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); - - if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDOFF)) - if (set_custom_lcdon_timeout(0) == true) - display_state_transition_update_display_state_timeout_by_priority(); - - if (display_state_transition_is_possible_to_go_lcdoff()) { - /* enter next state directly */ - states[get_pm_cur_state()].trans(EVENT_TIMEOUT); - } else { - if ((get_pm_cur_state() == S_SLEEP) - && (is_emulator() == true || timeout_sleep_support == false)) - return 0; - - st->action(st->timeout); - } - } - - return 0; -} - static gboolean lcd_on_expired(void *data) { int lock_state, ret; @@ -952,7 +899,7 @@ go_suspend: go_lcd_off: if (!pm_get_power_lock_support()) { /* Resume !! */ - states[get_pm_cur_state()].trans(EVENT_DEVICE); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE); } return 0; } @@ -985,7 +932,7 @@ int poll_callback(int condition, PMMsg *data) if ((last_t != now) || (get_pm_cur_state() == S_LCDOFF) || (get_pm_cur_state() == S_SLEEP)) { - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); last_t = now; } } @@ -1007,7 +954,7 @@ static int update_setting(int key_idx, int val) switch (key_idx) { case SETTING_TO_NORMAL: display_state_transition_update_display_state_timeout_by_priority(); - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); break; case SETTING_LOW_BATT: if (display_misc_is_low_battery_state(val)) { @@ -1071,13 +1018,13 @@ static int update_setting(int key_idx, int val) stop_lock_timer(); display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); break; case SETTING_LOCK_SCREEN_BG: set_lock_screen_bg_state(val); display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); break; case SETTING_POWER_CUSTOM_BRIGHTNESS: if (val == VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON) @@ -1208,7 +1155,7 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) /* Apply new backlight time */ display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); if (holdkey_block) { display_lock_set_custom_holdkey_block(true); @@ -1266,7 +1213,7 @@ void reset_lcd_timeout(GDBusConnection *conn, display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); } static int delayed_init_done(void *data) @@ -1387,10 +1334,10 @@ static int power_resume_from_echomem_callback(void *data) system_wakeup_flag = true; if (check_wakeup_src() == EVENT_DEVICE) /* system waked up by devices */ - states[get_pm_cur_state()].trans(EVENT_DEVICE); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE); else /* system waked up by user input */ - states[get_pm_cur_state()].trans(EVENT_INPUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); return 0; } diff --git a/src/display/display-lock.c b/src/display/display-lock.c index d218a19..5b2df70 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -275,7 +275,7 @@ static gboolean delete_state_cond_callback(void *data) * 2. Released lock is one of the pm_cur_state's lock * This emulates already expired transition timer */ if (!display_state_transition_is_there_state_transition_timer() && (get_pm_cur_state() == state)) - display_plugin_state_do_default_trans(get_pm_cur_state(), EVENT_TIMEOUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT); if (state == S_LCDOFF) set_process_active(false, pid); diff --git a/src/display/display-plugin.c b/src/display/display-plugin.c index 176ab5d..3af5995 100644 --- a/src/display/display-plugin.c +++ b/src/display/display-plugin.c @@ -166,6 +166,15 @@ int display_plugin_state_do_default_action(enum state_t state, int timeout) return -EOPNOTSUPP; } +/* FIXME: default_action/default_trans naming should be changed after state transition functions are relocated */ +bool display_plugin_state_is_there_default_action(enum state_t state) +{ + if (g_display_plugin.display_states[state] && g_display_plugin.display_states[state]->action) + return true; + + return false; +} + int display_plugin_state_get_name(enum state_t state, const char **state_name) { if (!state_name) diff --git a/src/display/display-plugin.h b/src/display/display-plugin.h index 820cf0f..bea8205 100644 --- a/src/display/display-plugin.h +++ b/src/display/display-plugin.h @@ -97,6 +97,7 @@ int display_plugin_backlight_transit_brightness(int start, int end, int step); int display_plugin_state_do_default_trans(enum state_t state, int evt); bool display_plugin_state_is_there_default_trans(enum state_t state); int display_plugin_state_do_default_action(enum state_t state, int timeout); +bool display_plugin_state_is_there_default_action(enum state_t state); int display_plugin_state_get_name(enum state_t state, const char **state_name); int display_plugin_state_set_timeout(enum state_t state, int state_timeout); int display_plugin_state_get_timeout(enum state_t state, int *state_timeout); diff --git a/src/display/display-state-transition.c b/src/display/display-state-transition.c index 4836cac..c7a5dff 100644 --- a/src/display/display-state-transition.c +++ b/src/display/display-state-transition.c @@ -92,7 +92,7 @@ static gboolean state_transition_timeout_handler(void *data) remove_state_transition(); - display_plugin_state_do_default_trans(get_pm_cur_state(), EVENT_TIMEOUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT); return G_SOURCE_REMOVE; } @@ -121,7 +121,7 @@ int display_state_transition_reset_state_transition_timeout(int timeout) state_transition_timer_id = g_timeout_add(timeout, state_transition_timeout_handler, NULL); else if (timeout == 0) - display_plugin_state_do_default_trans(get_pm_cur_state(), EVENT_TIMEOUT); + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT); return 0; } @@ -232,7 +232,7 @@ void display_state_transition_update_display_state_timeout_by_priority(void) _I("Normal: DIM timeout is set by %d ms", dim_state_timeout); } -static bool is_display_state_valid_for_transition(enum state_t state) +bool display_state_transition_is_display_state_support_transition(enum state_t state) { switch(state) { case S_NORMAL: @@ -251,7 +251,7 @@ int display_state_transition_check_state_transition_condition(enum state_t cur_s { int trans_cond; - if (!is_display_state_valid_for_transition(cur_state)) + if (!display_state_transition_is_display_state_support_transition(cur_state)) return -EPERM; makeup_trans_condition(); @@ -304,7 +304,6 @@ int display_state_transition_update_lcdoff_reason(int source) _E("Failed to set vconf value for lcd off source: %d", vconf_get_ext_errno()); return -EPERM; } - return 0; } @@ -342,4 +341,65 @@ bool display_state_transition_is_possible_to_go_lcdoff(void) _D("Goto LCDOFF direct: lock(%d) hdmi(%d) cradle(%d).", lock, hdmi_state, cradle); return true; +} + +/* FXIME: enter action logic should be discussed and considered about better logic */ +/* + * default transition function + * 1. call check + * 2. transition + * 3. call enter action function + */ +int display_state_transition_do_state_transition(enum state_t state, int evt_type) +{ + const char* current_state_name = NULL; + const char* next_state_name = NULL; + enum state_t next_state; + int ret = 0; + int timeout = 0; + + if (!display_state_transition_is_display_state_support_transition(state)) + return -EPERM; + + if (display_plugin_state_is_there_default_trans(state)) + return display_plugin_state_do_default_trans(state, evt_type); + + display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, evt_type); + + /* check conditions */ + ret = display_state_transition_check_state_transition_condition(get_pm_cur_state(), next_state); + if (ret < 0) { + display_plugin_state_get_name(get_pm_cur_state(), ¤t_state_name); + display_plugin_state_get_name(next_state, &next_state_name); + /* There is a condition. */ + _I("%s locked. Trans to %s failed.", current_state_name, next_state_name); + return -EPERM; + } + + /* state transition */ + set_pm_old_state(get_pm_cur_state()); + set_pm_cur_state(next_state); + + /* enter action */ + if (display_plugin_state_is_there_default_action(get_pm_cur_state())) { + if (get_pm_cur_state() == S_LCDOFF) + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); + + if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDOFF)) + if (set_custom_lcdon_timeout(0) == true) + display_state_transition_update_display_state_timeout_by_priority(); + + if (display_state_transition_is_possible_to_go_lcdoff()) { + /* enter next state directly */ + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT); + } else { + if ((get_pm_cur_state() == S_SLEEP) && + (is_emulator() == true || timeout_sleep_support == false)) + return 0; + + display_plugin_state_get_timeout(get_pm_cur_state(), &timeout); + display_plugin_state_do_default_action(get_pm_cur_state(), timeout); + } + } + return 0; } \ No newline at end of file diff --git a/src/display/display-state-transition.h b/src/display/display-state-transition.h index e114326..eeead2f 100644 --- a/src/display/display-state-transition.h +++ b/src/display/display-state-transition.h @@ -40,5 +40,7 @@ void display_state_transition_update_display_state_timeout_by_priority(void); int display_state_transition_check_state_transition_condition(enum state_t cur_state, enum state_t next_state); int display_state_transition_update_lcdoff_reason(int source); bool display_state_transition_is_possible_to_go_lcdoff(void); +int display_state_transition_do_state_transition(enum state_t state, int evt_type); +bool display_state_transition_is_display_state_support_transition(enum state_t state); #endif /* __DISPLAY_STATE_TRANSITION_H__ */ \ No newline at end of file diff --git a/src/display/plugin-common/poll.c b/src/display/plugin-common/poll.c index 769c6d4..d9f1d1d 100644 --- a/src/display/plugin-common/poll.c +++ b/src/display/plugin-common/poll.c @@ -30,6 +30,7 @@ #include "poll.h" #include "display-ops.h" #include "display-plugin.h" +#include "display-state-transition.h" #include "shared/plugin.h" static PMMsg recv_data; @@ -74,7 +75,7 @@ static int __pm_lock_internal(pid_t pid, int s_bits, int flag, int timeout) if (cond < 0) return cond; - if (!display_plugin_state_is_there_default_trans(cond)) + if (!display_state_transition_is_display_state_support_transition(cond)) return -ENOTSUP; cond = SET_COND_REQUEST(cond, PM_REQUEST_LOCK); @@ -103,7 +104,7 @@ static int __pm_unlock_internal(pid_t pid, int s_bits, int flag) if (cond < 0) return cond; - if (!display_plugin_state_is_there_default_trans(cond)) + if (!display_state_transition_is_display_state_support_transition(cond)) return -ENOTSUP; cond = SET_COND_REQUEST(cond, PM_REQUEST_UNLOCK); @@ -138,7 +139,7 @@ static int __pm_change_internal(pid_t pid, int s_bits) return -ENOTSUP; } - if (!display_plugin_state_is_there_default_trans(cond)) + if (!display_state_transition_is_display_state_support_transition(cond)) return -ENOTSUP; cond = SET_COND_REQUEST(cond, PM_REQUEST_CHANGE); -- 2.7.4 From b5ee57b809a0da9fe219c048551abf9a4f46a68b Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 12 Jun 2023 17:03:04 +0900 Subject: [PATCH 06/16] input: Remove unused code of input-dbus from plugin Change-Id: I28af8d7611c138eab106b748fea3d9efc38b5e90 Signed-off-by: Youngjae Cho --- plugins/iot-headless/input/input-dbus.c | 40 ------------------------------ plugins/iot-headless/input/input-dbus.h | 6 ----- plugins/iot-headless/input/input-handler.c | 1 - 3 files changed, 47 deletions(-) delete mode 100644 plugins/iot-headless/input/input-dbus.c delete mode 100644 plugins/iot-headless/input/input-dbus.h diff --git a/plugins/iot-headless/input/input-dbus.c b/plugins/iot-headless/input/input-dbus.c deleted file mode 100644 index 8b72583..0000000 --- a/plugins/iot-headless/input/input-dbus.c +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include -#include - -#include "shared/common.h" -#include "input-handler.h" -#include "core/log.h" - -static GVariant *dbus_emulate_key(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int keycode, keyvalue; - - g_variant_get(param, "(ii)", &keycode, &keyvalue); - - input_handler_process_key(keycode, keyvalue); - - return gdbus_new_g_variant_tuple(); -} - -static const dbus_method_s dbus_methods[] = { - { "EmulateKey", "ii", NULL, dbus_emulate_key }, -}; - -static const dbus_interface_u dbus_interface = { - .oh = NULL, - .name = DEVICED_INTERFACE_INPUT, - .methods = dbus_methods, - .nr_methods = ARRAY_SIZE(dbus_methods), -}; - -void init_input_dbus(void) -{ - int ret; - - ret = gdbus_add_object(NULL, DEVICED_PATH_INPUT, &dbus_interface); - if (ret < 0) - _W("Failed to init plugin iot-headless input dbus interface(%d)", ret); -} diff --git a/plugins/iot-headless/input/input-dbus.h b/plugins/iot-headless/input/input-dbus.h deleted file mode 100644 index 1be58c4..0000000 --- a/plugins/iot-headless/input/input-dbus.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __INPUT_DBUS_H__ -#define __INPUT_DBUS_H__ - -void init_input_dbus(void); - -#endif //__INPUT_DBUS_H__ diff --git a/plugins/iot-headless/input/input-handler.c b/plugins/iot-headless/input/input-handler.c index 2f02aa5..c332d32 100644 --- a/plugins/iot-headless/input/input-handler.c +++ b/plugins/iot-headless/input/input-handler.c @@ -30,7 +30,6 @@ #include "shared/event.h" #include "input-config.h" -#include "input-dbus.h" #include "input/input.h" static int input_event_handler_id; -- 2.7.4 From e4a5f20676cb9b32e0735c1e28f6b8185a5d8265 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Mon, 12 Jun 2023 20:43:41 +0900 Subject: [PATCH 07/16] display: Remove lcd_on_expired()/stop_lock_timer()/check_lock_screen() These functions are used when the EVENT_INPUT occurs from the below situation, S_SLEEP/S_LCDOFF --> EVENT_INPUT --> S_NORMAL check_lock_screen() checks lock_screen state, If lock_screen is not launched, this adds timeout callback for lcd_on_procedure(). stop_lock_timer() removes callback from above description. lcd_on_expired() is callback for lcd_on_procedure() after timeout. Simply, that functions checks lock screen status, and then If lock screen is not launched, go to lcd_on_procedure after timeout value. However, according to the default_action code logic, it goes to lcd_on_procedure() regardless of check_lock_screen(). Also, meaningless lcd_on_procedure() call occurs. Thus, lcd_on_expired()/stop_lock_timer()/check_lock_screen() is removed. Change-Id: Ie82889e951678260ac10e1b7c86546040aff3fc8 Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 55 +-------------------------------------- plugins/mobile/display/core.c | 55 +-------------------------------------- plugins/tv/display/core.c | 55 +-------------------------------------- plugins/wearable/display/core.c | 55 +-------------------------------------- 4 files changed, 4 insertions(+), 216 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 74eb8fd..240eb3b 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -100,7 +100,6 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; static int system_wakeup_flag = false; static char *custom_change_name; -static guint lock_timeout_id; static struct timeval lcdon_tv; /* * The two variables(lcdon_broadcast, pmstate_suspend) must be set initial @@ -723,51 +722,6 @@ static void sig_hup(int signo) pm_save_logdump(); } -static gboolean lcd_on_expired(void *data) -{ - int lock_state, ret; - - if (lock_timeout_id) - lock_timeout_id = 0; - - /* check state of lock */ - ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); - if (ret > 0 && lock_state == VCONFKEY_IDLE_LOCK) - return G_SOURCE_REMOVE; - else if (ret < 0) - _E("Failed to get vconf value for idle lock state: %d", vconf_get_ext_errno()); - - /* lock screen is not launched yet, but lcd is on */ - if (check_lcd_is_on() == false) - lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); - - return G_SOURCE_REMOVE; -} - -static inline void stop_lock_timer(void) -{ - if (lock_timeout_id) { - g_source_remove(lock_timeout_id); - lock_timeout_id = 0; - } -} - -static void check_lock_screen(void) -{ - int lock_state, ret; - - stop_lock_timer(); - - /* check state of lock */ - ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); - if (ret < 0 || lock_state == VCONFKEY_IDLE_LOCK) - return; - - /* Use time to check lock is done. */ - lock_timeout_id = g_timeout_add(display_conf.lock_wait_time, - lcd_on_expired, NULL); -} - /* default enter action function */ static int default_action(int timeout) { @@ -826,9 +780,7 @@ static int default_action(int timeout) * normal state : backlight on and restore * the previous brightness */ - if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) - check_lock_screen(); - else if (get_pm_old_state() == S_LCDDIM) + if (get_pm_old_state() == S_LCDDIM) display_backlight_update_by_default_brightness(); if (check_lcd_is_on() == false) @@ -850,7 +802,6 @@ static int default_action(int timeout) case S_LCDOFF: if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { - stop_lock_timer(); /* lcd off state : turn off the backlight */ if (display_panel_get_dpms_cached_state() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); @@ -863,9 +814,6 @@ static int default_action(int timeout) break; case S_SLEEP: - if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) - stop_lock_timer(); - if (display_panel_get_dpms_cached_state() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); @@ -1015,7 +963,6 @@ static int update_setting(int key_idx, int val) display_panel_get_dpms_cached_state() != DPMS_ON && is_lcdon_blocked() == LCDON_BLOCK_NONE) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); - stop_lock_timer(); display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 6d1244d..51daaac 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -102,7 +102,6 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; static int system_wakeup_flag = false; static char *custom_change_name; -static guint lock_timeout_id; static struct timeval lcdon_tv; /* * The two variables(lcdon_broadcast, pmstate_suspend) must be set initial @@ -733,51 +732,6 @@ static void sig_hup(int signo) pm_save_logdump(); } -static gboolean lcd_on_expired(void *data) -{ - int lock_state, ret; - - if (lock_timeout_id) - lock_timeout_id = 0; - - /* check state of lock */ - ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); - if (ret > 0 && lock_state == VCONFKEY_IDLE_LOCK) - return G_SOURCE_REMOVE; - else if (ret < 0) - _E("Failed to get vconf value for idle lock state: %d", vconf_get_ext_errno()); - - /* lock screen is not launched yet, but lcd is on */ - if (check_lcd_is_on() == false) - lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); - - return G_SOURCE_REMOVE; -} - -static inline void stop_lock_timer(void) -{ - if (lock_timeout_id) { - g_source_remove(lock_timeout_id); - lock_timeout_id = 0; - } -} - -static void check_lock_screen(void) -{ - int lock_state, ret; - - stop_lock_timer(); - - /* check state of lock */ - ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); - if (ret < 0 || lock_state == VCONFKEY_IDLE_LOCK) - return; - - /* Use time to check lock is done. */ - lock_timeout_id = g_timeout_add(display_conf.lock_wait_time, - lcd_on_expired, NULL); -} - /* default enter action function */ static int default_action(int timeout) { @@ -836,9 +790,7 @@ static int default_action(int timeout) * normal state : backlight on and restore * the previous brightness */ - if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) - check_lock_screen(); - else if (get_pm_old_state() == S_LCDDIM) + if (get_pm_old_state() == S_LCDDIM) display_backlight_update_by_default_brightness(); if (check_lcd_is_on() == false) @@ -860,7 +812,6 @@ static int default_action(int timeout) case S_LCDOFF: if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { - stop_lock_timer(); /* lcd off state : turn off the backlight */ if (display_panel_get_dpms_cached_state() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); @@ -873,9 +824,6 @@ static int default_action(int timeout) break; case S_SLEEP: - if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) - stop_lock_timer(); - if (display_panel_get_dpms_cached_state() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); @@ -1025,7 +973,6 @@ static int update_setting(int key_idx, int val) display_panel_get_dpms_cached_state() != DPMS_ON && is_lcdon_blocked() == LCDON_BLOCK_NONE) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); - stop_lock_timer(); display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 33072ae..05826a9 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -100,7 +100,6 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; static int system_wakeup_flag = false; static char *custom_change_name; -static guint lock_timeout_id; static struct timeval lcdon_tv; /* * The two variables(lcdon_broadcast, pmstate_suspend) must be set initial @@ -723,51 +722,6 @@ static void sig_hup(int signo) pm_save_logdump(); } -static gboolean lcd_on_expired(void *data) -{ - int lock_state, ret; - - if (lock_timeout_id) - lock_timeout_id = 0; - - /* check state of lock */ - ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); - if (ret > 0 && lock_state == VCONFKEY_IDLE_LOCK) - return G_SOURCE_REMOVE; - else if (ret < 0) - _E("Failed to get vconf value for idle lock state: %d", vconf_get_ext_errno()); - - /* lock screen is not launched yet, but lcd is on */ - if (check_lcd_is_on() == false) - lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); - - return G_SOURCE_REMOVE; -} - -static inline void stop_lock_timer(void) -{ - if (lock_timeout_id) { - g_source_remove(lock_timeout_id); - lock_timeout_id = 0; - } -} - -static void check_lock_screen(void) -{ - int lock_state, ret; - - stop_lock_timer(); - - /* check state of lock */ - ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); - if (ret < 0 || lock_state == VCONFKEY_IDLE_LOCK) - return; - - /* Use time to check lock is done. */ - lock_timeout_id = g_timeout_add(display_conf.lock_wait_time, - lcd_on_expired, NULL); -} - /* default enter action function */ static int default_action(int timeout) { @@ -826,9 +780,7 @@ static int default_action(int timeout) * normal state : backlight on and restore * the previous brightness */ - if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) - check_lock_screen(); - else if (get_pm_old_state() == S_LCDDIM) + if (get_pm_old_state() == S_LCDDIM) display_backlight_update_by_default_brightness(); if (check_lcd_is_on() == false) @@ -850,7 +802,6 @@ static int default_action(int timeout) case S_LCDOFF: if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { - stop_lock_timer(); /* lcd off state : turn off the backlight */ if (display_panel_get_dpms_cached_state() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); @@ -863,9 +814,6 @@ static int default_action(int timeout) break; case S_SLEEP: - if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) - stop_lock_timer(); - if (display_panel_get_dpms_cached_state() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); @@ -1015,7 +963,6 @@ static int update_setting(int key_idx, int val) display_panel_get_dpms_cached_state() != DPMS_ON && is_lcdon_blocked() == LCDON_BLOCK_NONE) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); - stop_lock_timer(); display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index de873cb..a47192f 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -112,7 +112,6 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; static int system_wakeup_flag = false; static char *custom_change_name; -static guint lock_timeout_id; static guint transit_timer; static struct timeval lcdon_tv; /* @@ -1119,51 +1118,6 @@ static int default_trans(int evt) return 0; } -static gboolean lcd_on_expired(void *data) -{ - int lock_state, ret; - - if (lock_timeout_id) - lock_timeout_id = 0; - - /* check state of lock */ - ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); - if (ret > 0 && lock_state == VCONFKEY_IDLE_LOCK) - return G_SOURCE_REMOVE; - else if (ret < 0) - _E("Failed to get vconf value for idle lock state: %d", vconf_get_ext_errno()); - - /* lock screen is not launched yet, but lcd is on */ - if (check_lcd_is_on() == false) - lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); - - return G_SOURCE_REMOVE; -} - -static inline void stop_lock_timer(void) -{ - if (lock_timeout_id) { - g_source_remove(lock_timeout_id); - lock_timeout_id = 0; - } -} - -static void check_lock_screen(void) -{ - int lock_state, ret; - - stop_lock_timer(); - - /* check state of lock */ - ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); - if (ret < 0 || lock_state == VCONFKEY_IDLE_LOCK) - return; - - /* Use time to check lock is done. */ - lock_timeout_id = g_timeout_add(display_conf.lock_wait_time, - lcd_on_expired, NULL); -} - /* default enter action function */ static int default_action(int timeout) { @@ -1234,9 +1188,7 @@ static int default_action(int timeout) * normal state : backlight on and restore * the previous brightness */ - if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) - check_lock_screen(); - else if (get_pm_old_state() == S_LCDDIM) + if (get_pm_old_state() == S_LCDDIM) display_backlight_update_by_default_brightness(); if (check_lcd_is_on() == false) @@ -1258,7 +1210,6 @@ static int default_action(int timeout) case S_LCDOFF: if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { - stop_lock_timer(); /* lcd off state : turn off the backlight */ if (display_panel_get_dpms_cached_state() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); @@ -1271,9 +1222,6 @@ static int default_action(int timeout) break; case S_SLEEP: - if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) - stop_lock_timer(); - if (display_panel_get_dpms_cached_state() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); @@ -1421,7 +1369,6 @@ static int update_setting(int key_idx, int val) display_panel_get_dpms_cached_state() != DPMS_ON && is_lcdon_blocked() == LCDON_BLOCK_NONE) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); - stop_lock_timer(); display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) states[get_pm_cur_state()].trans(EVENT_INPUT); -- 2.7.4 From eb986c8d42dd107f15cfb14b4ac7220d79fcc455 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Mon, 12 Jun 2023 21:46:48 +0900 Subject: [PATCH 08/16] display: Relocate touch_event_blocked() touch_event_blocked() checks touch event blocking during lcd_on/off_procedure(). For relocating lcd_on/off_procedure(), touch_event_blocked() is also relocated. This functions are added below display-misc. - int display_misc_set_touch_event_blocked(bool blocked); - bool display_misc_is_touch_event_blocked(void); -> This replaces touch_event_blocked() Change-Id: Icaa609ad4a4e168663dd85556dea2c448b5747bd Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 11 ++--------- plugins/iot-headed/display/key-filter.c | 3 ++- plugins/mobile/display/core.c | 11 ++--------- plugins/mobile/display/key-filter.c | 3 ++- plugins/tv/display/core.c | 11 ++--------- plugins/tv/display/key-filter.c | 3 ++- plugins/wearable/display/core.c | 11 ++--------- plugins/wearable/display/key-filter.c | 3 ++- src/display/core.h | 1 - src/display/display-misc.c | 12 ++++++++++++ src/display/display-misc.h | 2 ++ 11 files changed, 30 insertions(+), 41 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 240eb3b..772b225 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -107,8 +107,6 @@ static struct timeval lcdon_tv; */ static bool lcdon_broadcast = true; -static bool touch_blocked = false; - /* default transition, action fuctions */ static int default_action(int timeout); @@ -201,11 +199,6 @@ static const char* __device_flags_to_string(enum device_flags flags) return UNKNOWN_STR; } -bool touch_event_blocked(void) -{ - return touch_blocked; -} - void lcd_on_procedure(int state, enum device_flags flag) { unsigned long flags = NORMAL_MODE; @@ -252,7 +245,7 @@ void lcd_on_procedure(int state, enum device_flags flag) touchled_control_backlight(TOUCHLED_DIRECT_ON); - touch_blocked = false; + display_misc_set_touch_event_blocked(false); } inline void lcd_off_procedure(enum device_flags flag) @@ -285,7 +278,7 @@ inline void lcd_off_procedure(enum device_flags flag) /* operation */ - touch_blocked = true; + display_misc_set_touch_event_blocked(true); set_setting_pmstate(S_LCDOFF); diff --git a/plugins/iot-headed/display/key-filter.c b/plugins/iot-headed/display/key-filter.c index 5361e0e..e0e0ae9 100644 --- a/plugins/iot-headed/display/key-filter.c +++ b/plugins/iot-headed/display/key-filter.c @@ -37,6 +37,7 @@ #include "display-backlight.h" #include "display-ops.h" #include "display-config.h" +#include "display-misc.h" #include "display-state-transition.h" #include "shared/common.h" #include "shared/devices.h" @@ -693,7 +694,7 @@ static void check_key_filter(struct timeval time, unsigned short type, unsigned ignore = false; break; case EV_ABS: - if (touch_event_blocked() + if (display_misc_is_touch_event_blocked() && !g_display_plugin.config->touch_wakeup && pinput->value == KEY_BEING_PRESSED) return; diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 51daaac..5206550 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -109,8 +109,6 @@ static struct timeval lcdon_tv; */ static bool lcdon_broadcast = true; -static bool touch_blocked = false; - /* default transition, action fuctions */ static int default_action(int timeout); @@ -208,11 +206,6 @@ static const char* __device_flags_to_string(enum device_flags flags) return UNKNOWN_STR; } -bool touch_event_blocked(void) -{ - return touch_blocked; -} - void lcd_on_procedure(int state, enum device_flags flag) { unsigned long flags = NORMAL_MODE; @@ -259,7 +252,7 @@ void lcd_on_procedure(int state, enum device_flags flag) touchled_control_backlight(TOUCHLED_DIRECT_ON); - touch_blocked = false; + display_misc_set_touch_event_blocked(false); } inline void lcd_off_procedure(enum device_flags flag) @@ -292,7 +285,7 @@ inline void lcd_off_procedure(enum device_flags flag) /* operation */ - touch_blocked = true; + display_misc_set_touch_event_blocked(true); set_setting_pmstate(S_LCDOFF); diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index 65a0de2..11d6dfb 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -37,6 +37,7 @@ #include "display-backlight.h" #include "display-ops.h" #include "display-config.h" +#include "display-misc.h" #include "display-state-transition.h" #include "shared/common.h" #include "shared/devices.h" @@ -720,7 +721,7 @@ static void check_key_filter(struct timeval time, unsigned short type, unsigned ignore = false; break; case EV_ABS: - if (touch_event_blocked() + if (display_misc_is_touch_event_blocked() && !g_display_plugin.config->touch_wakeup && pinput->value == KEY_BEING_PRESSED) return; diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 05826a9..a66afaa 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -107,8 +107,6 @@ static struct timeval lcdon_tv; */ static bool lcdon_broadcast = true; -static bool touch_blocked = false; - /* default transition, action fuctions */ static int default_action(int timeout); @@ -201,11 +199,6 @@ static const char* __device_flags_to_string(enum device_flags flags) return UNKNOWN_STR; } -bool touch_event_blocked(void) -{ - return touch_blocked; -} - void lcd_on_procedure(int state, enum device_flags flag) { unsigned long flags = NORMAL_MODE; @@ -252,7 +245,7 @@ void lcd_on_procedure(int state, enum device_flags flag) touchled_control_backlight(TOUCHLED_DIRECT_ON); - touch_blocked = false; + display_misc_set_touch_event_blocked(false); } inline void lcd_off_procedure(enum device_flags flag) @@ -285,7 +278,7 @@ inline void lcd_off_procedure(enum device_flags flag) /* operation */ - touch_blocked = true; + display_misc_set_touch_event_blocked(true); set_setting_pmstate(S_LCDOFF); diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index 6a44187..50fb6d6 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -37,6 +37,7 @@ #include "display-backlight.h" #include "display-ops.h" #include "display-config.h" +#include "display-misc.h" #include "display-state-transition.h" #include "shared/common.h" #include "shared/devices.h" @@ -687,7 +688,7 @@ static void check_key_filter(struct timeval time, unsigned short type, unsigned ignore = false; break; case EV_ABS: - if (touch_event_blocked() + if (display_misc_is_touch_event_blocked() && !g_display_plugin.config->touch_wakeup && pinput->value == KEY_BEING_PRESSED) return; diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index a47192f..5a8f2bf 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -120,8 +120,6 @@ static struct timeval lcdon_tv; */ static bool lcdon_broadcast = true; -static bool touch_blocked = false; - /* default transition, action fuctions */ static int default_trans(int evt); static int default_action(int timeout); @@ -452,11 +450,6 @@ static int get_device_flags(unsigned long *device_flags) return 0; } -bool touch_event_blocked(void) -{ - return touch_blocked; -} - static gboolean late_transit_on(void *data) { if (!transit_timer) @@ -532,7 +525,7 @@ void lcd_on_procedure(int state, enum device_flags flag) lcdon_broadcast = true; } - touch_blocked = false; + display_misc_set_touch_event_blocked(false); } inline void lcd_off_procedure(enum device_flags flag) @@ -565,7 +558,7 @@ inline void lcd_off_procedure(enum device_flags flag) /* operation */ - touch_blocked = true; + display_misc_set_touch_event_blocked(true); if (flags & AMBIENT_MODE) { if (ambient_get_state() == true) diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index 2658612..701041a 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -37,6 +37,7 @@ #include "display-panel.h" #include "display-backlight.h" #include "display-config.h" +#include "display-misc.h" #include "display-state-transition.h" #include "shared/common.h" #include "shared/devices.h" @@ -647,7 +648,7 @@ static void check_key_filter(struct timeval time, unsigned short type, unsigned ignore = false; break; case EV_ABS: - if (touch_event_blocked() && !ambient_get_state() + if (display_misc_is_touch_event_blocked() && !ambient_get_state() && !g_display_plugin.config->touch_wakeup && pinput->value == KEY_BEING_PRESSED) return; diff --git a/src/display/core.h b/src/display/core.h index 6a11082..0b5d791 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -130,7 +130,6 @@ int custom_lcdon(int timeout); void lcd_on_direct(enum device_flags flags); void lcd_on_procedure(int state, enum device_flags flag); void lcd_off_procedure(enum device_flags flag); -bool touch_event_blocked(void); void broadcast_lcd_off_late(enum device_flags flags); /* auto-brightness.c */ diff --git a/src/display/display-misc.c b/src/display/display-misc.c index ec3cc91..e1d02af 100644 --- a/src/display/display-misc.c +++ b/src/display/display-misc.c @@ -38,6 +38,7 @@ #include "poll.h" static bool stay_touchscreen_off = false; +static bool touch_event_blocked = false; /* FIXME: This fucntion should be relocated under the battery module */ bool display_misc_is_low_battery_state(int val) @@ -97,6 +98,17 @@ void display_misc_get_stay_touchscreen_off(bool *on) *on = stay_touchscreen_off; } +int display_misc_set_touch_event_blocked(bool blocked) +{ + touch_event_blocked = blocked; + return 0; +} + +bool display_misc_is_touch_event_blocked(void) +{ + return touch_event_blocked; +} + /* FIXME: This fucntion should be relocated under the battery module or redefined */ static int changed_battery_health(void *data) { diff --git a/src/display/display-misc.h b/src/display/display-misc.h index 3176350..e213f81 100644 --- a/src/display/display-misc.h +++ b/src/display/display-misc.h @@ -34,5 +34,7 @@ void display_misc_get_stay_touchscreen_off(bool *on); void display_misc_register_battery_health_notifier(void); void display_misc_unregister_battery_health_notifier(void); void display_misc_save_display_log(const char *path); +int display_misc_set_touch_event_blocked(bool blocked); +bool display_misc_is_touch_event_blocked(void); #endif /* __DISPLAY_MISC_H__ */ \ No newline at end of file -- 2.7.4 From df74a37e72e8caa1ec5a4cf5fb5a453770c80210 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Tue, 13 Jun 2023 11:00:03 +0900 Subject: [PATCH 09/16] display: Relocate lcd_on/off_procedure() lcd_on/off_procedure() rules are same in all plugins except wearable. Thus, duplicated codes are removed and relocated to display-panel. These functions are added below display-panel. - void display_panel_lcd_on_procedure(int state, enum device_flags flag); -> This replaces lcd_on_procedure(), it works to turn on lcd. - void display_panel_lcd_off_procedure(enum device_flags flag); -> This replaces lcd_off_procedure(), it works to turn off lcd. - bool display_panel_is_lcd_on_state_broadcasted(void); -> With this, It is possible to know if the lcd_on/off_procedure() done. This is used as flag of lcd on/off process. This function is added below display-plugin. - int display_plugin_lcd_off_procedure(enum device_flags flag); -> This is for wearable plugin, there is lcd_off_procedure() use case in the key-filter.c Change-Id: I1a7f8268df4d45d0585fe7c8a93981cc7be4268c Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 129 ++++--------------------------- plugins/iot-headed/display/key-filter.c | 2 +- plugins/mobile/display/core.c | 131 +++++--------------------------- plugins/mobile/display/key-filter.c | 2 +- plugins/tv/display/core.c | 129 ++++--------------------------- plugins/tv/display/key-filter.c | 2 +- plugins/wearable/display/core.c | 5 +- plugins/wearable/display/key-filter.c | 2 +- src/display/core.h | 2 - src/display/display-panel.c | 107 +++++++++++++++++++++++++- src/display/display-panel.h | 3 + src/display/display-plugin.c | 10 +++ src/display/display-plugin.h | 2 + 13 files changed, 176 insertions(+), 350 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 772b225..6d0393a 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -101,11 +101,6 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; static int system_wakeup_flag = false; static char *custom_change_name; static struct timeval lcdon_tv; -/* - * The two variables(lcdon_broadcast, pmstate_suspend) must be set initial - * state because it should be sent from previous state at booting time. - */ -static bool lcdon_broadcast = true; /* default transition, action fuctions */ static int default_action(int timeout); @@ -199,99 +194,6 @@ static const char* __device_flags_to_string(enum device_flags flags) return UNKNOWN_STR; } -void lcd_on_procedure(int state, enum device_flags flag) -{ - unsigned long flags = NORMAL_MODE; - display_plugin_get_device_flags(&flags); - flags |= flag; - - /* - * Display on procedure - * step 1. leave doze - * step 2. broadcast lcd on signal with cause - * step 3. set brightness - * step 4. set pmstate of vconf - * step 5. display on operate - * - a. display on - * - b. TSP(touch screen) and touchkey enable - * step 6. broadcast lcd on complete signal - * step 7. key backlight enable - */ - leave_doze(); - - _I("[lcdstep] 0x%lx", flags); - - /* send LCDOn dbus signal */ - if (!lcdon_broadcast) - broadcast_lcd_on(SIGNAL_PRE, flags); - - /* Update brightness level */ - if (state == LCD_DIM) - display_backlight_set_brightness_by_dim_brightness(); - else if (state == LCD_NORMAL) - display_backlight_update_by_default_brightness(); - - if (state == LCD_NORMAL) - set_setting_pmstate(S_NORMAL); - else if (state == LCD_DIM) - set_setting_pmstate(S_LCDDIM); - - display_start_dependent_device(flags); - - if (!lcdon_broadcast) { - broadcast_lcd_on(SIGNAL_POST, flags); - lcdon_broadcast = true; - } - - touchled_control_backlight(TOUCHLED_DIRECT_ON); - - display_misc_set_touch_event_blocked(false); -} - -inline void lcd_off_procedure(enum device_flags flag) -{ - unsigned long flags = NORMAL_MODE; - display_plugin_get_device_flags(&flags); - flags |= flag; - - /* - * Display off procedure - * step 0. enhance mode off using nofity (e.g mdnie, HBM, LBM) - * step 1. broadcast lcd off signal with cause - * step 2. set pmstate of vconf - * step 3. display off operate - * - a. display off - * - b. TSP(touch screen) and touchkey disable - * step 4. broadcast lcd off complete siganl - * step 5. enter doze mode if it is enabled - */ - _I("[lcdstep] 0x%lx", flags); - - /* notification */ - - device_notify(DEVICE_NOTIFIER_LCD_OFF, NULL); - - if (lcdon_broadcast) { - broadcast_lcd_off(SIGNAL_PRE, flags); - lcdon_broadcast = false; - } - - /* operation */ - - display_misc_set_touch_event_blocked(true); - - set_setting_pmstate(S_LCDOFF); - - touchled_control_backlight(TOUCHLED_DIRECT_OFF); - - display_stop_dependent_device(flags); - - broadcast_lcd_off(SIGNAL_POST, flags); - device_notify(DEVICE_NOTIFIER_LCD_OFF_COMPLETE, NULL); - - enter_doze(); -} - static void update_display_locktime(int time) { display_state_transition_set_lock_screen_timeout(time); @@ -314,7 +216,7 @@ void lcd_on_direct(enum device_flags flags) _D("lcd is on directly"); gettimeofday(&lcdon_tv, NULL); - lcd_on_procedure(LCD_NORMAL, flags); + display_panel_lcd_on_procedure(LCD_NORMAL, flags); update_display_locktime(LOCK_SCREEN_INPUT_TIMEOUT); } @@ -395,7 +297,7 @@ int custom_lcdoff(enum device_flags flag) _I("custom lcd off by flag(%d)", flag); if (display_panel_get_dpms_cached_state() == DPMS_ON) - lcd_off_procedure(flag); + display_panel_lcd_off_procedure(flag); if (set_custom_lcdon_timeout(0) == true) display_state_transition_update_display_state_timeout_by_priority(); @@ -483,7 +385,7 @@ int display_off_by_reason(const char *reason) _I("platform lcd off by %s", reason); if (display_panel_get_dpms_cached_state() == DPMS_ON) - lcd_off_procedure(flag); + display_panel_lcd_off_procedure(flag); /* state transition */ set_pm_old_state(get_pm_cur_state()); @@ -533,7 +435,7 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) break; case S_LCDOFF: if (display_panel_get_dpms_cached_state() == DPMS_ON) - lcd_off_procedure(LCD_OFF_BY_EVENT); + display_panel_lcd_off_procedure(LCD_OFF_BY_EVENT); if (set_custom_lcdon_timeout(0)) display_state_transition_update_display_state_timeout_by_priority(); default_proc_change_state_action(next, -1); @@ -546,7 +448,7 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) delete_condition(S_NORMAL); delete_condition(S_LCDDIM); delete_condition(S_LCDOFF); - if (lcdon_broadcast) { + if (display_panel_is_lcd_on_state_broadcasted()) { _I("broadcast lcd off signal at non-lcd device"); broadcast_lcd_off(SIGNAL_PRE, 0); broadcast_lcd_off(SIGNAL_POST, 0); @@ -777,7 +679,7 @@ static int default_action(int timeout) display_backlight_update_by_default_brightness(); if (check_lcd_is_on() == false) - lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); + display_panel_lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); break; case S_LCDDIM: @@ -790,25 +692,25 @@ static int default_action(int timeout) display_backlight_set_brightness_by_dim_brightness(); if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) - lcd_on_procedure(LCD_DIM, NORMAL_MODE); + display_panel_lcd_on_procedure(LCD_DIM, NORMAL_MODE); break; case S_LCDOFF: if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { /* lcd off state : turn off the backlight */ if (display_panel_get_dpms_cached_state() == DPMS_ON) - lcd_off_procedure(LCD_OFF_BY_TIMEOUT); + display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); } display_panel_get_lcd_paneloff_mode(&lcd_paneloff_mode); if (display_panel_get_dpms_cached_state() == DPMS_ON || lcd_paneloff_mode) - lcd_off_procedure(LCD_OFF_BY_TIMEOUT); + display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); break; case S_SLEEP: if (display_panel_get_dpms_cached_state() == DPMS_ON) - lcd_off_procedure(LCD_OFF_BY_TIMEOUT); + display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); if (!pm_get_power_lock_support()) { /* sleep state : set system mode to SUSPEND */ @@ -955,7 +857,7 @@ static int update_setting(int key_idx, int val) val == VCONFKEY_IDLE_LOCK && display_panel_get_dpms_cached_state() != DPMS_ON && is_lcdon_blocked() == LCDON_BLOCK_NONE) - lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); + display_panel_lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); @@ -1186,7 +1088,7 @@ static gboolean delayed_dpms_init_done(gpointer data) switch (get_pm_cur_state()) { case S_NORMAL: case S_LCDDIM: - lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); + display_panel_lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); if (display_conf.timeout_enable) { timeout = states[S_NORMAL].timeout; /* check minimun lcd on time */ @@ -1196,7 +1098,7 @@ static gboolean delayed_dpms_init_done(gpointer data) } break; case S_LCDOFF: - lcd_off_procedure(LCD_OFF_BY_EVENT); + display_panel_lcd_off_procedure(LCD_OFF_BY_EVENT); timeout = display_conf.lcdoff_timeout; display_state_transition_reset_state_transition_timeout(timeout); break; @@ -1235,6 +1137,7 @@ static int display_probe(void *data) setup_display_plugin_backlight_ops(dp); dp->set_dim_state = NULL; dp->get_device_flags = NULL; + dp->lcd_off_procedure = NULL; setup_display_plugin_backlight_ops(dp); /* check display feature */ @@ -1417,9 +1320,9 @@ static void display_init(void *data) // wm_ready = check_wm_ready(); if (display_panel_init_dpms()) { if (is_lcdon_blocked() != LCDON_BLOCK_NONE) - lcd_off_procedure(LCD_OFF_BY_EVENT); + display_panel_lcd_off_procedure(LCD_OFF_BY_EVENT); else - lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); + display_panel_lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); } else { add_timer_for_dpms_init(); } diff --git a/plugins/iot-headed/display/key-filter.c b/plugins/iot-headed/display/key-filter.c index e0e0ae9..c6aa7d1 100644 --- a/plugins/iot-headed/display/key-filter.c +++ b/plugins/iot-headed/display/key-filter.c @@ -229,7 +229,7 @@ static inline void switch_off_lcd(void) broadcast_lcdoff_by_powerkey(); - lcd_off_procedure(LCD_OFF_BY_POWER_KEY); + display_panel_lcd_off_procedure(LCD_OFF_BY_POWER_KEY); } static void check_key_combination(struct input_event *pinput) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 5206550..f7732c4 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -103,11 +103,6 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; static int system_wakeup_flag = false; static char *custom_change_name; static struct timeval lcdon_tv; -/* - * The two variables(lcdon_broadcast, pmstate_suspend) must be set initial - * state because it should be sent from previous state at booting time. - */ -static bool lcdon_broadcast = true; /* default transition, action fuctions */ static int default_action(int timeout); @@ -206,99 +201,6 @@ static const char* __device_flags_to_string(enum device_flags flags) return UNKNOWN_STR; } -void lcd_on_procedure(int state, enum device_flags flag) -{ - unsigned long flags = NORMAL_MODE; - display_plugin_get_device_flags(&flags); - flags |= flag; - - /* - * Display on procedure - * step 1. leave doze - * step 2. broadcast lcd on signal with cause - * step 3. set brightness - * step 4. set pmstate of vconf - * step 5. display on operate - * - a. display on - * - b. TSP(touch screen) and touchkey enable - * step 6. broadcast lcd on complete signal - * step 7. key backlight enable - */ - leave_doze(); - - _I("[lcdstep] 0x%lx", flags); - - /* send LCDOn dbus signal */ - if (!lcdon_broadcast) - broadcast_lcd_on(SIGNAL_PRE, flags); - - /* Update brightness level */ - if (state == LCD_DIM) - display_backlight_set_brightness_by_dim_brightness(); - else if (state == LCD_NORMAL) - display_backlight_update_by_default_brightness(); - - if (state == LCD_NORMAL) - set_setting_pmstate(S_NORMAL); - else if (state == LCD_DIM) - set_setting_pmstate(S_LCDDIM); - - display_start_dependent_device(flags); - - if (!lcdon_broadcast) { - broadcast_lcd_on(SIGNAL_POST, flags); - lcdon_broadcast = true; - } - - touchled_control_backlight(TOUCHLED_DIRECT_ON); - - display_misc_set_touch_event_blocked(false); -} - -inline void lcd_off_procedure(enum device_flags flag) -{ - unsigned long flags = NORMAL_MODE; - display_plugin_get_device_flags(&flags); - flags |= flag; - - /* - * Display off procedure - * step 0. enhance mode off using nofity (e.g mdnie, HBM, LBM) - * step 1. broadcast lcd off signal with cause - * step 2. set pmstate of vconf - * step 3. display off operate - * - a. display off - * - b. TSP(touch screen) and touchkey disable - * step 4. broadcast lcd off complete siganl - * step 5. enter doze mode if it is enabled - */ - _I("[lcdstep] 0x%lx", flags); - - /* notification */ - - device_notify(DEVICE_NOTIFIER_LCD_OFF, NULL); - - if (lcdon_broadcast) { - broadcast_lcd_off(SIGNAL_PRE, flags); - lcdon_broadcast = false; - } - - /* operation */ - - display_misc_set_touch_event_blocked(true); - - set_setting_pmstate(S_LCDOFF); - - touchled_control_backlight(TOUCHLED_DIRECT_OFF); - - display_stop_dependent_device(flags); - - broadcast_lcd_off(SIGNAL_POST, flags); - device_notify(DEVICE_NOTIFIER_LCD_OFF_COMPLETE, NULL); - - enter_doze(); -} - static void update_display_locktime(int time) { display_state_transition_set_lock_screen_timeout(time); @@ -321,7 +223,7 @@ void lcd_on_direct(enum device_flags flags) _D("lcd is on directly"); gettimeofday(&lcdon_tv, NULL); - lcd_on_procedure(LCD_NORMAL, flags); + display_panel_lcd_on_procedure(LCD_NORMAL, flags); update_display_locktime(LOCK_SCREEN_INPUT_TIMEOUT); } @@ -402,7 +304,7 @@ int custom_lcdoff(enum device_flags flag) _I("custom lcd off by flag(%d)", flag); if (display_panel_get_dpms_cached_state() == DPMS_ON) - lcd_off_procedure(flag); + display_panel_lcd_off_procedure(flag); if (set_custom_lcdon_timeout(0) == true) display_state_transition_update_display_state_timeout_by_priority(); @@ -490,7 +392,7 @@ int display_off_by_reason(const char *reason) _I("platform lcd off by %s", reason); if (display_panel_get_dpms_cached_state() == DPMS_ON) - lcd_off_procedure(flag); + display_panel_lcd_off_procedure(flag); /* state transition */ set_pm_old_state(get_pm_cur_state()); @@ -541,9 +443,9 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) case S_LCDOFF: if (display_panel_get_dpms_cached_state() == DPMS_ON) { if (get_proximity_state() == SENSOR_PROXIMITY_NEAR) - lcd_off_procedure(LCD_OFF_BY_PROXIMITY); + display_panel_lcd_off_procedure(LCD_OFF_BY_PROXIMITY); else - lcd_off_procedure(LCD_OFF_BY_EVENT); + display_panel_lcd_off_procedure(LCD_OFF_BY_EVENT); } if (set_custom_lcdon_timeout(0)) display_state_transition_update_display_state_timeout_by_priority(); @@ -557,7 +459,7 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) delete_condition(S_NORMAL); delete_condition(S_LCDDIM); delete_condition(S_LCDOFF); - if (lcdon_broadcast) { + if (display_panel_is_lcd_on_state_broadcasted()) { _I("broadcast lcd off signal at non-lcd device"); broadcast_lcd_off(SIGNAL_PRE, 0); broadcast_lcd_off(SIGNAL_POST, 0); @@ -787,7 +689,7 @@ static int default_action(int timeout) display_backlight_update_by_default_brightness(); if (check_lcd_is_on() == false) - lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); + display_panel_lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); break; case S_LCDDIM: @@ -800,25 +702,25 @@ static int default_action(int timeout) display_backlight_set_brightness_by_dim_brightness(); if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) - lcd_on_procedure(LCD_DIM, NORMAL_MODE); + display_panel_lcd_on_procedure(LCD_DIM, NORMAL_MODE); break; case S_LCDOFF: if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { /* lcd off state : turn off the backlight */ if (display_panel_get_dpms_cached_state() == DPMS_ON) - lcd_off_procedure(LCD_OFF_BY_TIMEOUT); + display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); } display_panel_get_lcd_paneloff_mode(&lcd_paneloff_mode); if (display_panel_get_dpms_cached_state() == DPMS_ON || lcd_paneloff_mode) - lcd_off_procedure(LCD_OFF_BY_TIMEOUT); + display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); break; case S_SLEEP: if (display_panel_get_dpms_cached_state() == DPMS_ON) - lcd_off_procedure(LCD_OFF_BY_TIMEOUT); + display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); if (!pm_get_power_lock_support()) { /* sleep state : set system mode to SUSPEND */ @@ -965,7 +867,7 @@ static int update_setting(int key_idx, int val) val == VCONFKEY_IDLE_LOCK && display_panel_get_dpms_cached_state() != DPMS_ON && is_lcdon_blocked() == LCDON_BLOCK_NONE) - lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); + display_panel_lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); @@ -1196,7 +1098,7 @@ static gboolean delayed_dpms_init_done(gpointer data) switch (get_pm_cur_state()) { case S_NORMAL: case S_LCDDIM: - lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); + display_panel_lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); if (display_conf.timeout_enable) { timeout = states[S_NORMAL].timeout; /* check minimun lcd on time */ @@ -1206,7 +1108,7 @@ static gboolean delayed_dpms_init_done(gpointer data) } break; case S_LCDOFF: - lcd_off_procedure(LCD_OFF_BY_EVENT); + display_panel_lcd_off_procedure(LCD_OFF_BY_EVENT); timeout = display_conf.lcdoff_timeout; display_state_transition_reset_state_transition_timeout(timeout); break; @@ -1245,6 +1147,7 @@ static int display_probe(void *data) setup_display_plugin_backlight_ops(dp); dp->set_dim_state = NULL; dp->get_device_flags = NULL; + dp->lcd_off_procedure = NULL; setup_display_plugin_backlight_ops(dp); /** @@ -1423,9 +1326,9 @@ static void display_init(void *data) // wm_ready = check_wm_ready(); if (display_panel_init_dpms()) { if (is_lcdon_blocked() != LCDON_BLOCK_NONE) - lcd_off_procedure(LCD_OFF_BY_EVENT); + display_panel_lcd_off_procedure(LCD_OFF_BY_EVENT); else - lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); + display_panel_lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); } else { add_timer_for_dpms_init(); } diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index 11d6dfb..a8dbe81 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -219,7 +219,7 @@ static inline void switch_off_lcd(void) broadcast_lcdoff_by_powerkey(); - lcd_off_procedure(LCD_OFF_BY_POWER_KEY); + display_panel_lcd_off_procedure(LCD_OFF_BY_POWER_KEY); } static void check_key_combination(struct input_event *pinput) diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index a66afaa..e53409e 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -101,11 +101,6 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; static int system_wakeup_flag = false; static char *custom_change_name; static struct timeval lcdon_tv; -/* - * The two variables(lcdon_broadcast, pmstate_suspend) must be set initial - * state because it should be sent from previous state at booting time. - */ -static bool lcdon_broadcast = true; /* default transition, action fuctions */ static int default_action(int timeout); @@ -199,99 +194,6 @@ static const char* __device_flags_to_string(enum device_flags flags) return UNKNOWN_STR; } -void lcd_on_procedure(int state, enum device_flags flag) -{ - unsigned long flags = NORMAL_MODE; - display_plugin_get_device_flags(&flags); - flags |= flag; - - /* - * Display on procedure - * step 1. leave doze - * step 2. broadcast lcd on signal with cause - * step 3. set brightness - * step 4. set pmstate of vconf - * step 5. display on operate - * - a. display on - * - b. TSP(touch screen) and touchkey enable - * step 6. broadcast lcd on complete signal - * step 7. key backlight enable - */ - leave_doze(); - - _I("[lcdstep] 0x%lx", flags); - - /* send LCDOn dbus signal */ - if (!lcdon_broadcast) - broadcast_lcd_on(SIGNAL_PRE, flags); - - /* Update brightness level */ - if (state == LCD_DIM) - display_backlight_set_brightness_by_dim_brightness(); - else if (state == LCD_NORMAL) - display_backlight_update_by_default_brightness(); - - if (state == LCD_NORMAL) - set_setting_pmstate(S_NORMAL); - else if (state == LCD_DIM) - set_setting_pmstate(S_LCDDIM); - - display_start_dependent_device(flags); - - if (!lcdon_broadcast) { - broadcast_lcd_on(SIGNAL_POST, flags); - lcdon_broadcast = true; - } - - touchled_control_backlight(TOUCHLED_DIRECT_ON); - - display_misc_set_touch_event_blocked(false); -} - -inline void lcd_off_procedure(enum device_flags flag) -{ - unsigned long flags = NORMAL_MODE; - display_plugin_get_device_flags(&flags); - flags |= flag; - - /* - * Display off procedure - * step 0. enhance mode off using nofity (e.g mdnie, HBM, LBM) - * step 1. broadcast lcd off signal with cause - * step 2. set pmstate of vconf - * step 3. display off operate - * - a. display off - * - b. TSP(touch screen) and touchkey disable - * step 4. broadcast lcd off complete siganl - * step 5. enter doze mode if it is enabled - */ - _I("[lcdstep] 0x%lx", flags); - - /* notification */ - - device_notify(DEVICE_NOTIFIER_LCD_OFF, NULL); - - if (lcdon_broadcast) { - broadcast_lcd_off(SIGNAL_PRE, flags); - lcdon_broadcast = false; - } - - /* operation */ - - display_misc_set_touch_event_blocked(true); - - set_setting_pmstate(S_LCDOFF); - - touchled_control_backlight(TOUCHLED_DIRECT_OFF); - - display_stop_dependent_device(flags); - - broadcast_lcd_off(SIGNAL_POST, flags); - device_notify(DEVICE_NOTIFIER_LCD_OFF_COMPLETE, NULL); - - enter_doze(); -} - static void update_display_locktime(int time) { display_state_transition_set_lock_screen_timeout(time); @@ -314,7 +216,7 @@ void lcd_on_direct(enum device_flags flags) _D("lcd is on directly"); gettimeofday(&lcdon_tv, NULL); - lcd_on_procedure(LCD_NORMAL, flags); + display_panel_lcd_on_procedure(LCD_NORMAL, flags); update_display_locktime(LOCK_SCREEN_INPUT_TIMEOUT); } @@ -395,7 +297,7 @@ int custom_lcdoff(enum device_flags flag) _I("custom lcd off by flag(%d)", flag); if (display_panel_get_dpms_cached_state() == DPMS_ON) - lcd_off_procedure(flag); + display_panel_lcd_off_procedure(flag); if (set_custom_lcdon_timeout(0) == true) display_state_transition_update_display_state_timeout_by_priority(); @@ -483,7 +385,7 @@ int display_off_by_reason(const char *reason) _I("platform lcd off by %s", reason); if (display_panel_get_dpms_cached_state() == DPMS_ON) - lcd_off_procedure(flag); + display_panel_lcd_off_procedure(flag); /* state transition */ set_pm_old_state(get_pm_cur_state()); @@ -533,7 +435,7 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) break; case S_LCDOFF: if (display_panel_get_dpms_cached_state() == DPMS_ON) - lcd_off_procedure(LCD_OFF_BY_EVENT); + display_panel_lcd_off_procedure(LCD_OFF_BY_EVENT); if (set_custom_lcdon_timeout(0)) display_state_transition_update_display_state_timeout_by_priority(); default_proc_change_state_action(next, -1); @@ -546,7 +448,7 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) delete_condition(S_NORMAL); delete_condition(S_LCDDIM); delete_condition(S_LCDOFF); - if (lcdon_broadcast) { + if (display_panel_is_lcd_on_state_broadcasted()) { _I("broadcast lcd off signal at non-lcd device"); broadcast_lcd_off(SIGNAL_PRE, 0); broadcast_lcd_off(SIGNAL_POST, 0); @@ -777,7 +679,7 @@ static int default_action(int timeout) display_backlight_update_by_default_brightness(); if (check_lcd_is_on() == false) - lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); + display_panel_lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); break; case S_LCDDIM: @@ -790,25 +692,25 @@ static int default_action(int timeout) display_backlight_set_brightness_by_dim_brightness(); if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) - lcd_on_procedure(LCD_DIM, NORMAL_MODE); + display_panel_lcd_on_procedure(LCD_DIM, NORMAL_MODE); break; case S_LCDOFF: if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { /* lcd off state : turn off the backlight */ if (display_panel_get_dpms_cached_state() == DPMS_ON) - lcd_off_procedure(LCD_OFF_BY_TIMEOUT); + display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); } display_panel_get_lcd_paneloff_mode(&lcd_paneloff_mode); if (display_panel_get_dpms_cached_state() == DPMS_ON || lcd_paneloff_mode) - lcd_off_procedure(LCD_OFF_BY_TIMEOUT); + display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); break; case S_SLEEP: if (display_panel_get_dpms_cached_state() == DPMS_ON) - lcd_off_procedure(LCD_OFF_BY_TIMEOUT); + display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); if (!pm_get_power_lock_support()) { /* sleep state : set system mode to SUSPEND */ @@ -955,7 +857,7 @@ static int update_setting(int key_idx, int val) val == VCONFKEY_IDLE_LOCK && display_panel_get_dpms_cached_state() != DPMS_ON && is_lcdon_blocked() == LCDON_BLOCK_NONE) - lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); + display_panel_lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); @@ -1186,7 +1088,7 @@ static gboolean delayed_dpms_init_done(gpointer data) switch (get_pm_cur_state()) { case S_NORMAL: case S_LCDDIM: - lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); + display_panel_lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); if (display_conf.timeout_enable) { timeout = states[S_NORMAL].timeout; /* check minimun lcd on time */ @@ -1196,7 +1098,7 @@ static gboolean delayed_dpms_init_done(gpointer data) } break; case S_LCDOFF: - lcd_off_procedure(LCD_OFF_BY_EVENT); + display_panel_lcd_off_procedure(LCD_OFF_BY_EVENT); timeout = display_conf.lcdoff_timeout; display_state_transition_reset_state_transition_timeout(timeout); break; @@ -1236,6 +1138,7 @@ static int display_probe(void *data) setup_display_plugin_backlight_ops(dp); dp->set_dim_state = NULL; dp->get_device_flags = NULL; + dp->lcd_off_procedure = NULL; setup_display_plugin_backlight_ops(dp); /** @@ -1414,9 +1317,9 @@ static void display_init(void *data) // wm_ready = check_wm_ready(); if (display_panel_init_dpms()) { if (is_lcdon_blocked() != LCDON_BLOCK_NONE) - lcd_off_procedure(LCD_OFF_BY_EVENT); + display_panel_lcd_off_procedure(LCD_OFF_BY_EVENT); else - lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); + display_panel_lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); } else { add_timer_for_dpms_init(); } diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index 50fb6d6..a6c969d 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -229,7 +229,7 @@ static inline void switch_off_lcd(void) broadcast_lcdoff_by_powerkey(); - lcd_off_procedure(LCD_OFF_BY_POWER_KEY); + display_panel_lcd_off_procedure(LCD_OFF_BY_POWER_KEY); } static void check_key_combination(struct input_event *pinput) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 5a8f2bf..697b776 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -462,7 +462,7 @@ static gboolean late_transit_on(void *data) return G_SOURCE_REMOVE; } -void lcd_on_procedure(int state, enum device_flags flag) +static void lcd_on_procedure(int state, enum device_flags flag) { unsigned long flags = NORMAL_MODE; display_plugin_get_device_flags(&flags); @@ -528,7 +528,7 @@ void lcd_on_procedure(int state, enum device_flags flag) display_misc_set_touch_event_blocked(false); } -inline void lcd_off_procedure(enum device_flags flag) +static void lcd_off_procedure(enum device_flags flag) { unsigned long flags = NORMAL_MODE; display_plugin_get_device_flags(&flags); @@ -1661,6 +1661,7 @@ static int display_probe(void *data) setup_display_plugin_backlight_ops(dp); dp->set_dim_state = set_dim_state; dp->get_device_flags = get_device_flags; + dp->lcd_off_procedure = lcd_off_procedure; setup_display_plugin_backlight_ops(dp); /** diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index 701041a..19ae629 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -226,7 +226,7 @@ static inline void switch_off_lcd(void) broadcast_lcdoff_by_powerkey(); - lcd_off_procedure(LCD_OFF_BY_POWER_KEY); + display_panel_lcd_off_procedure(LCD_OFF_BY_POWER_KEY); } static void check_key_combination(struct input_event *pinput) diff --git a/src/display/core.h b/src/display/core.h index 0b5d791..9c07e26 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -128,8 +128,6 @@ int display_off_by_reason(const char *reason); int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name); int custom_lcdon(int timeout); void lcd_on_direct(enum device_flags flags); -void lcd_on_procedure(int state, enum device_flags flag); -void lcd_off_procedure(enum device_flags flag); void broadcast_lcd_off_late(enum device_flags flags); /* auto-brightness.c */ diff --git a/src/display/display-panel.c b/src/display/display-panel.c index 22542ac..2c94538 100644 --- a/src/display/display-panel.c +++ b/src/display/display-panel.c @@ -18,11 +18,13 @@ #include "shared/log.h" #include "power/power-suspend.h" +#include "power/power-doze.h" #include "ambient-mode.h" #include "device-interface.h" -#include "display-backlight.h" +#include "display-misc.h" #include "display-panel.h" -#include "display-plugin.h" +#include "display-signal.h" +#include "led/touch-key.h" #define MAX_WHITE_BALANCE_GAIN 2047 #define MAX_WHITE_BALANCE_OFFSET 2047 @@ -34,6 +36,7 @@ static int dpms_running_state = DPMS_SETTING_DONE; static bool lcd_paneloff_mode = false; +static bool lcd_on_broadcasted = true; /* FIXME: This function is for temporary use, should be fixed after plugin refactoring */ int display_panel_set_dpms_state(int dpms_on, enum device_flags flags) @@ -201,6 +204,106 @@ void display_panel_get_lcd_paneloff_mode(bool *on) *on = lcd_paneloff_mode; } +void display_panel_lcd_on_procedure(int state, enum device_flags flag) +{ + unsigned long flags = NORMAL_MODE; + display_plugin_get_device_flags(&flags); + flags |= flag; + + /* + * Display on procedure + * step 1. leave doze + * step 2. broadcast lcd on signal with cause + * step 3. set brightness + * step 4. set pmstate of vconf + * step 5. display on operate + * - a. display on + * - b. TSP(touch screen) and touchkey enable + * step 6. broadcast lcd on complete signal + * step 7. key backlight enable + */ + leave_doze(); + + _I("[lcdstep] 0x%lx", flags); + + /* send LCDOn dbus signal */ + if (!lcd_on_broadcasted) + broadcast_lcd_on(SIGNAL_PRE, flags); + + /* Update brightness level */ + if (state == LCD_DIM) + display_backlight_set_brightness_by_dim_brightness(); + else if (state == LCD_NORMAL) + display_backlight_update_by_default_brightness(); + + if (state == LCD_NORMAL) + set_setting_pmstate(S_NORMAL); + else if (state == LCD_DIM) + set_setting_pmstate(S_LCDDIM); + + display_start_dependent_device(flags); + + if (!lcd_on_broadcasted) { + broadcast_lcd_on(SIGNAL_POST, flags); + lcd_on_broadcasted = true; + } + + touchled_control_backlight(TOUCHLED_DIRECT_ON); + + display_misc_set_touch_event_blocked(false); +} + +void display_panel_lcd_off_procedure(enum device_flags flag) +{ + unsigned long flags = NORMAL_MODE; + display_plugin_get_device_flags(&flags); + flags |= flag; + + if (display_plugin_lcd_off_procedure(flag) == 0) + return; + /* + * Display off procedure + * step 0. enhance mode off using nofity (e.g mdnie, HBM, LBM) + * step 1. broadcast lcd off signal with cause + * step 2. set pmstate of vconf + * step 3. display off operate + * - a. display off + * - b. TSP(touch screen) and touchkey disable + * step 4. broadcast lcd off complete siganl + * step 5. enter doze mode if it is enabled + */ + _I("[lcdstep] 0x%lx", flags); + + /* notification */ + + device_notify(DEVICE_NOTIFIER_LCD_OFF, NULL); + + if (lcd_on_broadcasted) { + broadcast_lcd_off(SIGNAL_PRE, flags); + lcd_on_broadcasted = false; + } + + /* operation */ + + display_misc_set_touch_event_blocked(true); + + set_setting_pmstate(S_LCDOFF); + + touchled_control_backlight(TOUCHLED_DIRECT_OFF); + + display_stop_dependent_device(flags); + + broadcast_lcd_off(SIGNAL_POST, flags); + device_notify(DEVICE_NOTIFIER_LCD_OFF_COMPLETE, NULL); + + enter_doze(); +} + +bool display_panel_is_lcd_on_state_broadcasted(void) +{ + return lcd_on_broadcasted; +} + /* FIXME: This function is deprecated, should be fixed after plugin refactoring */ void display_panel_set_dpms_running_state(int val) { diff --git a/src/display/display-panel.h b/src/display/display-panel.h index 4cbc779..862fc35 100644 --- a/src/display/display-panel.h +++ b/src/display/display-panel.h @@ -32,6 +32,9 @@ int display_panel_set_panel_state_by_off_state(enum device_flags flags); int display_panel_set_panel_state_by_standby_state(bool standby_on); void display_panel_set_lcd_paneloff_mode(bool on); void display_panel_get_lcd_paneloff_mode(bool *on); +void display_panel_lcd_on_procedure(int state, enum device_flags flag); +void display_panel_lcd_off_procedure(enum device_flags flag); +bool display_panel_is_lcd_on_state_broadcasted(void); /* Deprecated functions */ int display_panel_set_image_effect(enum display_image_effect effect); int display_panel_get_image_effect(enum display_image_effect *effect); diff --git a/src/display/display-plugin.c b/src/display/display-plugin.c index 3af5995..d588965 100644 --- a/src/display/display-plugin.c +++ b/src/display/display-plugin.c @@ -99,6 +99,16 @@ int display_plugin_auto_brightness_control(enum brightness_request_e request, in return 0; } +int display_plugin_lcd_off_procedure(enum device_flags flag) +{ + if (g_display_plugin.lcd_off_procedure) { + g_display_plugin.lcd_off_procedure(flag); + 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 bea8205..d66dcac 100644 --- a/src/display/display-plugin.h +++ b/src/display/display-plugin.h @@ -67,6 +67,7 @@ struct display_plugin { /* FIXME: function names will be redefined */ void (*set_dim_state) (bool on); int (*get_device_flags) (unsigned long *device_flags); + void (*lcd_off_procedure) (enum device_flags flag); struct display_config *config; struct display_backlight_ops *backlight; @@ -86,6 +87,7 @@ const char* display_plugin_device_flags_to_string(enum device_flags flags); int display_plugin_auto_brightness_control(enum brightness_request_e request, int set_brightness); int display_plugin_set_dim_state(bool on); int display_plugin_get_device_flags(unsigned long *device_flags); +int display_plugin_lcd_off_procedure(enum device_flags flag); int display_plugin_backlight_get_lcd_power(void); int display_plugin_backlight_set_brightness(int brightness); -- 2.7.4 From e1c14429b409a6c2b163040ab5e3d29807f105e9 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 12 Jun 2023 18:08:09 +0900 Subject: [PATCH 10/16] input: Define plugin interface for input Input plugin must implement interface provided by input-plugin-interface.h with symbol name INPUT_PLUGIN_INTERFACE_SYMBOL. The input core dlopen() and dlsym() with that symbol, initializing or exiting input plugin within the deviced core execution. Change-Id: Id279db971cb0351b609a022de02a51672242c0b6 Signed-off-by: Youngjae Cho --- plugins/iot-headless/input/input-handler.c | 12 ++--- plugins/iot-headless/input/input-handler.h | 6 --- src/input/input-plugin-interface.h | 29 +++++++++++ src/input/input-plugin.c | 83 ++++++++++++++++++++++++++++++ src/input/input-plugin.h | 25 +++++++++ src/input/input.c | 8 +-- 6 files changed, 148 insertions(+), 15 deletions(-) create mode 100644 src/input/input-plugin-interface.h create mode 100644 src/input/input-plugin.c create mode 100644 src/input/input-plugin.h diff --git a/plugins/iot-headless/input/input-handler.c b/plugins/iot-headless/input/input-handler.c index c332d32..f5d5a21 100644 --- a/plugins/iot-headless/input/input-handler.c +++ b/plugins/iot-headless/input/input-handler.c @@ -22,15 +22,16 @@ #include #include #include +#include #include "shared/common.h" -#include "shared/devices.h" #include "shared/device-notifier.h" #include "shared/log.h" #include "shared/event.h" #include "input-config.h" #include "input/input.h" +#include "input/input-plugin-interface.h" static int input_event_handler_id; @@ -151,10 +152,12 @@ static void input_handler_process_key(struct timeval time, unsigned short type, device_notify(DEVICE_NOTIFIER_KEY_RELEASE, (void *)(intptr_t) keycode); } -static void input_handler_init(void *data) +static int input_handler_init(void *data) { init_input_config(); input_register_event_callback(input_handler_process_key, NULL, NULL, &input_event_handler_id); + + return 0; } static void input_handler_exit(void *data) @@ -162,10 +165,7 @@ static void input_handler_exit(void *data) input_unregister_event_callback(input_event_handler_id); } -static const struct device_ops input_handler_device_ops = { - DECLARE_NAME_LEN("input-handler"), +const struct input_plugin_interface INPUT_PLUGIN_INTERFACE_SYMBOL = { .init = input_handler_init, .exit = input_handler_exit, }; - -DEVICE_OPS_REGISTER(&input_handler_device_ops) diff --git a/plugins/iot-headless/input/input-handler.h b/plugins/iot-headless/input/input-handler.h index e66730d..e69de29 100644 --- a/plugins/iot-headless/input/input-handler.h +++ b/plugins/iot-headless/input/input-handler.h @@ -1,6 +0,0 @@ -#ifndef __INPUT_HANDLER_H__ -#define __INPUT_HANDLER_H__ - -void input_handler_process_key(int keycode, int keyvalue); - -#endif //__INPUT_HANDLER_H__ \ No newline at end of file diff --git a/src/input/input-plugin-interface.h b/src/input/input-plugin-interface.h new file mode 100644 index 0000000..26736a4 --- /dev/null +++ b/src/input/input-plugin-interface.h @@ -0,0 +1,29 @@ +/* + * deviced + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __INPUT_PLUGIN_INTERFACE_H__ +#define __INPUT_PLUGIN_INTERFACE_H__ + +struct input_plugin_interface { + int (*init) (void *); + void (*exit) (void *); +}; + +#define INPUT_PLUGIN_INTERFACE_SYMBOL input_plugin_interface_sym + +#endif// __INPUT_PLUGIN_INTERFACE_H__ diff --git a/src/input/input-plugin.c b/src/input/input-plugin.c new file mode 100644 index 0000000..ff894ca --- /dev/null +++ b/src/input/input-plugin.c @@ -0,0 +1,83 @@ +#include +#include +#include + +#include "input-plugin-interface.h" + +#define INPUT_PLUGIN_PATH LIBPATH"/deviced/input-handler.so" + +#define __stringify(s) #s +#define stringify(s) __stringify(s) + +static void *g_input_plugin_handle; +static struct input_plugin_interface *g_input_plugin; + +static int load_input_plugin(void) +{ + void *g_input_plugin_handle; + + if (g_input_plugin) + return 0; + + if (access(INPUT_PLUGIN_PATH, F_OK) != 0) + return -ENOENT; + + g_input_plugin_handle = dlopen(INPUT_PLUGIN_PATH, RTLD_NOW | RTLD_GLOBAL); + if (!g_input_plugin_handle) { + _E("Failed to load input plugin shared object, %s", dlerror()); + return -1; + } + + g_input_plugin = dlsym(g_input_plugin_handle, stringify(INPUT_PLUGIN_INTERFACE_SYMBOL)); + if (!g_input_plugin) { + _E("Failed to load input plugin symbol, %s", dlerror()); + return -1; + } + + return 0; +} + +static void unload_input_plugin(void) +{ + int ret; + + if (!g_input_plugin_handle) + return; + + g_input_plugin = NULL; + + ret = dlclose(g_input_plugin_handle); + if (ret != 0) { + _E("Failed to unload input plugin shared object, %s", dlerror()); + return; + } + + g_input_plugin_handle = NULL; +} + +int input_plugin_init(void *data) +{ + int ret; + + if (!g_input_plugin) { + ret = load_input_plugin(); + if (ret != 0) + return ret; + } + + if (!g_input_plugin->init) + return -EOPNOTSUPP; + + return g_input_plugin->init(data); +} + +void input_plugin_exit(void *data) +{ + if (!g_input_plugin) + return; + + if (g_input_plugin->exit) + g_input_plugin->exit(data); + + unload_input_plugin(); +} diff --git a/src/input/input-plugin.h b/src/input/input-plugin.h new file mode 100644 index 0000000..cb17a3d --- /dev/null +++ b/src/input/input-plugin.h @@ -0,0 +1,25 @@ +/* + * deviced + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __INPUT_PLUGIN_H__ +#define __INPUT_PLUGIN_H__ + +int input_plugin_init(void *data); +void input_plugin_exit(void *data); + +#endif //__INPUT_PLUGIN_H__ diff --git a/src/input/input.c b/src/input/input.c index f596414..3b3f067 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -35,6 +35,7 @@ #include "shared/log.h" #include "input.h" #include "input-dbus.h" +#include "input-plugin.h" #include "input-parser.h" #include "input-device-manager.h" @@ -42,7 +43,6 @@ static struct udev *udev; static struct libinput *li; -static struct input_ops *input_plugin_ops; static guint efd; struct input_event_handler { @@ -249,8 +249,9 @@ static void input_init(void *data) int ret; int fd; - if (input_plugin_ops == NULL) - _E("Failed to init input_ops"); + ret = input_plugin_init(data); + if (ret < 0) + _E("Failed to initialize input plugin(%d)", ret); ret = input_devman_init(); if (ret < 0) { @@ -318,6 +319,7 @@ static void input_exit(void *data) udev_unref(udev); input_devman_exit(); + input_plugin_exit(data); } static const struct device_ops input_device_ops = { -- 2.7.4 From bd2257744910e1fd4866a72f4bfafc5a4132f606 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 13 Jun 2023 20:15:19 +0900 Subject: [PATCH 11/16] input: Simplify input_plugin_init()/input_plugin_exit() Change-Id: Ifaf1a2e359b8f639a05836e32ff351b58940ffae Signed-off-by: Youngjae Cho --- src/input/input-plugin.c | 70 +++++++++++++++--------------------------------- 1 file changed, 21 insertions(+), 49 deletions(-) diff --git a/src/input/input-plugin.c b/src/input/input-plugin.c index ff894ca..03b30b7 100644 --- a/src/input/input-plugin.c +++ b/src/input/input-plugin.c @@ -12,57 +12,27 @@ static void *g_input_plugin_handle; static struct input_plugin_interface *g_input_plugin; -static int load_input_plugin(void) +int input_plugin_init(void *data) { - void *g_input_plugin_handle; - - if (g_input_plugin) - return 0; - - if (access(INPUT_PLUGIN_PATH, F_OK) != 0) + if (access(INPUT_PLUGIN_PATH, F_OK) != 0) { + _D("There is no input plugin, %s", INPUT_PLUGIN_PATH); return -ENOENT; - - g_input_plugin_handle = dlopen(INPUT_PLUGIN_PATH, RTLD_NOW | RTLD_GLOBAL); - if (!g_input_plugin_handle) { - _E("Failed to load input plugin shared object, %s", dlerror()); - return -1; - } - - g_input_plugin = dlsym(g_input_plugin_handle, stringify(INPUT_PLUGIN_INTERFACE_SYMBOL)); - if (!g_input_plugin) { - _E("Failed to load input plugin symbol, %s", dlerror()); - return -1; } - return 0; -} - -static void unload_input_plugin(void) -{ - int ret; - - if (!g_input_plugin_handle) - return; - - g_input_plugin = NULL; - - ret = dlclose(g_input_plugin_handle); - if (ret != 0) { - _E("Failed to unload input plugin shared object, %s", dlerror()); - return; + if (!g_input_plugin_handle) { + g_input_plugin_handle = dlopen(INPUT_PLUGIN_PATH, RTLD_NOW | RTLD_GLOBAL); + if (!g_input_plugin_handle) { + _E("Failed to load input plugin shared object, %s", dlerror()); + return -ENOTSUP; + } } - g_input_plugin_handle = NULL; -} - -int input_plugin_init(void *data) -{ - int ret; - if (!g_input_plugin) { - ret = load_input_plugin(); - if (ret != 0) - return ret; + g_input_plugin = dlsym(g_input_plugin_handle, stringify(INPUT_PLUGIN_INTERFACE_SYMBOL)); + if (!g_input_plugin) { + _E("Failed to load input plugin symbol, %s", dlerror()); + return -ENOTSUP; + } } if (!g_input_plugin->init) @@ -73,11 +43,13 @@ int input_plugin_init(void *data) void input_plugin_exit(void *data) { - if (!g_input_plugin) - return; - - if (g_input_plugin->exit) + if (g_input_plugin && g_input_plugin->exit) g_input_plugin->exit(data); - unload_input_plugin(); + g_input_plugin = NULL; + + if (g_input_plugin_handle) + dlclose(g_input_plugin_handle); + + g_input_plugin_handle = NULL; } -- 2.7.4 From 44988bdbb2f2e707e2033f8d22fd000ccf3799cf Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 14 Jun 2023 15:38:34 +0900 Subject: [PATCH 12/16] display: Remove unused killable-daemon code Change-Id: Idffac4921c3b147ec3fced2525c92eb8e3444f52 Signed-off-by: Youngjae Cho --- plugins/wearable/display/core.c | 217 +--------------------------------------- src/display/display-config.h | 7 -- src/display/display-lock.c | 18 +--- src/display/display-lock.h | 12 --- 4 files changed, 5 insertions(+), 249 deletions(-) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 697b776..2aadae3 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -155,19 +155,8 @@ static struct state states[S_END] = { (b.tv_sec * 1000000 + b.tv_usec)) \ / 1000) -#define KILLABLE_DAEMON_LOCK_LIMIT 1800 /* seconds, 30min */ #define FORCE_RELEASE_LOCK_INTERVAL 5 /* seconds */ -static void get_comm(pid_t pid, char *comm); -static bool is_killable_daemon(pid_t pid); -static gboolean pmlock_terminate_daemon_to_release_lock(gpointer data); -static int pmlock_check(void *data); -static int powerlock_load_config(struct parse_result *result, void *user_data); -static void free_killable_daemon_list(void); - -static GList *display_lock_killable_daemon; -static bool initialized_killable_daemon_list; - static struct display_config display_conf = { .lock_wait_time = LOCK_SCREEN_WATING_TIME, .longpress_interval = LONG_PRESS_INTERVAL, @@ -186,7 +175,6 @@ static struct display_config display_conf = { .input_support = true, .lockcheck_timeout = 600, .display_init_direction = DISPLAY_INIT_DIRECTION_HORIZONTAL, - .pmlock_check = pmlock_check, .aod_enter_level = 40, .aod_tsp = true, .touch_wakeup = false, @@ -248,181 +236,6 @@ static const char* __device_flags_to_string(enum device_flags flags) return UNKNOWN_STR; } -static void get_comm(pid_t pid, char *comm) -{ - char buf[PATH_MAX]; - int fd, r; - - if (pid >= INTERNAL_LOCK_BASE) - snprintf(buf, PATH_MAX, "/proc/%d/comm", getpid()); - else - snprintf(buf, PATH_MAX, "/proc/%d/comm", pid); - - fd = open(buf, O_RDONLY); - if (fd < 0) { - comm[0] = '\0'; - _E("Process(%d) does not exist now(may be dead without unlock).", pid); - return; - } - - r = read(fd, comm, PATH_MAX); - if ((r > 0) && (r < PATH_MAX)) { - if (comm[r - 1] == '\n') - comm[r - 1] = '\0'; - else - comm[r] = '\0'; - } else - comm[0] = '\0'; - - close(fd); -} - -static bool is_killable_daemon(pid_t pid) -{ - char pname[PATH_MAX] = {0, }; - const char *blacklist; - GList *l; - - get_comm(pid, pname); - if (!(*pname)) - return false; - - SYS_G_LIST_FOREACH(display_lock_killable_daemon, l, blacklist) { - if (MATCH(pname, blacklist)) - return true; - } - - return false; -} - -static gboolean pmlock_terminate_daemon_to_release_lock(gpointer data) -{ - pid_t pid; - PmLockNode *node; - enum state_t state; - int ret; - bool pid_exist; - char pname[PATH_MAX] = {0, }; - - if (!data) { - _E("Invalid parameter."); - return G_SOURCE_REMOVE; - } - - node = (PmLockNode *) data; - state = node->state; - pid = node->pid; - - if (pid <= 0) { - _E("Invalid lock pid."); - del_node(state, node); - return G_SOURCE_REMOVE; - } - - if (!node->killable_daemon) { - _E("Incorrect checker, this is not a killable daemon. Stop checking lock."); - return G_SOURCE_REMOVE; - } - - pid_exist = (kill(pid, 0) == 0); - if (pid_exist) - get_comm(pid, pname); - - if (node->force_release == false) { - /* Stop checking lock if process had been terminated */ - if (!pid_exist) { - del_node(state, node); - _I("Process %d not found. Stop checking lock.", pid); - return G_SOURCE_REMOVE; - } - - /* KILLABLE_DAEMON_LOCK_LIMIT is expired. Kill the daemon */ - CRITICAL_LOG("%s(%d) holds %s lock for %ds. kill SIGTERM.", - *pname ? pname : "Unknown", pid, states[state].name, KILLABLE_DAEMON_LOCK_LIMIT); - ret = kill(pid, SIGTERM); - if (ret < 0) - CRITICAL_LOG_E("Failed to send SIGTERM to process %s(%d), %d.", - *pname ? pname : "Unknown", pid, errno); - - node->force_release = true; - node->warning_id = g_timeout_add_seconds(FORCE_RELEASE_LOCK_INTERVAL, - pmlock_terminate_daemon_to_release_lock, (gpointer)node); - } else if (node->force_release == true) { - /* kill confirmation */ - if (pid_exist) { - CRITICAL_LOG("%s(%d) is still alive, kill SIGKILL.", - *pname ? pname : "Unknown", pid); - - ret = kill(pid, SIGKILL); - if (ret < 0) - CRITICAL_LOG_E("Failed to kill process %s(%d), %d.", - *pname ? pname : "Unknown", pid, errno); - } - - /* release lock */ - CRITICAL_LOG("Release %s lock occupied by PID %d.", states[state].name, pid); - del_node(state, node); - set_unlock_time(pid, state); - - if (!display_state_transition_is_there_state_transition_timer()) - states[get_pm_cur_state()].trans(EVENT_TIMEOUT); - } - - return G_SOURCE_REMOVE; -} - -static int pmlock_check(void *data) -{ - PmLockNode *node; - int ret; - - assert(data); - node = (PmLockNode *) data; - - if (!initialized_killable_daemon_list) { - ret = config_parse(POWERLOCK_CONF_FILE, powerlock_load_config, NULL); - /* config file may not exist */ - if (ret < 0 && ret != -ENOENT) - _W("Failed to load %s, %d.", POWERLOCK_CONF_FILE, ret); - - if (status == DEVICE_OPS_STATUS_UNINIT) { - _W("Lock request before display init. Preloaded killable list."); - initialized_killable_daemon_list = true; - } else if (status == DEVICE_OPS_STATUS_STOP) { - _W("Lock request after display stop. Loaded list will be freed immediately."); - node->killable_daemon = is_killable_daemon(node->pid); - free_killable_daemon_list(); - goto killable_marked; - } - } - - node->killable_daemon = is_killable_daemon(node->pid); - -killable_marked: - /* use default lock checker */ - if (!node->killable_daemon) - return 0; - - return g_timeout_add_seconds(KILLABLE_DAEMON_LOCK_LIMIT, - pmlock_terminate_daemon_to_release_lock, (gpointer)node); -} - -static void free_killable_daemon_list(void) -{ - GList *l, *l_next; - char *blacklist; - - if (!display_lock_killable_daemon) - return; - - SYS_G_LIST_FOREACH_SAFE(display_lock_killable_daemon, l, l_next, blacklist) { - SYS_G_LIST_REMOVE(display_lock_killable_daemon, blacklist); - free(blacklist); - } - display_lock_killable_daemon = NULL; - initialized_killable_daemon_list = false; -} - static int get_device_flags(unsigned long *device_flags) { if (!device_flags) @@ -952,8 +765,7 @@ static void proc_condition_lock(PMMsg *data) } } - _SD("be requested LOCK info pname(%s), holdkeyblock(%d) flags(%d) killable_daemon(%d)", - pname, holdkey_block, flags, tmp->killable_daemon); + _SD("be requested LOCK info pname(%s), holdkeyblock(%d) flags(%d)", pname, holdkey_block, flags); set_lock_time(pid, pname, state); device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value); @@ -1582,26 +1394,6 @@ static int delayed_init_done(void *data) return done; } -static int powerlock_load_config(struct parse_result *result, void *user_data) -{ - char *name = NULL; - - _D("powerlock_load_config: section=%s name=%s value=%s", result->section, result->name, result->value); - - if (MATCH(result->section, "KillableDaemon") && MATCH(result->name, "KillableList")) { - name = strndup(result->value, PATH_MAX - 1); - if (!name) { - _E("Not enough memory."); - return -ENOMEM; - } - - CRITICAL_LOG("Add %s to killable daemon list.", name); - SYS_G_LIST_APPEND(display_lock_killable_daemon, name); - } - - return 0; -} - static gboolean delayed_dpms_init_done(gpointer data) { int timeout; @@ -1812,12 +1604,6 @@ static void display_init(void *data) _W("Failed to load '%s', use default value: %d", DISPLAY_CONF_FILE, ret); - ret = config_parse(POWERLOCK_CONF_FILE, powerlock_load_config, NULL); - /* config file may not exist */ - if (ret < 0 && ret != -ENOENT) - _W("Failed to load %s, %d.", POWERLOCK_CONF_FILE, ret); - initialized_killable_daemon_list = true; - register_kernel_uevent_control(&lcd_uevent_ops); register_kernel_uevent_control(&sec_dsim_uevent_ops); @@ -1969,7 +1755,6 @@ static void display_exit(void *data) exit_lcd_operation(); free_lock_info_list(); - free_killable_daemon_list(); /* free display service */ display_service_free(); diff --git a/src/display/display-config.h b/src/display/display-config.h index 71c060b..967e9bd 100644 --- a/src/display/display-config.h +++ b/src/display/display-config.h @@ -43,13 +43,6 @@ struct display_config { int continuous_sampling; int lockcheck_timeout; int display_init_direction; - - /* Define pmlock checker. - * Return id of the lock checker. - * - * Returning 0 will use default lock checker */ - int (*pmlock_check) (void *data); - int aod_enter_level; bool aod_tsp; bool timeout_enable; diff --git a/src/display/display-lock.c b/src/display/display-lock.c index 5b2df70..0e20288 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -199,8 +199,7 @@ static gboolean default_pmlock_check(void *data) } if (!is_app(pid)) { - /* For (non-killable) daemon, - * no need to ask resourced if it is abnormal lock */ + /* For daemon, no need to ask resourced if it is abnormal lock */ broadcast_pmlock_expired(pid, state, NULL, node->time); return G_SOURCE_CONTINUE; } @@ -361,18 +360,9 @@ PmLockNode *display_lock_add_pmlock_node(enum state_t s_index, pid_t pid, bool h } n->broadcast_warning = true; - if (pid < INTERNAL_LOCK_BASE) { - /* check if this lock node needs custom-defined lock checker. - * n->warning_id would be 0 if fails to register the checker, - * or there is no need to use that checker */ - if (g_display_plugin.config->pmlock_check) - n->warning_id = g_display_plugin.config->pmlock_check(n); - - /* use default lock checker */ - if (!n->warning_id) - n->warning_id = g_timeout_add_seconds(g_display_plugin.config->lockcheck_timeout, - default_pmlock_check, (gpointer)n); - } + if (pid < INTERNAL_LOCK_BASE) + n->warning_id = g_timeout_add_seconds(g_display_plugin.config->lockcheck_timeout, + default_pmlock_check, (gpointer)n); SYS_G_LIST_APPEND(cond_head[s_index], n); diff --git a/src/display/display-lock.h b/src/display/display-lock.h index 30e8006..abf2b9f 100644 --- a/src/display/display-lock.h +++ b/src/display/display-lock.h @@ -38,18 +38,6 @@ typedef struct _pm_lock_node { bool holdkey_block; bool app_background; bool broadcast_warning; - - /* Set true when the lock holder is an entry of - * the list display_lock_killable_daemon. - * If true, deviced tries to kill this lock holder when - * the holder holds lock longer than KILLABLE_DAEMON_LOCK_LIMIT */ - bool killable_daemon; - - /* Set true when the lock holder holds lock - * longer than KILLABLE_DAEMON_LOCK_LIMIT. - * After a while, FORCE_RELEASE_LOCK_INTERVAL, - * this lock will be released. */ - bool force_release; } PmLockNode; bool check_lock_state(int state); -- 2.7.4 From 1089fa81a7e399893bbed57dddec5043293a5f57 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Wed, 14 Jun 2023 10:54:25 +0900 Subject: [PATCH 13/16] display: Relocate default_action() For relocating default_action(), there are some changes. 1. Add device_ops_status getter/setter temporarily. 2. Add lcd on time update and calculation functions. 3. Remove state action functions from the display-plugin. -> Since default_action() has relocated, these functions no longer need to exist. New functions in the display - void display_set_display_ops_status(enum device_ops_status dev_ops_status); - int display_get_display_ops_status(enum device_ops_status *dev_ops_status); -> device_ops_status is set during the display init, probe, exit... New functions in the display-panel - void display_panel_update_lcd_on_timeval(void); - int display_panel_calculate_diff_time_between_lcd_on_direct_and_state_action(int *diff_time); -> These functions update lcd_on time and caculate the time difference between lcd_on_direct and do_state_action. New function in the display-state-transition - int display_state_transition_do_state_action(int timeout); -> This function is usually called after the display state changed. It handles the rest of the work for changed display state. Change-Id: If6ccd5f5cbcae21ed87db473596bdc3c71ddb86f Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 200 ++++----------------------------- plugins/mobile/display/core.c | 199 ++++---------------------------- plugins/tv/display/core.c | 199 ++++---------------------------- plugins/wearable/display/core.c | 27 ++--- src/display/display-panel.c | 29 +++++ src/display/display-panel.h | 2 + src/display/display-plugin.c | 17 --- src/display/display-plugin.h | 2 - src/display/display-state-transition.c | 144 +++++++++++++++++++++++- src/display/display-state-transition.h | 1 + src/display/display.c | 18 +++ src/display/display.h | 2 + 12 files changed, 272 insertions(+), 568 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 6d0393a..484832f 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -100,21 +100,17 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; static int system_wakeup_flag = false; static char *custom_change_name; -static struct timeval lcdon_tv; - -/* default transition, action fuctions */ -static int default_action(int timeout); static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; static struct state states[S_END] = { { S_START, "S_START", NULL, NULL, NULL, NULL }, - { S_NORMAL, "S_NORMAL", NULL, default_action, NULL, NULL }, - { S_LCDDIM, "S_LCDDIM", NULL, default_action, NULL, NULL }, - { S_LCDOFF, "S_LCDOFF", NULL, default_action, NULL, NULL }, + { S_NORMAL, "S_NORMAL", NULL, NULL, NULL, NULL }, + { S_LCDDIM, "S_LCDDIM", NULL, NULL, NULL, NULL }, + { S_LCDOFF, "S_LCDOFF", NULL, NULL, NULL, NULL }, { S_STANDBY, "S_STANDBY", NULL, NULL, NULL, NULL }, - { S_SLEEP, "S_SLEEP", NULL, default_action, NULL, NULL }, + { S_SLEEP, "S_SLEEP", NULL, NULL, NULL, NULL }, { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, }; @@ -131,11 +127,6 @@ static struct state states[S_END] = { #define CONTINUOUS_SAMPLING 1 #define LCDOFF_TIMEOUT 300 /* milli second */ -#define DIFF_TIMEVAL_MS(a, b) \ - (((a.tv_sec * 1000000 + a.tv_usec) - \ - (b.tv_sec * 1000000 + b.tv_usec)) \ - / 1000) - static struct display_config display_conf = { .lock_wait_time = LOCK_SCREEN_WATING_TIME, .longpress_interval = LONG_PRESS_INTERVAL, @@ -215,20 +206,12 @@ void lcd_on_direct(enum device_flags flags) set_pm_cur_state(S_NORMAL); _D("lcd is on directly"); - gettimeofday(&lcdon_tv, NULL); + display_panel_update_lcd_on_timeval(); display_panel_lcd_on_procedure(LCD_NORMAL, flags); update_display_locktime(LOCK_SCREEN_INPUT_TIMEOUT); } -static inline bool check_lcd_is_on(void) -{ - if (display_panel_get_dpms_cached_state() != DPMS_ON) - return false; - - return true; -} - static gboolean timer_refresh_cb(gpointer data) { struct state *st; @@ -238,8 +221,7 @@ static gboolean timer_refresh_cb(gpointer data) set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -251,7 +233,7 @@ int custom_lcdon(int timeout) if (timeout <= 0) return -EINVAL; - if (check_lcd_is_on() == false) + if (display_panel_get_dpms_cached_state() != DPMS_ON) lcd_on_direct(LCD_ON_BY_GESTURE); _I("Custom lcd on timeout(%d ms).", timeout); @@ -263,9 +245,7 @@ int custom_lcdon(int timeout) set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); g_idle_add(timer_refresh_cb, NULL); @@ -307,9 +287,7 @@ int custom_lcdoff(enum device_flags flag) set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -336,7 +314,7 @@ int display_on_by_reason(const char *reason, int timeout) return -EINVAL; } - if (check_lcd_is_on() == false) + if (display_panel_get_dpms_cached_state() != DPMS_ON) lcd_on_direct(flag); _I("platform lcd on by %s (%d ms)", reason, timeout); @@ -348,9 +326,7 @@ int display_on_by_reason(const char *reason, int timeout) set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -392,9 +368,7 @@ int display_off_by_reason(const char *reason) set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -408,12 +382,11 @@ static void default_proc_change_state_action(enum state_t next, int timeout) st = &states[get_pm_cur_state()]; - if (st && st->action) { - if (timeout < 0) - st->action(st->timeout); - else - st->action(timeout); - } + if (timeout < 0) + display_state_transition_do_state_action(st->timeout); + else + display_state_transition_do_state_action(timeout); + } static int default_proc_change_state(unsigned int cond, pid_t pid) @@ -425,7 +398,7 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) switch (next) { case S_NORMAL: - if (check_lcd_is_on() == false) + if (display_panel_get_dpms_cached_state() != DPMS_ON) lcd_on_direct(LCD_ON_BY_EVENT); update_display_locktime(LOCK_SCREEN_CONTROL_TIMEOUT); default_proc_change_state_action(next, -1); @@ -617,136 +590,6 @@ static void sig_hup(int signo) pm_save_logdump(); } -/* default enter action function */ -static int default_action(int timeout) -{ - int wakeup_count = -1, pm_cur_state; - time_t now; - double diff; - static time_t last_update_time = 0; - static int last_timeout = 0; - struct timeval now_tv; - bool custom_status; - int brightness; - bool lcd_paneloff_mode = false; - - if (status != DEVICE_OPS_STATUS_START) { - _E("Display is not started."); - return -EINVAL; - } - - if (get_pm_cur_state() != S_SLEEP) { - if ((get_pm_cur_state() == S_NORMAL) && - lcdon_tv.tv_sec != 0) { - gettimeofday(&now_tv, NULL); - timeout -= DIFF_TIMEVAL_MS(now_tv, lcdon_tv); - lcdon_tv.tv_sec = 0; - } - /* set timer with current state timeout */ - display_state_transition_reset_state_transition_timeout(timeout); - - if (get_pm_cur_state() == S_NORMAL) { - time(&last_update_time); - last_timeout = timeout; - } else { - _I("Timout set: %s state %d ms", - states[get_pm_cur_state()].name, timeout); - } - } - - if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) { - power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, - power_get_wakeup_reason(), NULL); - set_setting_pmstate(get_pm_cur_state()); - pm_cur_state = get_pm_cur_state(); - device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); - } - - if ((get_pm_old_state() == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { - time(&now); - diff = difftime(now, last_update_time); - _I("S_NORMAL is changed to %s (timeout=%d ms diff=%.0f s).", - states[get_pm_cur_state()].name, last_timeout, diff); - } - - switch (get_pm_cur_state()) { - case S_NORMAL: - /* - * normal state : backlight on and restore - * the previous brightness - */ - if (get_pm_old_state() == S_LCDDIM) - display_backlight_update_by_default_brightness(); - - if (check_lcd_is_on() == false) - display_panel_lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); - break; - - case S_LCDDIM: - display_backlight_get_custom_status(&custom_status); - if ((get_pm_old_state() == S_NORMAL) && custom_status) { - display_backlight_get_brightness(&brightness); - display_backlight_set_custom_brightness(brightness); - } - /* lcd dim state : dim the brightness */ - display_backlight_set_brightness_by_dim_brightness(); - - if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) - display_panel_lcd_on_procedure(LCD_DIM, NORMAL_MODE); - break; - - case S_LCDOFF: - if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { - /* lcd off state : turn off the backlight */ - if (display_panel_get_dpms_cached_state() == DPMS_ON) - display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - } - - display_panel_get_lcd_paneloff_mode(&lcd_paneloff_mode); - if (display_panel_get_dpms_cached_state() == DPMS_ON - || lcd_paneloff_mode) - display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - break; - - case S_SLEEP: - if (display_panel_get_dpms_cached_state() == DPMS_ON) - display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - - if (!pm_get_power_lock_support()) { - /* sleep state : set system mode to SUSPEND */ - if (get_wakeup_count(&wakeup_count) < 0) - _E("Wakeup count read error."); - - if (wakeup_count < 0) { - _I("Wakup Event. Can not enter suspend mode."); - goto go_lcd_off; - } - - if (set_wakeup_count(wakeup_count) < 0) { - _E("Wakeup count write error."); - goto go_lcd_off; - } - } - goto go_suspend; - } - - return 0; - -go_suspend: -#ifdef ENABLE_PM_LOG - pm_history_save(PM_LOG_SLEEP, get_pm_cur_state()); -#endif - power_request_change_state(DEVICED_POWER_STATE_SLEEP, HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF_TIMEOUT); - return 0; - -go_lcd_off: - if (!pm_get_power_lock_support()) { - /* Resume !! */ - display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE); - } - return 0; -} - static void default_saving_mode(int onoff) { if (onoff) @@ -763,6 +606,7 @@ int poll_callback(int condition, PMMsg *data) static time_t last_t; time_t now; + display_get_display_ops_status(&status); if (status != DEVICE_OPS_STATUS_START) { _E("Display logic is not started."); return -ECANCELED; @@ -1354,7 +1198,7 @@ static void display_init(void *data) if (ret < 0) _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); - status = DEVICE_OPS_STATUS_START; + display_set_display_ops_status(DEVICE_OPS_STATUS_START); if (display_conf.timeout_enable) { timeout = states[S_NORMAL].timeout; /* check minimun lcd on time */ @@ -1376,7 +1220,7 @@ static void display_exit(void *data) { int i = INIT_END; - status = DEVICE_OPS_STATUS_STOP; + display_set_display_ops_status(DEVICE_OPS_STATUS_STOP); /* Set current state to S_NORMAL */ set_pm_cur_state(S_NORMAL); @@ -1434,6 +1278,7 @@ static int display_start(enum device_flags flags) if (!(flags & CORE_LOGIC_MODE)) return 0; + display_get_display_ops_status(&status); if (status == DEVICE_OPS_STATUS_START) return -EALREADY; @@ -1457,6 +1302,7 @@ static int display_stop(enum device_flags flags) if (!(flags & CORE_LOGIC_MODE)) return 0; + display_get_display_ops_status(&status); if (status == DEVICE_OPS_STATUS_STOP) return -EALREADY; diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index f7732c4..b6f15f0 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -102,21 +102,17 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; static int system_wakeup_flag = false; static char *custom_change_name; -static struct timeval lcdon_tv; - -/* default transition, action fuctions */ -static int default_action(int timeout); static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; static struct state states[S_END] = { { S_START, "S_START", NULL, NULL, NULL, NULL }, - { S_NORMAL, "S_NORMAL", NULL, default_action, NULL, NULL }, - { S_LCDDIM, "S_LCDDIM", NULL, default_action, NULL, NULL }, - { S_LCDOFF, "S_LCDOFF", NULL, default_action, NULL, NULL }, + { S_NORMAL, "S_NORMAL", NULL, NULL, NULL, NULL }, + { S_LCDDIM, "S_LCDDIM", NULL, NULL, NULL, NULL }, + { S_LCDOFF, "S_LCDOFF", NULL, NULL, NULL, NULL }, { S_STANDBY, "S_STANDBY", NULL, NULL, NULL, NULL }, - { S_SLEEP, "S_SLEEP", NULL, default_action, NULL, NULL }, + { S_SLEEP, "S_SLEEP", NULL, NULL, NULL, NULL }, { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, }; @@ -133,11 +129,6 @@ static struct state states[S_END] = { #define CONTINUOUS_SAMPLING 1 #define LCDOFF_TIMEOUT 300 /* milli second */ -#define DIFF_TIMEVAL_MS(a, b) \ - (((a.tv_sec * 1000000 + a.tv_usec) - \ - (b.tv_sec * 1000000 + b.tv_usec)) \ - / 1000) - static struct display_config display_conf = { .lock_wait_time = LOCK_SCREEN_WATING_TIME, .longpress_interval = LONG_PRESS_INTERVAL, @@ -222,20 +213,12 @@ void lcd_on_direct(enum device_flags flags) set_pm_cur_state(S_NORMAL); _D("lcd is on directly"); - gettimeofday(&lcdon_tv, NULL); + display_panel_update_lcd_on_timeval(); display_panel_lcd_on_procedure(LCD_NORMAL, flags); update_display_locktime(LOCK_SCREEN_INPUT_TIMEOUT); } -static inline bool check_lcd_is_on(void) -{ - if (display_panel_get_dpms_cached_state() != DPMS_ON) - return false; - - return true; -} - static gboolean timer_refresh_cb(gpointer data) { struct state *st; @@ -245,8 +228,7 @@ static gboolean timer_refresh_cb(gpointer data) set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -258,7 +240,7 @@ int custom_lcdon(int timeout) if (timeout <= 0) return -EINVAL; - if (check_lcd_is_on() == false) + if (display_panel_get_dpms_cached_state() != DPMS_ON) lcd_on_direct(LCD_ON_BY_GESTURE); _I("Custom lcd on timeout(%d ms).", timeout); @@ -270,9 +252,7 @@ int custom_lcdon(int timeout) set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); g_idle_add(timer_refresh_cb, NULL); @@ -314,9 +294,7 @@ int custom_lcdoff(enum device_flags flag) set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -343,7 +321,7 @@ int display_on_by_reason(const char *reason, int timeout) return -EINVAL; } - if (check_lcd_is_on() == false) + if (display_panel_get_dpms_cached_state() != DPMS_ON) lcd_on_direct(flag); _I("platform lcd on by %s (%d ms)", reason, timeout); @@ -355,9 +333,7 @@ int display_on_by_reason(const char *reason, int timeout) set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -399,9 +375,7 @@ int display_off_by_reason(const char *reason) set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -415,12 +389,10 @@ static void default_proc_change_state_action(enum state_t next, int timeout) st = &states[get_pm_cur_state()]; - if (st && st->action) { - if (timeout < 0) - st->action(st->timeout); - else - st->action(timeout); - } + if (timeout < 0) + display_state_transition_do_state_action(st->timeout); + else + display_state_transition_do_state_action(timeout); } static int default_proc_change_state(unsigned int cond, pid_t pid) @@ -432,7 +404,7 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) switch (next) { case S_NORMAL: - if (check_lcd_is_on() == false) + if (display_panel_get_dpms_cached_state() != DPMS_ON) lcd_on_direct(LCD_ON_BY_EVENT); update_display_locktime(LOCK_SCREEN_CONTROL_TIMEOUT); default_proc_change_state_action(next, -1); @@ -627,136 +599,6 @@ static void sig_hup(int signo) pm_save_logdump(); } -/* default enter action function */ -static int default_action(int timeout) -{ - int wakeup_count = -1, pm_cur_state; - time_t now; - double diff; - static time_t last_update_time = 0; - static int last_timeout = 0; - struct timeval now_tv; - bool custom_status; - int brightness; - bool lcd_paneloff_mode = false; - - if (status != DEVICE_OPS_STATUS_START) { - _E("Display is not started."); - return -EINVAL; - } - - if (get_pm_cur_state() != S_SLEEP) { - if ((get_pm_cur_state() == S_NORMAL) && - lcdon_tv.tv_sec != 0) { - gettimeofday(&now_tv, NULL); - timeout -= DIFF_TIMEVAL_MS(now_tv, lcdon_tv); - lcdon_tv.tv_sec = 0; - } - /* set timer with current state timeout */ - display_state_transition_reset_state_transition_timeout(timeout); - - if (get_pm_cur_state() == S_NORMAL) { - time(&last_update_time); - last_timeout = timeout; - } else { - _I("Timout set: %s state %d ms", - states[get_pm_cur_state()].name, timeout); - } - } - - if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) { - power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, - power_get_wakeup_reason(), NULL); - set_setting_pmstate(get_pm_cur_state()); - pm_cur_state = get_pm_cur_state(); - device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); - } - - if ((get_pm_old_state() == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { - time(&now); - diff = difftime(now, last_update_time); - _I("S_NORMAL is changed to %s (timeout=%d ms diff=%.0f s).", - states[get_pm_cur_state()].name, last_timeout, diff); - } - - switch (get_pm_cur_state()) { - case S_NORMAL: - /* - * normal state : backlight on and restore - * the previous brightness - */ - if (get_pm_old_state() == S_LCDDIM) - display_backlight_update_by_default_brightness(); - - if (check_lcd_is_on() == false) - display_panel_lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); - break; - - case S_LCDDIM: - display_backlight_get_custom_status(&custom_status); - if ((get_pm_old_state() == S_NORMAL) && custom_status) { - display_backlight_get_brightness(&brightness); - display_backlight_set_custom_brightness(brightness); - } - /* lcd dim state : dim the brightness */ - display_backlight_set_brightness_by_dim_brightness(); - - if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) - display_panel_lcd_on_procedure(LCD_DIM, NORMAL_MODE); - break; - - case S_LCDOFF: - if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { - /* lcd off state : turn off the backlight */ - if (display_panel_get_dpms_cached_state() == DPMS_ON) - display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - } - - display_panel_get_lcd_paneloff_mode(&lcd_paneloff_mode); - if (display_panel_get_dpms_cached_state() == DPMS_ON - || lcd_paneloff_mode) - display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - break; - - case S_SLEEP: - if (display_panel_get_dpms_cached_state() == DPMS_ON) - display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - - if (!pm_get_power_lock_support()) { - /* sleep state : set system mode to SUSPEND */ - if (get_wakeup_count(&wakeup_count) < 0) - _E("Wakeup count read error."); - - if (wakeup_count < 0) { - _I("Wakup Event. Can not enter suspend mode."); - goto go_lcd_off; - } - - if (set_wakeup_count(wakeup_count) < 0) { - _E("Wakeup count write error."); - goto go_lcd_off; - } - } - goto go_suspend; - } - - return 0; - -go_suspend: -#ifdef ENABLE_PM_LOG - pm_history_save(PM_LOG_SLEEP, get_pm_cur_state()); -#endif - power_request_change_state(DEVICED_POWER_STATE_SLEEP, HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF_TIMEOUT); - return 0; - -go_lcd_off: - if (!pm_get_power_lock_support()) { - /* Resume !! */ - display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE); - } - return 0; -} - static void default_saving_mode(int onoff) { if (onoff) @@ -773,6 +615,7 @@ int poll_callback(int condition, PMMsg *data) static time_t last_t; time_t now; + display_get_display_ops_status(&status); if (status != DEVICE_OPS_STATUS_START) { _E("Display logic is not started."); return -ECANCELED; @@ -1360,7 +1203,7 @@ static void display_init(void *data) if (ret < 0) _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); - status = DEVICE_OPS_STATUS_START; + display_set_display_ops_status(DEVICE_OPS_STATUS_START); if (display_conf.timeout_enable) { timeout = states[S_NORMAL].timeout; /* check minimun lcd on time */ @@ -1382,7 +1225,7 @@ static void display_exit(void *data) { int i = INIT_END; - status = DEVICE_OPS_STATUS_STOP; + display_set_display_ops_status(DEVICE_OPS_STATUS_STOP); /* Set current state to S_NORMAL */ set_pm_cur_state(S_NORMAL); @@ -1445,6 +1288,7 @@ static int display_start(enum device_flags flags) if (!(flags & CORE_LOGIC_MODE)) return 0; + display_get_display_ops_status(&status); if (status == DEVICE_OPS_STATUS_START) return -EALREADY; @@ -1468,6 +1312,7 @@ static int display_stop(enum device_flags flags) if (!(flags & CORE_LOGIC_MODE)) return 0; + display_get_display_ops_status(&status); if (status == DEVICE_OPS_STATUS_STOP) return -EALREADY; diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index e53409e..8397009 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -100,21 +100,17 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; static int system_wakeup_flag = false; static char *custom_change_name; -static struct timeval lcdon_tv; - -/* default transition, action fuctions */ -static int default_action(int timeout); static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; static struct state states[S_END] = { { S_START, "S_START", NULL, NULL, NULL, NULL }, - { S_NORMAL, "S_NORMAL", NULL, default_action, NULL, NULL }, - { S_LCDDIM, "S_LCDDIM", NULL, default_action, NULL, NULL }, - { S_LCDOFF, "S_LCDOFF", NULL, default_action, NULL, NULL }, + { S_NORMAL, "S_NORMAL", NULL, NULL, NULL, NULL }, + { S_LCDDIM, "S_LCDDIM", NULL, NULL, NULL, NULL }, + { S_LCDOFF, "S_LCDOFF", NULL, NULL, NULL, NULL }, { S_STANDBY, "S_STANDBY", NULL, NULL, NULL, NULL }, - { S_SLEEP, "S_SLEEP", NULL, default_action, NULL, NULL }, + { S_SLEEP, "S_SLEEP", NULL, NULL, NULL, NULL }, { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, }; @@ -131,11 +127,6 @@ static struct state states[S_END] = { #define CONTINUOUS_SAMPLING 1 #define LCDOFF_TIMEOUT 300 /* milli second */ -#define DIFF_TIMEVAL_MS(a, b) \ - (((a.tv_sec * 1000000 + a.tv_usec) - \ - (b.tv_sec * 1000000 + b.tv_usec)) \ - / 1000) - static struct display_config display_conf = { .lock_wait_time = LOCK_SCREEN_WATING_TIME, .longpress_interval = LONG_PRESS_INTERVAL, @@ -215,20 +206,12 @@ void lcd_on_direct(enum device_flags flags) set_pm_cur_state(S_NORMAL); _D("lcd is on directly"); - gettimeofday(&lcdon_tv, NULL); + display_panel_update_lcd_on_timeval(); display_panel_lcd_on_procedure(LCD_NORMAL, flags); update_display_locktime(LOCK_SCREEN_INPUT_TIMEOUT); } -static inline bool check_lcd_is_on(void) -{ - if (display_panel_get_dpms_cached_state() != DPMS_ON) - return false; - - return true; -} - static gboolean timer_refresh_cb(gpointer data) { struct state *st; @@ -238,8 +221,7 @@ static gboolean timer_refresh_cb(gpointer data) set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -251,7 +233,7 @@ int custom_lcdon(int timeout) if (timeout <= 0) return -EINVAL; - if (check_lcd_is_on() == false) + if (display_panel_get_dpms_cached_state() != DPMS_ON) lcd_on_direct(LCD_ON_BY_GESTURE); _I("Custom lcd on timeout(%d ms).", timeout); @@ -263,9 +245,7 @@ int custom_lcdon(int timeout) set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); g_idle_add(timer_refresh_cb, NULL); @@ -307,9 +287,7 @@ int custom_lcdoff(enum device_flags flag) set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -336,7 +314,7 @@ int display_on_by_reason(const char *reason, int timeout) return -EINVAL; } - if (check_lcd_is_on() == false) + if (display_panel_get_dpms_cached_state() != DPMS_ON) lcd_on_direct(flag); _I("platform lcd on by %s (%d ms)", reason, timeout); @@ -348,9 +326,7 @@ int display_on_by_reason(const char *reason, int timeout) set_pm_cur_state(S_NORMAL); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -392,9 +368,7 @@ int display_off_by_reason(const char *reason) set_pm_cur_state(S_LCDOFF); st = &states[get_pm_cur_state()]; - /* enter action */ - if (st->action) - st->action(st->timeout); + display_state_transition_do_state_action(st->timeout); return 0; } @@ -408,12 +382,10 @@ static void default_proc_change_state_action(enum state_t next, int timeout) st = &states[get_pm_cur_state()]; - if (st && st->action) { - if (timeout < 0) - st->action(st->timeout); - else - st->action(timeout); - } + if (timeout < 0) + display_state_transition_do_state_action(st->timeout); + else + display_state_transition_do_state_action(timeout); } static int default_proc_change_state(unsigned int cond, pid_t pid) @@ -425,7 +397,7 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) switch (next) { case S_NORMAL: - if (check_lcd_is_on() == false) + if (display_panel_get_dpms_cached_state() != DPMS_ON) lcd_on_direct(LCD_ON_BY_EVENT); update_display_locktime(LOCK_SCREEN_CONTROL_TIMEOUT); default_proc_change_state_action(next, -1); @@ -617,136 +589,6 @@ static void sig_hup(int signo) pm_save_logdump(); } -/* default enter action function */ -static int default_action(int timeout) -{ - int wakeup_count = -1, pm_cur_state; - time_t now; - double diff; - static time_t last_update_time = 0; - static int last_timeout = 0; - struct timeval now_tv; - bool custom_status; - int brightness; - bool lcd_paneloff_mode = false; - - if (status != DEVICE_OPS_STATUS_START) { - _E("Display is not started."); - return -EINVAL; - } - - if (get_pm_cur_state() != S_SLEEP) { - if ((get_pm_cur_state() == S_NORMAL) && - lcdon_tv.tv_sec != 0) { - gettimeofday(&now_tv, NULL); - timeout -= DIFF_TIMEVAL_MS(now_tv, lcdon_tv); - lcdon_tv.tv_sec = 0; - } - /* set timer with current state timeout */ - display_state_transition_reset_state_transition_timeout(timeout); - - if (get_pm_cur_state() == S_NORMAL) { - time(&last_update_time); - last_timeout = timeout; - } else { - _I("Timout set: %s state %d ms", - states[get_pm_cur_state()].name, timeout); - } - } - - if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) { - power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, - power_get_wakeup_reason(), NULL); - set_setting_pmstate(get_pm_cur_state()); - pm_cur_state = get_pm_cur_state(); - device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); - } - - if ((get_pm_old_state() == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { - time(&now); - diff = difftime(now, last_update_time); - _I("S_NORMAL is changed to %s (timeout=%d ms diff=%.0f s).", - states[get_pm_cur_state()].name, last_timeout, diff); - } - - switch (get_pm_cur_state()) { - case S_NORMAL: - /* - * normal state : backlight on and restore - * the previous brightness - */ - if (get_pm_old_state() == S_LCDDIM) - display_backlight_update_by_default_brightness(); - - if (check_lcd_is_on() == false) - display_panel_lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); - break; - - case S_LCDDIM: - display_backlight_get_custom_status(&custom_status); - if ((get_pm_old_state() == S_NORMAL) && custom_status) { - display_backlight_get_brightness(&brightness); - display_backlight_set_custom_brightness(brightness); - } - /* lcd dim state : dim the brightness */ - display_backlight_set_brightness_by_dim_brightness(); - - if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) - display_panel_lcd_on_procedure(LCD_DIM, NORMAL_MODE); - break; - - case S_LCDOFF: - if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { - /* lcd off state : turn off the backlight */ - if (display_panel_get_dpms_cached_state() == DPMS_ON) - display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - } - - display_panel_get_lcd_paneloff_mode(&lcd_paneloff_mode); - if (display_panel_get_dpms_cached_state() == DPMS_ON - || lcd_paneloff_mode) - display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - break; - - case S_SLEEP: - if (display_panel_get_dpms_cached_state() == DPMS_ON) - display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - - if (!pm_get_power_lock_support()) { - /* sleep state : set system mode to SUSPEND */ - if (get_wakeup_count(&wakeup_count) < 0) - _E("Wakeup count read error."); - - if (wakeup_count < 0) { - _I("Wakup Event. Can not enter suspend mode."); - goto go_lcd_off; - } - - if (set_wakeup_count(wakeup_count) < 0) { - _E("Wakeup count write error."); - goto go_lcd_off; - } - } - goto go_suspend; - } - - return 0; - -go_suspend: -#ifdef ENABLE_PM_LOG - pm_history_save(PM_LOG_SLEEP, get_pm_cur_state()); -#endif - power_request_change_state(DEVICED_POWER_STATE_SLEEP, HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF_TIMEOUT); - return 0; - -go_lcd_off: - if (!pm_get_power_lock_support()) { - /* Resume !! */ - display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE); - } - return 0; -} - static void default_saving_mode(int onoff) { if (onoff) @@ -763,6 +605,7 @@ int poll_callback(int condition, PMMsg *data) static time_t last_t; time_t now; + display_get_display_ops_status(&status); if (status != DEVICE_OPS_STATUS_START) { _E("Display logic is not started."); return -ECANCELED; @@ -1351,7 +1194,7 @@ static void display_init(void *data) if (ret < 0) _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); - status = DEVICE_OPS_STATUS_START; + display_set_display_ops_status(DEVICE_OPS_STATUS_START); if (display_conf.timeout_enable) { timeout = states[S_NORMAL].timeout; /* check minimun lcd on time */ @@ -1373,7 +1216,7 @@ static void display_exit(void *data) { int i = INIT_END; - status = DEVICE_OPS_STATUS_STOP; + display_set_display_ops_status(DEVICE_OPS_STATUS_STOP); /* Set current state to S_NORMAL */ set_pm_cur_state(S_NORMAL); @@ -1431,6 +1274,7 @@ static int display_start(enum device_flags flags) if (!(flags & CORE_LOGIC_MODE)) return 0; + display_get_display_ops_status(&status); if (status == DEVICE_OPS_STATUS_START) return -EALREADY; @@ -1454,6 +1298,7 @@ static int display_stop(enum device_flags flags) if (!(flags & CORE_LOGIC_MODE)) return 0; + display_get_display_ops_status(&status); if (status == DEVICE_OPS_STATUS_STOP) return -EALREADY; diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 2aadae3..ee2c0a5 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -113,7 +113,6 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; static int system_wakeup_flag = false; static char *custom_change_name; static guint transit_timer; -static struct timeval lcdon_tv; /* * The two variables(lcdon_broadcast, pmstate_suspend) must be set initial * state because it should be sent from previous state at booting time. @@ -150,11 +149,6 @@ static struct state states[S_END] = { #define CONTINUOUS_SAMPLING 1 #define LCDOFF_TIMEOUT 300 /* milli second */ -#define DIFF_TIMEVAL_MS(a, b) \ - (((a.tv_sec * 1000000 + a.tv_usec) - \ - (b.tv_sec * 1000000 + b.tv_usec)) \ - / 1000) - #define FORCE_RELEASE_LOCK_INTERVAL 5 /* seconds */ static struct display_config display_conf = { @@ -429,7 +423,7 @@ void lcd_on_direct(enum device_flags flags) set_pm_cur_state(S_NORMAL); _D("lcd is on directly"); - gettimeofday(&lcdon_tv, NULL); + display_panel_update_lcd_on_timeval(); lcd_on_procedure(LCD_NORMAL, flags); update_display_locktime(LOCK_SCREEN_INPUT_TIMEOUT); @@ -932,11 +926,12 @@ static int default_action(int timeout) double diff; static time_t last_update_time = 0; static int last_timeout = 0; - struct timeval now_tv; bool custom_status; int brightness; bool lcd_paneloff_mode = false; + int diff_time = 0; + display_get_display_ops_status(&status); if (status != DEVICE_OPS_STATUS_START) { _E("Display is not started."); return -EINVAL; @@ -951,11 +946,10 @@ static int default_action(int timeout) } if (get_pm_cur_state() != S_SLEEP) { - if ((get_pm_cur_state() == S_NORMAL) && - lcdon_tv.tv_sec != 0) { - gettimeofday(&now_tv, NULL); - timeout -= DIFF_TIMEVAL_MS(now_tv, lcdon_tv); - lcdon_tv.tv_sec = 0; + if ((get_pm_cur_state() == S_NORMAL)) { + if (display_panel_calculate_diff_time_between_lcd_on_direct_and_state_action(&diff_time) == 0) { + timeout -= diff_time; + } } /* set timer with current state timeout */ display_state_transition_reset_state_transition_timeout(timeout); @@ -1081,6 +1075,7 @@ int poll_callback(int condition, PMMsg *data) static time_t last_t; time_t now; + display_get_display_ops_status(&status); if (status != DEVICE_OPS_STATUS_START) { _E("Display logic is not started."); return -ECANCELED; @@ -1699,7 +1694,7 @@ static void display_init(void *data) if (ret < 0) _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); - status = DEVICE_OPS_STATUS_START; + display_set_display_ops_status(DEVICE_OPS_STATUS_START); if (display_conf.timeout_enable) { timeout = states[S_NORMAL].timeout; /* check minimun lcd on time */ @@ -1721,7 +1716,7 @@ static void display_exit(void *data) { int i = INIT_END; - status = DEVICE_OPS_STATUS_STOP; + display_set_display_ops_status(DEVICE_OPS_STATUS_STOP); /* Set current state to S_NORMAL */ set_pm_cur_state(S_NORMAL); @@ -1784,6 +1779,7 @@ static int display_start(enum device_flags flags) if (!(flags & CORE_LOGIC_MODE)) return 0; + display_get_display_ops_status(&status); if (status == DEVICE_OPS_STATUS_START) return -EALREADY; @@ -1807,6 +1803,7 @@ static int display_stop(enum device_flags flags) if (!(flags & CORE_LOGIC_MODE)) return 0; + display_get_display_ops_status(&status); if (status == DEVICE_OPS_STATUS_STOP) return -EALREADY; diff --git a/src/display/display-panel.c b/src/display/display-panel.c index 2c94538..813bedb 100644 --- a/src/display/display-panel.c +++ b/src/display/display-panel.c @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "shared/log.h" #include "power/power-suspend.h" @@ -34,9 +35,15 @@ #define LCD_PHASED_MIN_BRIGHTNESS 1 #define LCD_PHASED_CHANGE_STEP 5 +#define DIFF_TIMEVAL_MS(a, b) \ + (((a.tv_sec * 1000000 + a.tv_usec) - \ + (b.tv_sec * 1000000 + b.tv_usec)) \ + / 1000) + static int dpms_running_state = DPMS_SETTING_DONE; static bool lcd_paneloff_mode = false; static bool lcd_on_broadcasted = true; +static struct timeval lcd_on_timeval; /* FIXME: This function is for temporary use, should be fixed after plugin refactoring */ int display_panel_set_dpms_state(int dpms_on, enum device_flags flags) @@ -304,6 +311,28 @@ bool display_panel_is_lcd_on_state_broadcasted(void) return lcd_on_broadcasted; } +/* FIXME: lcd on time calculation should be discussed, because it is only for lcd_on_direct routine */ +void display_panel_update_lcd_on_timeval(void) +{ + gettimeofday(&lcd_on_timeval, NULL); +} + +int display_panel_calculate_diff_time_between_lcd_on_direct_and_state_action(int *diff_time) +{ + struct timeval now_timeval; + + if (!diff_time) + return -EINVAL; + + if (lcd_on_timeval.tv_sec != 0) { + gettimeofday(&now_timeval, NULL); + *diff_time = DIFF_TIMEVAL_MS(now_timeval, lcd_on_timeval); + return 0; + } + + return -1; +} + /* FIXME: This function is deprecated, should be fixed after plugin refactoring */ void display_panel_set_dpms_running_state(int val) { diff --git a/src/display/display-panel.h b/src/display/display-panel.h index 862fc35..e6bb4c6 100644 --- a/src/display/display-panel.h +++ b/src/display/display-panel.h @@ -35,6 +35,8 @@ void display_panel_get_lcd_paneloff_mode(bool *on); void display_panel_lcd_on_procedure(int state, enum device_flags flag); void display_panel_lcd_off_procedure(enum device_flags flag); 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); /* Deprecated functions */ int display_panel_set_image_effect(enum display_image_effect effect); int display_panel_get_image_effect(enum display_image_effect *effect); diff --git a/src/display/display-plugin.c b/src/display/display-plugin.c index d588965..c46b17b 100644 --- a/src/display/display-plugin.c +++ b/src/display/display-plugin.c @@ -168,23 +168,6 @@ bool display_plugin_state_is_there_default_trans(enum state_t state) return false; } -int display_plugin_state_do_default_action(enum state_t state, int timeout) -{ - if (g_display_plugin.display_states[state] && g_display_plugin.display_states[state]->action) - return g_display_plugin.display_states[state]->action(timeout); - - return -EOPNOTSUPP; -} - -/* FIXME: default_action/default_trans naming should be changed after state transition functions are relocated */ -bool display_plugin_state_is_there_default_action(enum state_t state) -{ - if (g_display_plugin.display_states[state] && g_display_plugin.display_states[state]->action) - return true; - - return false; -} - int display_plugin_state_get_name(enum state_t state, const char **state_name) { if (!state_name) diff --git a/src/display/display-plugin.h b/src/display/display-plugin.h index d66dcac..9b256f4 100644 --- a/src/display/display-plugin.h +++ b/src/display/display-plugin.h @@ -98,8 +98,6 @@ int display_plugin_backlight_transit_brightness(int start, int end, int step); /* FIXME: function names will be redefined */ int display_plugin_state_do_default_trans(enum state_t state, int evt); bool display_plugin_state_is_there_default_trans(enum state_t state); -int display_plugin_state_do_default_action(enum state_t state, int timeout); -bool display_plugin_state_is_there_default_action(enum state_t state); int display_plugin_state_get_name(enum state_t state, const char **state_name); int display_plugin_state_set_timeout(enum state_t state, int state_timeout); int display_plugin_state_get_timeout(enum state_t state, int *state_timeout); diff --git a/src/display/display-state-transition.c b/src/display/display-state-transition.c index c7a5dff..1518b46 100644 --- a/src/display/display-state-transition.c +++ b/src/display/display-state-transition.c @@ -21,14 +21,15 @@ * @brief This file has functions related to display state transition */ +#include "shared/log.h" #include "core/udev.h" #include "device-interface.h" #include "display-state-transition.h" #include "display-lock.h" #include "display-plugin.h" #include "extcon/extcon.h" +#include "power/power.h" #include "power/power-suspend.h" -#include "shared/log.h" #define ALWAYS_ON_TIMEOUT 360000000 @@ -381,7 +382,7 @@ int display_state_transition_do_state_transition(enum state_t state, int evt_typ set_pm_cur_state(next_state); /* enter action */ - if (display_plugin_state_is_there_default_action(get_pm_cur_state())) { + if (display_state_transition_is_display_state_support_transition(get_pm_cur_state())) { if (get_pm_cur_state() == S_LCDOFF) display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); @@ -398,8 +399,145 @@ int display_state_transition_do_state_transition(enum state_t state, int evt_typ return 0; display_plugin_state_get_timeout(get_pm_cur_state(), &timeout); - display_plugin_state_do_default_action(get_pm_cur_state(), timeout); + display_state_transition_do_state_action(timeout); + } + } + return 0; +} + +/* FIXME: diff time calculation, set_wakeup_count should be discussed again later */ +int display_state_transition_do_state_action(int timeout) +{ + int wakeup_count = -1, pm_cur_state; + time_t now; + double diff = 0; + static time_t last_update_time = 0; + static int last_timeout = 0; + bool custom_status; + int brightness; + bool lcd_paneloff_mode = false; + const char* state_name; + enum device_ops_status display_ops_status; + int diff_time = 0; + + if (!display_state_transition_is_display_state_support_transition(get_pm_cur_state())) + return -EPERM; + + display_get_display_ops_status(&display_ops_status); + if (display_ops_status != DEVICE_OPS_STATUS_START) { + _E("Display is not started."); + return -EINVAL; + } + + if (get_pm_cur_state() != S_SLEEP) { + if ((get_pm_cur_state() == S_NORMAL)) { + if (display_panel_calculate_diff_time_between_lcd_on_direct_and_state_action(&diff_time) == 0) { + timeout -= diff_time; + } + } + + /* set timer with current state timeout */ + display_state_transition_reset_state_transition_timeout(timeout); + + if (get_pm_cur_state() == S_NORMAL) { + time(&last_update_time); + last_timeout = timeout; + } else { + display_plugin_state_get_name(get_pm_cur_state(), &state_name); + _I("Timout set: %s state %d ms", state_name, timeout); + } + } + + if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) { + power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, + power_get_wakeup_reason(), NULL); + set_setting_pmstate(get_pm_cur_state()); + pm_cur_state = get_pm_cur_state(); + device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); + } + + if ((get_pm_old_state() == S_NORMAL) && (get_pm_cur_state() != S_NORMAL)) { + time(&now); + diff = difftime(now, last_update_time); + display_plugin_state_get_name(get_pm_cur_state(), &state_name); + _I("S_NORMAL is changed to %s (timeout=%d ms diff=%.0f s).", + state_name, last_timeout, diff); + } + + switch (get_pm_cur_state()) { + case S_NORMAL: + /* + * normal state : backlight on and restore + * the previous brightness + */ + if (get_pm_old_state() == S_LCDDIM) + display_backlight_update_by_default_brightness(); + + if (display_panel_get_dpms_cached_state() != DPMS_ON) + display_panel_lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); + break; + + case S_LCDDIM: + display_backlight_get_custom_status(&custom_status); + if ((get_pm_old_state() == S_NORMAL) && custom_status) { + display_backlight_get_brightness(&brightness); + display_backlight_set_custom_brightness(brightness); + } + /* lcd dim state : dim the brightness */ + display_backlight_set_brightness_by_dim_brightness(); + + if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) + display_panel_lcd_on_procedure(LCD_DIM, NORMAL_MODE); + break; + + case S_LCDOFF: + if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { + /* lcd off state : turn off the backlight */ + if (display_panel_get_dpms_cached_state() == DPMS_ON) + display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); } + + display_panel_get_lcd_paneloff_mode(&lcd_paneloff_mode); + if (display_panel_get_dpms_cached_state() == DPMS_ON + || lcd_paneloff_mode) + display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); + break; + + case S_SLEEP: + if (display_panel_get_dpms_cached_state() == DPMS_ON) + display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT); + + if (!pm_get_power_lock_support()) { + /* sleep state : set system mode to SUSPEND */ + if (get_wakeup_count(&wakeup_count) < 0) + _E("Wakeup count read error."); + + if (wakeup_count < 0) { + _I("Wakup Event. Can not enter suspend mode."); + goto go_lcd_off; + } + + if (set_wakeup_count(wakeup_count) < 0) { + _E("Wakeup count write error."); + goto go_lcd_off; + } + } + goto go_suspend; + } + + return 0; + +go_suspend: +#ifdef ENABLE_PM_LOG + pm_history_save(PM_LOG_SLEEP, get_pm_cur_state()); +#endif + power_request_change_state(DEVICED_POWER_STATE_SLEEP, HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF_TIMEOUT); + return 0; + +go_lcd_off: + if (!pm_get_power_lock_support()) { + /* Resume !! */ + display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE); } return 0; } \ No newline at end of file diff --git a/src/display/display-state-transition.h b/src/display/display-state-transition.h index eeead2f..9182243 100644 --- a/src/display/display-state-transition.h +++ b/src/display/display-state-transition.h @@ -42,5 +42,6 @@ int display_state_transition_update_lcdoff_reason(int source); bool display_state_transition_is_possible_to_go_lcdoff(void); int display_state_transition_do_state_transition(enum state_t state, int evt_type); bool display_state_transition_is_display_state_support_transition(enum state_t state); +int display_state_transition_do_state_action(int timeout); #endif /* __DISPLAY_STATE_TRANSITION_H__ */ \ No newline at end of file diff --git a/src/display/display.c b/src/display/display.c index 0fe45c8..3418711 100644 --- a/src/display/display.c +++ b/src/display/display.c @@ -33,6 +33,7 @@ static unsigned int pm_status_flag; static enum display_init_direction_e g_display_init_direction; static bool g_display_hal_backend_available; static GList *display_dependent_device_ops; +static enum device_ops_status display_ops_status = DEVICE_OPS_STATUS_UNINIT; inline int get_pm_cur_state(void) { @@ -192,6 +193,23 @@ int display_initialize_display_state_timeout_from_setting(void) return 0; } +/** FIXME: display_ops_status getter/setter will be removed after plugin-core separation + This work should be proceeded in the display core +*/ +void display_set_display_ops_status(enum device_ops_status dev_ops_status) +{ + display_ops_status = dev_ops_status; +} + +int display_get_display_ops_status(enum device_ops_status *dev_ops_status) +{ + if (!dev_ops_status) + return -EINVAL; + + *dev_ops_status = display_ops_status; + return 0; +} + static int display_probe(void *data) { display_plugin_device_ops = find_device("display-plugin"); diff --git a/src/display/display.h b/src/display/display.h index 42b0096..d54fd31 100644 --- a/src/display/display.h +++ b/src/display/display.h @@ -57,5 +57,7 @@ void display_register_dependent_device(const struct device_ops *ops); void display_unregister_dependent_device(void); bool display_dimstay_check(void); int display_initialize_display_state_timeout_from_setting(void); +void display_set_display_ops_status(enum device_ops_status dev_ops_status); +int display_get_display_ops_status(enum device_ops_status *dev_ops_status); #endif //__DISPLAY_H__ -- 2.7.4 From 9f9ed65f7211990425d03b5a79719a7e0efe5869 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 13 Jun 2023 12:36:07 +0900 Subject: [PATCH 14/16] display: Remove unused holdkeyblock code Change-Id: I28ad71cca7b84f459adf333765ac213e6eb31929 Signed-off-by: Youngjae Cho --- plugins/iot-headed/display/core.c | 27 ++++------------- plugins/iot-headed/display/key-filter.c | 33 +++++++++------------ plugins/mobile/display/core.c | 27 ++++------------- plugins/mobile/display/key-filter.c | 33 +++++++++------------ plugins/tv/display/core.c | 27 ++++------------- plugins/tv/display/key-filter.c | 33 +++++++++------------ plugins/wearable/display/core.c | 26 ++++------------ plugins/wearable/display/key-filter.c | 33 +++++++++------------ src/display/core.h | 2 +- src/display/display-lock.c | 51 ++------------------------------ src/display/display-lock.h | 7 +---- src/display/plugin-common/display-dbus.c | 13 ++++---- src/display/plugin-common/poll.c | 3 -- src/display/poll.h | 3 -- src/libdeviced/display.c | 9 +----- 15 files changed, 91 insertions(+), 236 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 484832f..a547016 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -259,7 +259,6 @@ int custom_lcdoff(enum device_flags flag) check_processes(S_NORMAL); check_processes(S_LCDDIM); - /* check holdkey block flag in lock node */ if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { /* * When another proccess is normal lock, device is received call then, @@ -343,7 +342,6 @@ int display_off_by_reason(const char *reason) check_processes(S_NORMAL); check_processes(S_LCDDIM); - /* check holdkey block flag in lock node */ if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { _I("skip platform lcd off by gesture"); return -ECANCELED; @@ -442,7 +440,7 @@ static void proc_condition_lock(PMMsg *data) char pname[PATH_MAX]; pid_t pid = data->pid; enum state_t state; - int holdkey_block, ret; + int ret; bool value = true; unsigned int flags; const char *lock_type = NULL; @@ -458,8 +456,7 @@ static void proc_condition_lock(PMMsg *data) (pm_get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); - holdkey_block = GET_COND_FLAG(data->cond) & PM_FLAG_BLOCK_HOLDKEY; - tmp = display_lock_add_pmlock_node(state, pid, holdkey_block, data->timeout); + tmp = display_lock_add_pmlock_node(state, pid, data->timeout); if (!tmp) { _E("Failed to acquire lock, state: %d, pid: %d.", state, pid); return; @@ -491,8 +488,8 @@ static void proc_condition_lock(PMMsg *data) } } - _SD("be requested LOCK info pname(%s), holdkeyblock(%d) flags(%d)", - pname, holdkey_block, flags); + _SD("be requested LOCK info pname(%s), flags(%d)", + pname, flags); set_lock_time(pid, pname, state); device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value); @@ -821,7 +818,7 @@ static const char *errMSG[INIT_END] = { [INIT_DBUS] = "d-bus init error", }; -int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) +int set_lcd_timeout(int on, int dim, const char *name) { unsigned int custom_normal_timeout = 0; unsigned int custom_dim_timeout = 0; @@ -843,14 +840,6 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) if (get_pm_cur_state() == S_NORMAL) display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); - if (holdkey_block) { - display_lock_set_custom_holdkey_block(true); - _I("Hold key disabled."); - } else { - display_lock_set_custom_holdkey_block(false); - _I("Hold key enabled."); - } - if (custom_change_name) { free(custom_change_name); custom_change_name = 0; @@ -858,9 +847,7 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) display_state_transition_get_custom_timeout(S_NORMAL, &custom_normal_timeout); display_state_transition_get_custom_timeout(S_LCDDIM, &custom_dim_timeout); - if (custom_normal_timeout == 0 && - custom_dim_timeout == 0 && - !holdkey_block) + if (custom_normal_timeout == 0 && custom_dim_timeout == 0) return 0; custom_change_name = strndup(name, strlen(name)); @@ -868,7 +855,6 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) _E("Failed to malloc."); display_state_transition_set_custom_timeout(S_NORMAL, 0); display_state_transition_set_custom_timeout(S_LCDDIM, 0); - display_lock_set_custom_holdkey_block(false); return -ENOMEM; } @@ -895,7 +881,6 @@ void reset_lcd_timeout(GDBusConnection *conn, custom_change_name = 0; display_state_transition_set_custom_timeout(S_NORMAL, 0); display_state_transition_set_custom_timeout(S_LCDDIM, 0); - display_lock_set_custom_holdkey_block(false); display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) diff --git a/plugins/iot-headed/display/key-filter.c b/plugins/iot-headed/display/key-filter.c index c6aa7d1..a2f7b34 100644 --- a/plugins/iot-headed/display/key-filter.c +++ b/plugins/iot-headed/display/key-filter.c @@ -389,17 +389,14 @@ static int lcdoff_powerkey(void) check_processes(S_NORMAL); check_processes(S_LCDDIM); - if (!check_holdkey_block(S_NORMAL) && - !check_holdkey_block(S_LCDDIM)) { - if (display_info.update_auto_brightness) - display_info.update_auto_brightness(false); - switch_off_lcd(); - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); - display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); - } + if (display_info.update_auto_brightness) + display_info.update_auto_brightness(false); + switch_off_lcd(); + delete_condition(S_NORMAL); + delete_condition(S_LCDDIM); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); } else { ignore = false; skip_combination = false; @@ -507,15 +504,13 @@ static int process_screenlock_key(struct input_event *pinput) check_processes(S_NORMAL); check_processes(S_LCDDIM); - if (!check_holdkey_block(S_NORMAL) && !check_holdkey_block(S_LCDDIM)) { - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); - display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); + delete_condition(S_NORMAL); + delete_condition(S_LCDDIM); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); - /* LCD off forcly */ - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(-1, LCD_OFF); - } + /* LCD off forcly */ + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(-1, LCD_OFF); return true; } diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index b6f15f0..8ea1bf6 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -266,7 +266,6 @@ int custom_lcdoff(enum device_flags flag) check_processes(S_NORMAL); check_processes(S_LCDDIM); - /* check holdkey block flag in lock node */ if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { /* * When another proccess is normal lock, device is received call then, @@ -350,7 +349,6 @@ int display_off_by_reason(const char *reason) check_processes(S_NORMAL); check_processes(S_LCDDIM); - /* check holdkey block flag in lock node */ if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { _I("skip platform lcd off by gesture"); return -ECANCELED; @@ -452,7 +450,7 @@ static void proc_condition_lock(PMMsg *data) char pname[PATH_MAX]; pid_t pid = data->pid; enum state_t state; - int holdkey_block, ret; + int ret; bool value = true; unsigned int flags; const char *lock_type = NULL; @@ -468,8 +466,7 @@ static void proc_condition_lock(PMMsg *data) (pm_get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); - holdkey_block = GET_COND_FLAG(data->cond) & PM_FLAG_BLOCK_HOLDKEY; - tmp = display_lock_add_pmlock_node(state, pid, holdkey_block, data->timeout); + tmp = display_lock_add_pmlock_node(state, pid, data->timeout); if (!tmp) { _E("Failed to acquire lock, state: %d, pid: %d.", state, pid); return; @@ -500,8 +497,8 @@ static void proc_condition_lock(PMMsg *data) _E("Failed to send dbus signal PowerLock."); } } - _SD("be requested LOCK info pname(%s), holdkeyblock(%d) flags(%d)", - pname, holdkey_block, flags); + _SD("be requested LOCK info pname(%s), flags(%d)", + pname, flags); set_lock_time(pid, pname, state); device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value); @@ -830,7 +827,7 @@ static const char *errMSG[INIT_END] = { [INIT_DBUS] = "d-bus init error", }; -int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) +int set_lcd_timeout(int on, int dim, const char *name) { unsigned int custom_normal_timeout = 0; unsigned int custom_dim_timeout = 0; @@ -852,14 +849,6 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) if (get_pm_cur_state() == S_NORMAL) display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); - if (holdkey_block) { - display_lock_set_custom_holdkey_block(true); - _I("Hold key disabled."); - } else { - display_lock_set_custom_holdkey_block(false); - _I("Hold key enabled."); - } - if (custom_change_name) { free(custom_change_name); custom_change_name = 0; @@ -867,9 +856,7 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) display_state_transition_get_custom_timeout(S_NORMAL, &custom_normal_timeout); display_state_transition_get_custom_timeout(S_LCDDIM, &custom_dim_timeout); - if (custom_normal_timeout == 0 && - custom_dim_timeout == 0 && - !holdkey_block) + if (custom_normal_timeout == 0 && custom_dim_timeout == 0) return 0; custom_change_name = strndup(name, strlen(name)); @@ -877,7 +864,6 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) _E("Failed to malloc."); display_state_transition_set_custom_timeout(S_NORMAL, 0); display_state_transition_set_custom_timeout(S_LCDDIM, 0); - display_lock_set_custom_holdkey_block(false); return -ENOMEM; } @@ -904,7 +890,6 @@ void reset_lcd_timeout(GDBusConnection *conn, custom_change_name = 0; display_state_transition_set_custom_timeout(S_NORMAL, 0); display_state_transition_set_custom_timeout(S_LCDDIM, 0); - display_lock_set_custom_holdkey_block(false); display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index a8dbe81..b687754 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -379,17 +379,14 @@ static int lcdoff_powerkey(void) check_processes(S_NORMAL); check_processes(S_LCDDIM); - if (!check_holdkey_block(S_NORMAL) && - !check_holdkey_block(S_LCDDIM)) { - if (display_info.update_auto_brightness) - display_info.update_auto_brightness(false); - switch_off_lcd(); - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); - display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); - } + if (display_info.update_auto_brightness) + display_info.update_auto_brightness(false); + switch_off_lcd(); + delete_condition(S_NORMAL); + delete_condition(S_LCDDIM); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); } else { ignore = false; skip_combination = false; @@ -540,15 +537,13 @@ static int process_screenlock_key(struct input_event *pinput) check_processes(S_NORMAL); check_processes(S_LCDDIM); - if (!check_holdkey_block(S_NORMAL) && !check_holdkey_block(S_LCDDIM)) { - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); - display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); + delete_condition(S_NORMAL); + delete_condition(S_LCDDIM); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); - /* LCD off forcly */ - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(-1, LCD_OFF); - } + /* LCD off forcly */ + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(-1, LCD_OFF); return true; } diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 8397009..a585c86 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -259,7 +259,6 @@ int custom_lcdoff(enum device_flags flag) check_processes(S_NORMAL); check_processes(S_LCDDIM); - /* check holdkey block flag in lock node */ if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { /* * When another proccess is normal lock, device is received call then, @@ -343,7 +342,6 @@ int display_off_by_reason(const char *reason) check_processes(S_NORMAL); check_processes(S_LCDDIM); - /* check holdkey block flag in lock node */ if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { _I("skip platform lcd off by gesture"); return -ECANCELED; @@ -441,7 +439,7 @@ static void proc_condition_lock(PMMsg *data) char pname[PATH_MAX]; pid_t pid = data->pid; enum state_t state; - int holdkey_block, ret; + int ret; bool value = true; unsigned int flags; const char *lock_type = NULL; @@ -457,8 +455,7 @@ static void proc_condition_lock(PMMsg *data) (pm_get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); - holdkey_block = GET_COND_FLAG(data->cond) & PM_FLAG_BLOCK_HOLDKEY; - tmp = display_lock_add_pmlock_node(state, pid, holdkey_block, data->timeout); + tmp = display_lock_add_pmlock_node(state, pid, data->timeout); if (!tmp) { _E("Failed to acquire lock, state: %d, pid: %d.", state, pid); return; @@ -490,8 +487,8 @@ static void proc_condition_lock(PMMsg *data) } } - _SD("be requested LOCK info pname(%s), holdkeyblock(%d) flags(%d)", - pname, holdkey_block, flags); + _SD("be requested LOCK info pname(%s), flags(%d)", + pname, flags); set_lock_time(pid, pname, state); device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value); @@ -820,7 +817,7 @@ static const char *errMSG[INIT_END] = { [INIT_DBUS] = "d-bus init error", }; -int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) +int set_lcd_timeout(int on, int dim, const char *name) { unsigned int custom_normal_timeout = 0; unsigned int custom_dim_timeout = 0; @@ -842,14 +839,6 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) if (get_pm_cur_state() == S_NORMAL) display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT); - if (holdkey_block) { - display_lock_set_custom_holdkey_block(true); - _I("Hold key disabled."); - } else { - display_lock_set_custom_holdkey_block(false); - _I("Hold key enabled."); - } - if (custom_change_name) { free(custom_change_name); custom_change_name = 0; @@ -857,9 +846,7 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) display_state_transition_get_custom_timeout(S_NORMAL, &custom_normal_timeout); display_state_transition_get_custom_timeout(S_LCDDIM, &custom_dim_timeout); - if (custom_normal_timeout == 0 && - custom_dim_timeout == 0 && - !holdkey_block) + if (custom_normal_timeout == 0 && custom_dim_timeout == 0) return 0; custom_change_name = strndup(name, strlen(name)); @@ -867,7 +854,6 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) _E("Failed to malloc."); display_state_transition_set_custom_timeout(S_NORMAL, 0); display_state_transition_set_custom_timeout(S_LCDDIM, 0); - display_lock_set_custom_holdkey_block(false); return -ENOMEM; } @@ -894,7 +880,6 @@ void reset_lcd_timeout(GDBusConnection *conn, custom_change_name = 0; display_state_transition_set_custom_timeout(S_NORMAL, 0); display_state_transition_set_custom_timeout(S_LCDDIM, 0); - display_lock_set_custom_holdkey_block(false); display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index a6c969d..ca54808 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -389,17 +389,14 @@ static int lcdoff_powerkey(void) check_processes(S_NORMAL); check_processes(S_LCDDIM); - if (!check_holdkey_block(S_NORMAL) && - !check_holdkey_block(S_LCDDIM)) { - if (display_info.update_auto_brightness) - display_info.update_auto_brightness(false); - switch_off_lcd(); - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); - display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); - } + if (display_info.update_auto_brightness) + display_info.update_auto_brightness(false); + switch_off_lcd(); + delete_condition(S_NORMAL); + delete_condition(S_LCDDIM); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); } else { ignore = false; skip_combination = false; @@ -507,15 +504,13 @@ static int process_screenlock_key(struct input_event *pinput) check_processes(S_NORMAL); check_processes(S_LCDDIM); - if (!check_holdkey_block(S_NORMAL) && !check_holdkey_block(S_LCDDIM)) { - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); - display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); + delete_condition(S_NORMAL); + delete_condition(S_LCDDIM); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); - /* LCD off forcly */ - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(-1, LCD_OFF); - } + /* LCD off forcly */ + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(-1, LCD_OFF); return true; } diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index ee2c0a5..fecdae8 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -515,7 +515,6 @@ int custom_lcdoff(enum device_flags flag) check_processes(S_NORMAL); check_processes(S_LCDDIM); - /* check holdkey block flag in lock node */ if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { /* * When another proccess is normal lock, device is received call then, @@ -603,7 +602,6 @@ int display_off_by_reason(const char *reason) check_processes(S_NORMAL); check_processes(S_LCDDIM); - /* check holdkey block flag in lock node */ if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { _I("skip platform lcd off by gesture"); return -ECANCELED; @@ -710,7 +708,7 @@ static void proc_condition_lock(PMMsg *data) char pname[PATH_MAX]; pid_t pid = data->pid; enum state_t state; - int holdkey_block, ret; + int ret; bool value = true; unsigned int flags; const char *lock_type = NULL; @@ -726,8 +724,7 @@ static void proc_condition_lock(PMMsg *data) (pm_get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); - holdkey_block = GET_COND_FLAG(data->cond) & PM_FLAG_BLOCK_HOLDKEY; - tmp = display_lock_add_pmlock_node(state, pid, holdkey_block, data->timeout); + tmp = display_lock_add_pmlock_node(state, pid, data->timeout); if (!tmp) { _E("Failed to acquire lock, state: %d, pid: %d.", state, pid); return; @@ -759,7 +756,8 @@ static void proc_condition_lock(PMMsg *data) } } - _SD("be requested LOCK info pname(%s), holdkeyblock(%d) flags(%d)", pname, holdkey_block, flags); + _SD("be requested LOCK info pname(%s), flags(%d)", + pname, flags); set_lock_time(pid, pname, state); device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value); @@ -1288,7 +1286,7 @@ static const char *errMSG[INIT_END] = { [INIT_DBUS] = "d-bus init error", }; -int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) +int set_lcd_timeout(int on, int dim, const char *name) { unsigned int custom_normal_timeout = 0; unsigned int custom_dim_timeout = 0; @@ -1310,14 +1308,6 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) if (get_pm_cur_state() == S_NORMAL) states[get_pm_cur_state()].trans(EVENT_INPUT); - if (holdkey_block) { - display_lock_set_custom_holdkey_block(true); - _I("Hold key disabled."); - } else { - display_lock_set_custom_holdkey_block(false); - _I("Hold key enabled."); - } - if (custom_change_name) { free(custom_change_name); custom_change_name = 0; @@ -1325,9 +1315,7 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) display_state_transition_get_custom_timeout(S_NORMAL, &custom_normal_timeout); display_state_transition_get_custom_timeout(S_LCDDIM, &custom_dim_timeout); - if (custom_normal_timeout == 0 && - custom_dim_timeout == 0 && - !holdkey_block) + if (custom_normal_timeout == 0 && custom_dim_timeout == 0) return 0; custom_change_name = strndup(name, strlen(name)); @@ -1335,7 +1323,6 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name) _E("Failed to malloc."); display_state_transition_set_custom_timeout(S_NORMAL, 0); display_state_transition_set_custom_timeout(S_LCDDIM, 0); - display_lock_set_custom_holdkey_block(false); return -ENOMEM; } @@ -1362,7 +1349,6 @@ void reset_lcd_timeout(GDBusConnection *conn, custom_change_name = 0; display_state_transition_set_custom_timeout(S_NORMAL, 0); display_state_transition_set_custom_timeout(S_LCDDIM, 0); - display_lock_set_custom_holdkey_block(false); display_state_transition_update_display_state_timeout_by_priority(); if (get_pm_cur_state() == S_NORMAL) diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index 19ae629..a40dd48 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -386,17 +386,14 @@ static int lcdoff_powerkey(void) check_processes(S_NORMAL); check_processes(S_LCDDIM); - if (!check_holdkey_block(S_NORMAL) && - !check_holdkey_block(S_LCDDIM)) { - if (display_info.update_auto_brightness) - display_info.update_auto_brightness(false); - switch_off_lcd(); - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); - display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); - } + if (display_info.update_auto_brightness) + display_info.update_auto_brightness(false); + switch_off_lcd(); + delete_condition(S_NORMAL); + delete_condition(S_LCDDIM); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); } else { ignore = false; skip_combination = false; @@ -504,15 +501,13 @@ static int process_screenlock_key(struct input_event *pinput) check_processes(S_NORMAL); check_processes(S_LCDDIM); - if (!check_holdkey_block(S_NORMAL) && !check_holdkey_block(S_LCDDIM)) { - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); - display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); + delete_condition(S_NORMAL); + delete_condition(S_LCDDIM); + display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); - /* LCD off forcly */ - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(-1, LCD_OFF); - } + /* LCD off forcly */ + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(-1, LCD_OFF); return true; } diff --git a/src/display/core.h b/src/display/core.h index 9c07e26..96b4b8e 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -125,7 +125,7 @@ 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, int holdkey_block, const char *name); +int set_lcd_timeout(int on, int dim, const char *name); int custom_lcdon(int timeout); void lcd_on_direct(enum device_flags flags); void broadcast_lcd_off_late(enum device_flags flags); diff --git a/src/display/display-lock.c b/src/display/display-lock.c index 0e20288..ab719d1 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -44,7 +44,6 @@ static GList *cond_head[S_END]; static int trans_condition; -static bool custom_holdkey_block = false; bool check_lock_state(int state) { @@ -313,7 +312,7 @@ static int add_delete_state_cond_callback(unsigned int timeout, PmLockNode *targ return 0; } -static void handle_existing_pmlock_node(bool holdkey_block, unsigned int timeout, PmLockNode *found_node) +static void handle_existing_pmlock_node(unsigned int timeout, PmLockNode *found_node) { time_t now; @@ -323,10 +322,9 @@ static void handle_existing_pmlock_node(bool holdkey_block, unsigned int timeout time(&now); found_node->time = now; - found_node->holdkey_block = holdkey_block; } -PmLockNode *display_lock_add_pmlock_node(enum state_t s_index, pid_t pid, bool holdkey_block, unsigned int timeout) +PmLockNode *display_lock_add_pmlock_node(enum state_t s_index, pid_t pid, unsigned int timeout) { PmLockNode *n; PmLockNode *found_node; @@ -336,7 +334,7 @@ PmLockNode *display_lock_add_pmlock_node(enum state_t s_index, pid_t pid, bool h found_node = find_node(s_index, pid); if (found_node) { - handle_existing_pmlock_node(holdkey_block, timeout, found_node); + handle_existing_pmlock_node(timeout, found_node); return found_node; } @@ -351,7 +349,6 @@ PmLockNode *display_lock_add_pmlock_node(enum state_t s_index, pid_t pid, bool h n->pid = pid; add_delete_state_cond_callback(timeout, n); n->time = now; - n->holdkey_block = holdkey_block; /* LCDOFF lock should be maintained regardless of fg/bg state */ if (n->state == S_NORMAL || n->state == S_LCDDIM) { n->app_background = is_app_background(n->pid); @@ -408,7 +405,6 @@ int check_lock_condition(enum state_t state) const char *state_name = NULL; display_plugin_state_get_name(state, &state_name); - _D("check holdkey block : state of %s", state_name); SYS_G_LIST_FOREACH(cond_head[state], elem, t) { if (t->pid != owner && t->app_background == false) { @@ -421,32 +417,6 @@ int check_lock_condition(enum state_t state) return ret; } -int check_holdkey_block(enum state_t state) -{ - GList *elem; - PmLockNode *t = NULL; - int ret = 0; - const char *state_name = NULL; - - display_plugin_state_get_name(state, &state_name); - _I("Check holdkey block: state of %s", state_name); - - if (custom_holdkey_block == true) { - _I("Custom hold key blocked"); - return 1; - } - - SYS_G_LIST_FOREACH(cond_head[state], elem, t) { - if (t->holdkey_block == true) { - ret = 1; - _I("Hold key blocked by pid(%d).", t->pid); - break; - } - } - - return ret; -} - int delete_condition(enum state_t state) { GList *elem, *next; @@ -630,18 +600,3 @@ int display_app_terminated(void *data) return 0; } - -int display_lock_set_custom_holdkey_block(bool blocked) -{ - custom_holdkey_block = blocked; - return 0; -} - -int display_lock_get_custom_holdkey_block(bool *blocked) -{ - if (!blocked) - return -EINVAL; - - *blocked = custom_holdkey_block; - return 0; -} \ No newline at end of file diff --git a/src/display/display-lock.h b/src/display/display-lock.h index abf2b9f..9cc2531 100644 --- a/src/display/display-lock.h +++ b/src/display/display-lock.h @@ -35,7 +35,6 @@ typedef struct _pm_lock_node { guint warning_id; GVariant *warning_param; time_t time; - bool holdkey_block; bool app_background; bool broadcast_warning; } PmLockNode; @@ -44,10 +43,9 @@ bool check_lock_state(int state); bool pmlock_get_lock_state(enum state_t state); enum state_t power_lock_type_to_pmlock(power_lock_e power_lock_type); PmLockNode *find_node(enum state_t s_index, pid_t pid); -PmLockNode *display_lock_add_pmlock_node(enum state_t s_index, pid_t pid, bool holdkey_block, unsigned int timeout); +PmLockNode *display_lock_add_pmlock_node(enum state_t s_index, pid_t pid, unsigned int timeout); int del_node(enum state_t s_index, PmLockNode *n); int check_lock_condition(enum state_t state); -int check_holdkey_block(enum state_t state); int delete_condition(enum state_t state); void print_node(int next); void makeup_trans_condition(void); @@ -58,7 +56,4 @@ int display_app_background(void *data); int display_app_foreground(void *data); int display_app_terminated(void *data); -int display_lock_set_custom_holdkey_block(bool blocked); -int display_lock_get_custom_holdkey_block(bool *blocked); - #endif /* __DISPLAY_LOCK_H__ */ diff --git a/src/display/plugin-common/display-dbus.c b/src/display/plugin-common/display-dbus.c index 24eb2ff..9cf4cd5 100644 --- a/src/display/plugin-common/display-dbus.c +++ b/src/display/plugin-common/display-dbus.c @@ -169,9 +169,6 @@ static GVariant *dbus_lockstate(GDBusConnection *conn, flag = STAY_CUR_STATE; } - if (!strcmp(option2_str, HOLDKEYBLOCK_STR)) - flag |= HOLD_KEY_BLOCK; - if (flag & GOTO_STATE_NOW) { caps = display_get_caps(DISPLAY_ACTOR_API); @@ -720,11 +717,11 @@ static GVariant *dbus_setlcdtimeout(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) { - int on, dim, holdkey_block, ret; + int on, dim, dummy, ret; // dummy: holdkeyblock, unused pid_t pid; int id = 0; - g_variant_get(param, "(iii)", &on, &dim, &holdkey_block); + g_variant_get(param, "(iii)", &on, &dim, &dummy); pid = gdbus_connection_get_sender_pid(conn, sender); if (pid == -1 || kill(pid, 0) == -1) { @@ -733,7 +730,7 @@ static GVariant *dbus_setlcdtimeout(GDBusConnection *conn, goto error; } - ret = set_lcd_timeout(on, dim, holdkey_block, sender); + ret = set_lcd_timeout(on, dim, sender); if (ret) { _W("fail to set lcd timeout %d by %d", ret, pid); } else { @@ -742,8 +739,8 @@ static GVariant *dbus_setlcdtimeout(GDBusConnection *conn, _E("failed to watch name %s, id %d", sender, id); //todo: set return value } - _I("set lcd timeout on %d, dim %d, holdblock %d by %d", - on, dim, holdkey_block, pid); + _I("set lcd timeout on %d, dim %d, by %d", + on, dim, pid); } error: diff --git a/src/display/plugin-common/poll.c b/src/display/plugin-common/poll.c index d9f1d1d..ffc2806 100644 --- a/src/display/plugin-common/poll.c +++ b/src/display/plugin-common/poll.c @@ -84,9 +84,6 @@ static int __pm_lock_internal(pid_t pid, int s_bits, int flag, int timeout) /* if the flag is true, go to the locking state directly */ cond = SET_COND_FLAG(cond, PM_REQUEST_CHANGE); - if (flag & HOLD_KEY_BLOCK) - cond = SET_COND_FLAG(cond, PM_FLAG_BLOCK_HOLDKEY); - recv_data.pid = pid; recv_data.cond = cond; recv_data.timeout = timeout; diff --git a/src/display/poll.h b/src/display/poll.h index bd79b92..086f875 100644 --- a/src/display/poll.h +++ b/src/display/poll.h @@ -78,7 +78,6 @@ enum { #define STAY_CUR_STATE 0x1 #define GOTO_STATE_NOW 0x2 -#define HOLD_KEY_BLOCK 0x4 #define PM_SLEEP_MARGIN 0x0 /**< keep guard time for unlock */ #define PM_RESET_TIMER 0x1 /**< reset timer for unlock */ @@ -99,7 +98,6 @@ enum cond_request_e { }; enum cond_flags_e { - PM_FLAG_BLOCK_HOLDKEY = 1 << 0, PM_FLAG_RESET_TIMER = 1 << 1, PM_FLAG_KEEP_TIMER = 1 << 2, }; @@ -130,7 +128,6 @@ enum cond_flags_e { #define STAYCURSTATE_STR "staycurstate" #define GOTOSTATENOW_STR "gotostatenow" -#define HOLDKEYBLOCK_STR "holdkeyblock" #define STANDBYMODE_STR "standbymode" #define SLEEP_MARGIN_STR "sleepmargin" diff --git a/src/libdeviced/display.c b/src/libdeviced/display.c index b41d816..484e338 100644 --- a/src/libdeviced/display.c +++ b/src/libdeviced/display.c @@ -29,8 +29,6 @@ #define DISPLAY_MAX_BRIGHTNESS 100 #define DISPLAY_MIN_BRIGHTNESS 1 -#define HOLDKEY_BLOCK_BIT 0x1 - #define METHOD_SET_REFRESH_RATE "SetRefreshRate" #define METHOD_LOCK_STATE "lockstate" #define METHOD_UNLOCK_STATE "unlockstate" @@ -52,7 +50,6 @@ #define STR_STAYCURSTATE "staycurstate" #define STR_GOTOSTATENOW "gotostatenow" -#define STR_HOLDKEYBLOCK "holdkeyblock" #define STR_NULL "NULL" #define STR_SLEEP_MARGIN "sleepmargin" @@ -188,11 +185,7 @@ API int display_lock_state(unsigned int s_bits, unsigned int flag, p = STR_STAYCURSTATE; pa[1] = p; - if (flag & HOLD_KEY_BLOCK) - p = STR_HOLDKEYBLOCK; - else - p = STR_NULL; - pa[2] = p; + pa[2] = STR_NULL; ret = gdbus_call_async_with_reply(DEVICED_BUS_NAME, DEVICED_PATH_DISPLAY, -- 2.7.4 From 333653e09525d784bb161a460694412d6e2a1efc Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 13 Jun 2023 16:50:59 +0900 Subject: [PATCH 15/16] display: Make diaplay lock data private Changed list name 'cond_head' to 'g_display_lock_list'. Previously, the list had been exposed to another module using get_cond_head(). Remove the function to protect the data from being accessed oustide of the display-lock.c. Instead, the display-lock.c now provides services that the other module has done using get_cond_head(). Currently, the only below function has been added for display-misc.c. - display_lock_print_lock_info() All existing get_cond_head() has been replaced by proper functions. Change-Id: I4e4603f44c6613d71bb0b1e05abe6d45ae4a39c5 Signed-off-by: Youngjae Cho --- src/display/display-lock.c | 74 ++++++++++++++++++++++++++++++++++------------ src/display/display-lock.h | 3 +- src/display/display-misc.c | 21 +------------ src/time/time-handler.c | 11 ++----- 4 files changed, 60 insertions(+), 49 deletions(-) diff --git a/src/display/display-lock.c b/src/display/display-lock.c index ab719d1..dde7a22 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -32,6 +32,7 @@ #include "display-panel.h" #include "display-plugin.h" #include "display-config.h" +#include "display-misc.h" #include "display-state-transition.h" #include "shared/log-macro.h" #include "shared/apps.h" @@ -42,7 +43,7 @@ #define no_foreground_lock(st) (check_lock_state(st) == false) -static GList *cond_head[S_END]; +static GList *g_display_lock_list[S_END]; static int trans_condition; bool check_lock_state(int state) @@ -50,7 +51,7 @@ bool check_lock_state(int state) GList *elem; PmLockNode *t; - SYS_G_LIST_FOREACH(cond_head[state], elem, t) { + SYS_G_LIST_FOREACH(g_display_lock_list[state], elem, t) { if (t->app_background == false) return true; } @@ -60,7 +61,7 @@ bool check_lock_state(int state) bool pmlock_get_lock_state(enum state_t state) { - return (bool)SYS_G_LIST_LENGTH(cond_head[state]); + return (bool)SYS_G_LIST_LENGTH(g_display_lock_list[state]); } enum state_t power_lock_type_to_pmlock(power_lock_e power_lock_type) @@ -102,7 +103,7 @@ static void broadcast_pmlock_state_changed(enum state_t state) return; } - num_of_pmlock = g_list_length(cond_head[state]); + num_of_pmlock = g_list_length(g_display_lock_list[state]); if (num_of_pmlock > 1) return; @@ -236,7 +237,7 @@ PmLockNode *find_node(enum state_t s_index, pid_t pid) GList *elem; PmLockNode *t = NULL; - SYS_G_LIST_FOREACH(cond_head[s_index], elem, t) { + SYS_G_LIST_FOREACH(g_display_lock_list[s_index], elem, t) { if (t->pid == pid) return t; } @@ -361,7 +362,7 @@ PmLockNode *display_lock_add_pmlock_node(enum state_t s_index, pid_t pid, unsign n->warning_id = g_timeout_add_seconds(g_display_plugin.config->lockcheck_timeout, default_pmlock_check, (gpointer)n); - SYS_G_LIST_APPEND(cond_head[s_index], n); + SYS_G_LIST_APPEND(g_display_lock_list[s_index], n); refresh_app_cond(); @@ -375,7 +376,7 @@ int del_node(enum state_t s_index, PmLockNode *n) if (n == NULL) return 0; - SYS_G_LIST_REMOVE(cond_head[s_index], n); + SYS_G_LIST_REMOVE(g_display_lock_list[s_index], n); /* delete timer */ remove_pmlock_node_timeout_callback_id(n); @@ -406,7 +407,7 @@ int check_lock_condition(enum state_t state) display_plugin_state_get_name(state, &state_name); - SYS_G_LIST_FOREACH(cond_head[state], elem, t) { + SYS_G_LIST_FOREACH(g_display_lock_list[state], elem, t) { if (t->pid != owner && t->app_background == false) { ret = true; _I("state change was blocked by pid(%d)!", t->pid); @@ -426,10 +427,10 @@ int delete_condition(enum state_t state) display_plugin_state_get_name(state, &state_name); _I("delete condition : state of %s", state_name); - if (!cond_head[state]) + if (!g_display_lock_list[state]) return 0; - SYS_G_LIST_FOREACH_SAFE(cond_head[state], elem, next, t) { + SYS_G_LIST_FOREACH_SAFE(g_display_lock_list[state], elem, next, t) { remove_pmlock_node_timeout_callback_id(t); if (state == S_LCDOFF) set_process_active(false, t->pid); @@ -438,8 +439,8 @@ int delete_condition(enum state_t state) del_node(state, t); } - SYS_G_LIST_FREE_LIST(cond_head[state]); - cond_head[state] = NULL; + SYS_G_LIST_FREE_LIST(g_display_lock_list[state]); + g_display_lock_list[state] = NULL; broadcast_pmlock_state_changed(state); @@ -459,7 +460,7 @@ void print_node(int next) return; time(&now); - SYS_G_LIST_FOREACH(cond_head[next], elem, n) { + SYS_G_LIST_FOREACH(g_display_lock_list[next], elem, n) { diff = difftime(now, n->time); ctime_r(&n->time, buf); buf[strlen(buf) - 1] = 0; @@ -497,7 +498,7 @@ int check_processes(enum state_t prohibit_state) PmLockNode *t = NULL; int ret = 0; - SYS_G_LIST_FOREACH_SAFE(cond_head[prohibit_state], elem, next, t) { + SYS_G_LIST_FOREACH_SAFE(g_display_lock_list[prohibit_state], elem, next, t) { if (t->pid == -1 || (t->pid < INTERNAL_LOCK_BASE && kill(t->pid, 0) == -1)) { _E("%d process does not exist, delete the REQ" " - prohibit state %d ", @@ -516,11 +517,6 @@ int get_trans_condition(void) return trans_condition; } -GList *get_cond_head(enum state_t s_index) -{ - return cond_head[s_index]; -} - int display_app_background(void *data) { pid_t pid; @@ -600,3 +596,43 @@ int display_app_terminated(void *data) return 0; } + +static void print_lock_info(gpointer data, gpointer udata) +{ + PmLockNode *t = (PmLockNode *) data; + int **param = (int **) udata; + int *index = param[0]; + int fd = *(param[1]); + + char buf[PATH_MAX + 255] = { 0, }; + char pname[PATH_MAX] = { 0, }; + char time[32] = { 0, }; + const char *stname = NULL; + int ret; + + display_misc_get_process_name((pid_t)t->pid, pname); + ctime_r(&t->time, time); + display_plugin_state_get_name(t->state, &stname); + + snprintf(buf, sizeof(buf), " %d: [%s] locked by pid %d %s %s\n", *index, stname, t->pid, pname, time); + ret = write(fd, buf, strlen(buf)); + if (ret < 0) + _E("Failed to write, %m"); + + *index = *index + 1; +} + +int display_lock_print_lock_info(int fd) +{ + enum state_t s; + int index = 1; + int *param[2] = { &index, &fd }; + + if (fd < 0) + return -EINVAL; + + for (s = S_NORMAL; s < S_END; ++s) + g_list_foreach(g_display_lock_list[s], print_lock_info, param); + + return 0; +} diff --git a/src/display/display-lock.h b/src/display/display-lock.h index 9cc2531..c39147d 100644 --- a/src/display/display-lock.h +++ b/src/display/display-lock.h @@ -51,9 +51,10 @@ void print_node(int next); void makeup_trans_condition(void); int check_processes(enum state_t prohibit_state); int get_trans_condition(void); -GList *get_cond_head(enum state_t s_index); int display_app_background(void *data); int display_app_foreground(void *data); int display_app_terminated(void *data); +int display_lock_print_lock_info(int fd); + #endif /* __DISPLAY_LOCK_H__ */ diff --git a/src/display/display-misc.c b/src/display/display-misc.c index e1d02af..d606396 100644 --- a/src/display/display-misc.c +++ b/src/display/display-misc.c @@ -142,14 +142,8 @@ void display_misc_unregister_battery_health_notifier(void) static void print_info(int fd) { - int s_index = 0; char buf[PATH_MAX + 255]; - int i = 1; int ret; - char pname[PATH_MAX]; - PmLockNode *t; - GList *elem; - char time_buf[30]; int normal_state_timeout; int dim_state_timeout; int off_stata_timeout; @@ -199,20 +193,7 @@ static void print_info(int fd) if (ret < 0) _E("Write() failed: %d", errno); - for (s_index = S_NORMAL; s_index < S_END; s_index++) { - SYS_G_LIST_FOREACH(get_cond_head(s_index), elem, t) { - display_misc_get_process_name((pid_t)t->pid, pname); - ctime_r(&t->time, time_buf); - time_buf[strlen(time_buf) - 1] = 0; - display_plugin_state_get_name(s_index, ¤t_state_name); - snprintf(buf, sizeof(buf), - " %d: [%s] locked by pid %d %s %s\n", - i++, current_state_name, t->pid, pname, time_buf); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("Write() failed: %d", errno); - } - } + display_lock_print_lock_info(fd); print_lock_info_list(fd); diff --git a/src/time/time-handler.c b/src/time/time-handler.c index 46b80ec..8207a65 100644 --- a/src/time/time-handler.c +++ b/src/time/time-handler.c @@ -42,6 +42,7 @@ #include "shared/common.h" #include "shared/device-notifier.h" #include "shared/plugin.h" +#include "display-lock.h" #define PREDEF_SET_DATETIME "set_datetime" #define PREDEF_SET_TIMEZONE "set_timezone" @@ -74,7 +75,6 @@ static int tfd = -1; static gboolean tfd_cb(gint fd, GIOCondition condition, gpointer user_data); static int timerfd_check_stop(int fd); static int timerfd_check_start(void); -static GList* (*get_cond_head) (enum state_t state); char *substring(const char *str, size_t begin, size_t len) { @@ -363,10 +363,7 @@ static int time_lcd_changed_cb(void *data) if (lcd_state < S_LCDOFF) goto restart; - if (get_cond_head) - lcd_state = get_cond_head(S_LCDOFF) != NULL; - else - lcd_state = 0; + lcd_state = check_lock_condition(S_LCDOFF); if (lcd_state || !tfdh || tfd == -1) goto out; @@ -394,10 +391,6 @@ static void time_init(void *data) if (timerfd_check_start() == -1) _E("Failed system time change detector init."); register_notifier(DEVICE_NOTIFIER_LCD, time_lcd_changed_cb); - - get_cond_head = dlsym(display_plugin_handle(), "get_cond_head"); - if (!get_cond_head) - _E("Failed to load symbol get_cond_head(), %s.", dlerror()); } static const struct device_ops time_device_ops = { -- 2.7.4 From e596b38a44897ec13d435de1b5abda068d9d8071 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 16 Jun 2023 10:39:49 +0900 Subject: [PATCH 16/16] display: Refactor display lock Hide display_lock data, which was PmLockNdoe before, into display-lock.c. And display-lock.c has changed to support and can be controlled only by the below functions. --------------------------------------------------------------------- Removed | Newly Added --------------------------------------------------------------------- display_lock_add_pmlock_node | display_lock_request_lock --------------------------------------------------------------------- - | display_lock_update_lock --------------------------------------------------------------------- del_node | display_lock_release_lock --------------------------------------------------------------------- delete_condition | display_lock_release_lock_all --------------------------------------------------------------------- check_processes | - --------------------------------------------------------------------- get_trans_cnodition | - --------------------------------------------------------------------- makeup_trans_condition | - --------------------------------------------------------------------- check_lock_state | display_lock_is_state_locked --------------------------------------------------------------------- Change-Id: I82de53ecfbc4119bc6de5b030342859f8fb6ed9c Signed-off-by: Youngjae Cho --- plugins/iot-headed/display/core.c | 35 +- plugins/iot-headed/display/key-filter.c | 14 +- plugins/mobile/display/core.c | 35 +- plugins/mobile/display/key-filter.c | 14 +- plugins/tv/display/core.c | 35 +- plugins/tv/display/key-filter.c | 14 +- plugins/wearable/display/core.c | 39 +- plugins/wearable/display/key-filter.c | 14 +- src/display/core.h | 3 - src/display/display-config.c | 3 - src/display/display-config.h | 1 - src/display/display-lock.c | 638 ++++++++++++++----------------- src/display/display-lock.h | 30 +- src/display/display-misc.c | 8 +- src/display/display-state-transition.c | 27 +- src/display/plugin-common/display-dbus.c | 2 +- src/time/time-handler.c | 2 +- 17 files changed, 378 insertions(+), 536 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index a547016..4ce86f0 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -143,7 +143,6 @@ static struct display_config display_conf = { .continuous_sampling = CONTINUOUS_SAMPLING, .timeout_enable = true, .input_support = true, - .lockcheck_timeout = 600, .display_init_direction = DISPLAY_INIT_DIRECTION_HORIZONTAL, .aod_enter_level = 40, .aod_tsp = true, @@ -256,10 +255,7 @@ int custom_lcdoff(enum device_flags flag) { struct state *st; - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - - if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { + if (display_lock_is_state_locked(S_NORMAL) || display_lock_is_state_locked(S_LCDDIM)) { /* * When another proccess is normal lock, device is received call then, * call app can be changed to lcd state by proximity. @@ -267,7 +263,7 @@ int custom_lcdoff(enum device_flags flag) */ if (flag & LCD_OFF_BY_PROXIMITY) { _I("custom lcd off by proximity, delete normal lock"); - delete_condition(S_NORMAL); + display_lock_release_lock_all(S_NORMAL); } else { _I("skip custom lcd off"); return -ECANCELED; @@ -339,17 +335,14 @@ int display_off_by_reason(const char *reason) str_len = strlen(reason); if (!strncmp(reason, GESTURE_STR, str_len)) { - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - - if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { + 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)) { - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); + display_lock_release_lock_all(S_NORMAL); + display_lock_release_lock_all(S_LCDDIM); flag = LCD_OFF_BY_PALM; } else { @@ -416,9 +409,9 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) /* at first LCD_OFF and then goto sleep */ /* state transition */ default_proc_change_state_action(S_LCDOFF, TIMEOUT_NONE); - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); - delete_condition(S_LCDOFF); + display_lock_release_lock_all(S_NORMAL); + display_lock_release_lock_all(S_LCDDIM); + display_lock_release_lock_all(S_LCDOFF); if (display_panel_is_lcd_on_state_broadcasted()) { _I("broadcast lcd off signal at non-lcd device"); broadcast_lcd_off(SIGNAL_PRE, 0); @@ -436,7 +429,6 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) static void proc_condition_lock(PMMsg *data) { - PmLockNode *tmp; char pname[PATH_MAX]; pid_t pid = data->pid; enum state_t state; @@ -456,8 +448,11 @@ static void proc_condition_lock(PMMsg *data) (pm_get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); - tmp = display_lock_add_pmlock_node(state, pid, data->timeout); - if (!tmp) { + ret = display_lock_request_lock(state, pid, data->timeout); + if (ret == -EALREADY) + ret = display_lock_update_lock(state, pid, data->timeout); + + if (ret != 0) { _E("Failed to acquire lock, state: %d, pid: %d.", state, pid); return; } @@ -499,7 +494,6 @@ static void proc_condition_unlock(PMMsg *data) { pid_t pid = data->pid; enum state_t state; - PmLockNode *tmp; char pname[PATH_MAX]; bool value = false; unsigned int flags; @@ -513,8 +507,7 @@ static void proc_condition_unlock(PMMsg *data) flags = GET_COND_FLAG(data->cond); display_misc_get_process_name(pid, pname); - tmp = find_node(state, pid); - del_node(state, tmp); + display_lock_release_lock(state, pid); if (state == S_LCDOFF) set_process_active(false, pid); diff --git a/plugins/iot-headed/display/key-filter.c b/plugins/iot-headed/display/key-filter.c index a2f7b34..02504d8 100644 --- a/plugins/iot-headed/display/key-filter.c +++ b/plugins/iot-headed/display/key-filter.c @@ -386,14 +386,11 @@ static int lcdoff_powerkey(void) int ignore = true; if (decide_lcdoff() == true) { - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - if (display_info.update_auto_brightness) display_info.update_auto_brightness(false); switch_off_lcd(); - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); + display_lock_release_lock_all(S_NORMAL); + display_lock_release_lock_all(S_LCDDIM); display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); if (disp_plgn->pm_change_internal) disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); @@ -501,11 +498,8 @@ static int process_screenlock_key(struct input_event *pinput) if (!current_state_in_on()) return false; - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); + display_lock_release_lock_all(S_NORMAL); + display_lock_release_lock_all(S_LCDDIM); display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); /* LCD off forcly */ diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 8ea1bf6..29f8b80 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -145,7 +145,6 @@ static struct display_config display_conf = { .continuous_sampling = CONTINUOUS_SAMPLING, .timeout_enable = true, .input_support = true, - .lockcheck_timeout = 600, .display_init_direction = DISPLAY_INIT_DIRECTION_HORIZONTAL, .aod_enter_level = 40, .aod_tsp = true, @@ -263,10 +262,7 @@ int custom_lcdoff(enum device_flags flag) { struct state *st; - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - - if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { + if (display_lock_is_state_locked(S_NORMAL) || display_lock_is_state_locked(S_LCDDIM)) { /* * When another proccess is normal lock, device is received call then, * call app can be changed to lcd state by proximity. @@ -274,7 +270,7 @@ int custom_lcdoff(enum device_flags flag) */ if (flag & LCD_OFF_BY_PROXIMITY) { _I("custom lcd off by proximity, delete normal lock"); - delete_condition(S_NORMAL); + display_lock_release_lock_all(S_NORMAL); } else { _I("skip custom lcd off"); return -ECANCELED; @@ -346,17 +342,14 @@ int display_off_by_reason(const char *reason) str_len = strlen(reason); if (!strncmp(reason, GESTURE_STR, str_len)) { - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - - if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { + 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)) { - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); + display_lock_release_lock_all(S_NORMAL); + display_lock_release_lock_all(S_LCDDIM); flag = LCD_OFF_BY_PALM; } else { @@ -426,9 +419,9 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) /* at first LCD_OFF and then goto sleep */ /* state transition */ default_proc_change_state_action(S_LCDOFF, TIMEOUT_NONE); - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); - delete_condition(S_LCDOFF); + display_lock_release_lock_all(S_NORMAL); + display_lock_release_lock_all(S_LCDDIM); + display_lock_release_lock_all(S_LCDOFF); if (display_panel_is_lcd_on_state_broadcasted()) { _I("broadcast lcd off signal at non-lcd device"); broadcast_lcd_off(SIGNAL_PRE, 0); @@ -446,7 +439,6 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) static void proc_condition_lock(PMMsg *data) { - PmLockNode *tmp; char pname[PATH_MAX]; pid_t pid = data->pid; enum state_t state; @@ -466,8 +458,11 @@ static void proc_condition_lock(PMMsg *data) (pm_get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); - tmp = display_lock_add_pmlock_node(state, pid, data->timeout); - if (!tmp) { + ret = display_lock_request_lock(state, pid, data->timeout); + if (ret == -EALREADY) + ret = display_lock_update_lock(state, pid, data->timeout); + + if (ret != 0) { _E("Failed to acquire lock, state: %d, pid: %d.", state, pid); return; } @@ -508,7 +503,6 @@ static void proc_condition_unlock(PMMsg *data) { pid_t pid = data->pid; enum state_t state; - PmLockNode *tmp; char pname[PATH_MAX]; bool value = false; unsigned int flags; @@ -522,8 +516,7 @@ static void proc_condition_unlock(PMMsg *data) flags = GET_COND_FLAG(data->cond); display_misc_get_process_name(pid, pname); - tmp = find_node(state, pid); - del_node(state, tmp); + display_lock_release_lock(state, pid); if (state == S_LCDOFF) set_process_active(false, pid); diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index b687754..36bb59f 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -376,14 +376,11 @@ static int lcdoff_powerkey(void) int ignore = true; if (decide_lcdoff() == true) { - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - if (display_info.update_auto_brightness) display_info.update_auto_brightness(false); switch_off_lcd(); - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); + display_lock_release_lock_all(S_NORMAL); + display_lock_release_lock_all(S_LCDDIM); display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); if (disp_plgn->pm_change_internal) disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); @@ -534,11 +531,8 @@ static int process_screenlock_key(struct input_event *pinput) if (!current_state_in_on()) return false; - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); + display_lock_release_lock_all(S_NORMAL); + display_lock_release_lock_all(S_LCDDIM); display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); /* LCD off forcly */ diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index a585c86..e35377c 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -144,7 +144,6 @@ static struct display_config display_conf = { .timeout_enable = true, .input_support = true, .display_init_direction = DISPLAY_INIT_DIRECTION_HORIZONTAL, - .lockcheck_timeout = 600, .aod_enter_level = 40, .aod_tsp = true, .touch_wakeup = false, @@ -256,10 +255,7 @@ int custom_lcdoff(enum device_flags flag) { struct state *st; - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - - if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { + if (display_lock_is_state_locked(S_NORMAL) || display_lock_is_state_locked(S_LCDDIM)) { /* * When another proccess is normal lock, device is received call then, * call app can be changed to lcd state by proximity. @@ -267,7 +263,7 @@ int custom_lcdoff(enum device_flags flag) */ if (flag & LCD_OFF_BY_PROXIMITY) { _I("custom lcd off by proximity, delete normal lock"); - delete_condition(S_NORMAL); + display_lock_release_lock_all(S_NORMAL); } else { _I("skip custom lcd off"); return -ECANCELED; @@ -339,17 +335,14 @@ int display_off_by_reason(const char *reason) str_len = strlen(reason); if (!strncmp(reason, GESTURE_STR, str_len)) { - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - - if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { + 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)) { - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); + display_lock_release_lock_all(S_NORMAL); + display_lock_release_lock_all(S_LCDDIM); flag = LCD_OFF_BY_PALM; } else { @@ -415,9 +408,9 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) /* at first LCD_OFF and then goto sleep */ /* state transition */ default_proc_change_state_action(S_LCDOFF, TIMEOUT_NONE); - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); - delete_condition(S_LCDOFF); + display_lock_release_lock_all(S_NORMAL); + display_lock_release_lock_all(S_LCDDIM); + display_lock_release_lock_all(S_LCDOFF); if (display_panel_is_lcd_on_state_broadcasted()) { _I("broadcast lcd off signal at non-lcd device"); broadcast_lcd_off(SIGNAL_PRE, 0); @@ -435,7 +428,6 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) static void proc_condition_lock(PMMsg *data) { - PmLockNode *tmp; char pname[PATH_MAX]; pid_t pid = data->pid; enum state_t state; @@ -455,8 +447,11 @@ static void proc_condition_lock(PMMsg *data) (pm_get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); - tmp = display_lock_add_pmlock_node(state, pid, data->timeout); - if (!tmp) { + ret = display_lock_request_lock(state, pid, data->timeout); + if (ret == -EALREADY) + ret = display_lock_update_lock(state, pid, data->timeout); + + if (ret != 0) { _E("Failed to acquire lock, state: %d, pid: %d.", state, pid); return; } @@ -498,7 +493,6 @@ static void proc_condition_unlock(PMMsg *data) { pid_t pid = data->pid; enum state_t state; - PmLockNode *tmp; char pname[PATH_MAX]; bool value = false; unsigned int flags; @@ -512,8 +506,7 @@ static void proc_condition_unlock(PMMsg *data) flags = GET_COND_FLAG(data->cond); display_misc_get_process_name(pid, pname); - tmp = find_node(state, pid); - del_node(state, tmp); + display_lock_release_lock(state, pid); if (state == S_LCDOFF) set_process_active(false, pid); diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index ca54808..b46816d 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -386,14 +386,11 @@ static int lcdoff_powerkey(void) int ignore = true; if (decide_lcdoff() == true) { - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - if (display_info.update_auto_brightness) display_info.update_auto_brightness(false); switch_off_lcd(); - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); + display_lock_release_lock_all(S_NORMAL); + display_lock_release_lock_all(S_LCDDIM); display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); if (disp_plgn->pm_change_internal) disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); @@ -501,11 +498,8 @@ static int process_screenlock_key(struct input_event *pinput) if (!current_state_in_on()) return false; - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); + display_lock_release_lock_all(S_NORMAL); + display_lock_release_lock_all(S_LCDDIM); display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); /* LCD off forcly */ diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index fecdae8..08b3d6c 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -167,7 +167,6 @@ static struct display_config display_conf = { .continuous_sampling = CONTINUOUS_SAMPLING, .timeout_enable = true, .input_support = true, - .lockcheck_timeout = 600, .display_init_direction = DISPLAY_INIT_DIRECTION_HORIZONTAL, .aod_enter_level = 40, .aod_tsp = true, @@ -512,10 +511,7 @@ int custom_lcdoff(enum device_flags flag) { struct state *st; - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - - if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { + if (display_lock_is_state_locked(S_NORMAL) || display_lock_is_state_locked(S_LCDDIM)) { /* * When another proccess is normal lock, device is received call then, * call app can be changed to lcd state by proximity. @@ -523,7 +519,7 @@ int custom_lcdoff(enum device_flags flag) */ if (flag & LCD_OFF_BY_PROXIMITY) { _I("custom lcd off by proximity, delete normal lock"); - delete_condition(S_NORMAL); + display_lock_release_lock_all(S_NORMAL); } else { _I("skip custom lcd off"); return -ECANCELED; @@ -599,22 +595,19 @@ int display_off_by_reason(const char *reason) str_len = strlen(reason); if (!strncmp(reason, GESTURE_STR, str_len)) { - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - - if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { + 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)) { - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); + display_lock_release_lock_all(S_NORMAL); + display_lock_release_lock_all(S_LCDDIM); flag = LCD_OFF_BY_PALM; } else if (!strncmp(reason, DISPLAY_DETACH_STR, str_len)) { - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); + display_lock_release_lock_all(S_NORMAL); + display_lock_release_lock_all(S_LCDDIM); flag = LCD_OFF_BY_DISPLAY_DETACH; } else { @@ -684,9 +677,9 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) /* at first LCD_OFF and then goto sleep */ /* state transition */ default_proc_change_state_action(S_LCDOFF, TIMEOUT_NONE); - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); - delete_condition(S_LCDOFF); + display_lock_release_lock_all(S_NORMAL); + display_lock_release_lock_all(S_LCDDIM); + display_lock_release_lock_all(S_LCDOFF); if (lcdon_broadcast) { _I("broadcast lcd off signal at non-lcd device"); broadcast_lcd_off(SIGNAL_PRE, 0); @@ -704,7 +697,6 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) static void proc_condition_lock(PMMsg *data) { - PmLockNode *tmp; char pname[PATH_MAX]; pid_t pid = data->pid; enum state_t state; @@ -724,8 +716,11 @@ static void proc_condition_lock(PMMsg *data) (pm_get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); - tmp = display_lock_add_pmlock_node(state, pid, data->timeout); - if (!tmp) { + ret = display_lock_request_lock(state, pid, data->timeout); + if (ret == -EALREADY) + ret = display_lock_update_lock(state, pid, data->timeout); + + if (ret != 0) { _E("Failed to acquire lock, state: %d, pid: %d.", state, pid); return; } @@ -767,7 +762,6 @@ static void proc_condition_unlock(PMMsg *data) { pid_t pid = data->pid; enum state_t state; - PmLockNode *tmp; char pname[PATH_MAX]; bool value = false; unsigned int flags; @@ -781,8 +775,7 @@ static void proc_condition_unlock(PMMsg *data) flags = GET_COND_FLAG(data->cond); display_misc_get_process_name(pid, pname); - tmp = find_node(state, pid); - del_node(state, tmp); + display_lock_release_lock(state, pid); if (state == S_LCDOFF) set_process_active(false, pid); diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index a40dd48..e7b33e1 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -383,14 +383,11 @@ static int lcdoff_powerkey(void) int ignore = true; if (decide_lcdoff() == true) { - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - if (display_info.update_auto_brightness) display_info.update_auto_brightness(false); switch_off_lcd(); - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); + display_lock_release_lock_all(S_NORMAL); + display_lock_release_lock_all(S_LCDDIM); display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); if (disp_plgn->pm_change_internal) disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); @@ -498,11 +495,8 @@ static int process_screenlock_key(struct input_event *pinput) if (!current_state_in_on()) return false; - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - - delete_condition(S_NORMAL); - delete_condition(S_LCDDIM); + display_lock_release_lock_all(S_NORMAL); + display_lock_release_lock_all(S_LCDDIM); display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); /* LCD off forcly */ diff --git a/src/display/core.h b/src/display/core.h index 96b4b8e..d7b662a 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -105,9 +105,6 @@ typedef struct { } PMMsg; extern int poll_callback(int condition, PMMsg *data); -/* If the bit in a condition variable is set, - * we cannot transit the state until clear this bit. */ -int check_processes(enum state_t prohibit_state); extern struct state state[S_END]; void reset_lcd_timeout(GDBusConnection *conn, const gchar *sender, diff --git a/src/display/display-config.c b/src/display/display-config.c index 1025b6c..b138a8b 100644 --- a/src/display/display-config.c +++ b/src/display/display-config.c @@ -86,9 +86,6 @@ static int display_config_parse(struct parse_result *result, void *user_data) } else if (MATCH(result->name, "InputSupport")) { c->input_support = (MATCH(result->value, "yes") ? true : false); _D("Input is %s", c->input_support ? "supported" : "NOT supported"); - } else if (MATCH(result->name, "LockCheckTimeout")) { - SET_CONF(c->lockcheck_timeout, atoi(result->value)); - _D("LockCheckTimeout is %d", c->lockcheck_timeout); } else if (MATCH(result->name, "AODTSP")) { c->aod_tsp = (MATCH(result->value, "yes") ? true : false); _D("TSP control at is %d at aod", c->aod_tsp); diff --git a/src/display/display-config.h b/src/display/display-config.h index 967e9bd..be967c9 100644 --- a/src/display/display-config.h +++ b/src/display/display-config.h @@ -41,7 +41,6 @@ struct display_config { int alpm_on; int accel_sensor_on; int continuous_sampling; - int lockcheck_timeout; int display_init_direction; int aod_enter_level; bool aod_tsp; diff --git a/src/display/display-lock.c b/src/display/display-lock.c index dde7a22..a9cbe40 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -40,28 +40,159 @@ #define METHOD_APP_STATUS "CheckAppStatus" #define PID_MAX 6 #define LOCK_TIME_WARNING 60 /* 60 seconds */ +#define LOCK_WATCHDOG_PERIOD_SEC 600 -#define no_foreground_lock(st) (check_lock_state(st) == false) +struct display_lock { + enum state_t state; + pid_t pid; + guint timeout_id; + guint warning_id; + time_t time; + bool background; + bool broadcast_warning; + GList *l; +}; + +static GList *g_display_fglock_list[S_END]; /* lock requested by foreground app */ +static GList *g_display_bglock_list[S_END]; /* lock requested by background app */ + +static void broadcast_lock_changed(enum state_t state); + +static gboolean __find_lock(gconstpointer data, gconstpointer udata) +{ + const struct display_lock *dl = (const struct display_lock *) data; + const pid_t pid = *(const pid_t *) udata; + + if (dl->pid == pid) + return 0; + + return -1; +} + +static struct display_lock* find_lock(enum state_t state, pid_t pid) +{ + GList *l; + + l = g_list_find_custom(g_display_fglock_list[state], &pid, __find_lock); + if (l) + return l->data; + + l = g_list_find_custom(g_display_bglock_list[state], &pid, __find_lock); + if (l) + return l->data; + + return NULL; +}; + +/* Add lock to list */ +static void add_lock(struct display_lock *dl) +{ + enum state_t state; + + if (!dl) + return; + + state = dl->state; + + if (!dl->l) { + dl->l = g_list_alloc(); + dl->l->data = dl; + broadcast_lock_changed(state); + } + + if (dl->background) + g_display_bglock_list[state] = g_list_concat(g_display_bglock_list[state], dl->l); + else + g_display_fglock_list[state] = g_list_concat(g_display_fglock_list[state], dl->l); +} + +/** + * Remove lock from list but not free. + */ +static void remove_lock(struct display_lock *dl) +{ + enum state_t state; + + if (!dl) + return; -static GList *g_display_lock_list[S_END]; -static int trans_condition; + state = dl->state; + + g_display_bglock_list[state] = g_list_remove_link(g_display_bglock_list[state], dl->l); + g_display_fglock_list[state] = g_list_remove_link(g_display_fglock_list[state], dl->l); +} -bool check_lock_state(int state) +static void free_lock(struct display_lock *dl) { - GList *elem; - PmLockNode *t; + enum state_t state; + + if (!dl) + return; + + if (dl->timeout_id) { + g_source_remove(dl->timeout_id); + dl->timeout_id = 0; + } - SYS_G_LIST_FOREACH(g_display_lock_list[state], elem, t) { - if (t->app_background == false) - return true; + if (dl->warning_id) { + g_source_remove(dl->warning_id); + dl->warning_id = 0; } - return false; + state = dl->state; + + broadcast_lock_changed(state); + + /** + * the node must have been removed from list, that is, + * the dl->l must be a self-contained list with one element. + */ + assert(dl->l); + assert(dl->l->prev == NULL); + assert(dl->l->next == NULL); + + g_list_free(dl->l); + dl->l = NULL; + + free(dl); + dl = NULL; + + /* Trigger state transition */ + if (state == get_pm_cur_state() && // if the unlocked state is equal to the current display state + !display_lock_is_state_locked(state) && // if the released lock is the last lock + display_state_transition_is_there_state_transition_timer() == false) // if there is no running transition timer + display_state_transition_reset_state_transition_timeout(0); +} + +static void set_lock_foreground(struct display_lock *dl) +{ + if (!dl) + return; + + if (!dl->background) + return; + + remove_lock(dl); + dl->background = false; + add_lock(dl); +} + +static void set_lock_background(struct display_lock *dl) +{ + if (!dl) + return; + + if (dl->background) + return; + + remove_lock(dl); + dl->background = true; + add_lock(dl); } -bool pmlock_get_lock_state(enum state_t state) +int display_lock_is_state_locked(enum state_t state) { - return (bool)SYS_G_LIST_LENGTH(g_display_lock_list[state]); + return (g_display_fglock_list[state] != NULL); } enum state_t power_lock_type_to_pmlock(power_lock_e power_lock_type) @@ -78,21 +209,9 @@ enum state_t power_lock_type_to_pmlock(power_lock_e power_lock_type) } } -static void refresh_app_cond(void) +static void broadcast_lock_changed(enum state_t state) { - trans_condition = 0; - - if (check_lock_state(S_NORMAL)) - trans_condition |= MASK_NORMAL; - if (check_lock_state(S_LCDDIM)) - trans_condition |= MASK_DIM; - if (check_lock_state(S_LCDOFF)) - trans_condition |= MASK_OFF; -} - -static void broadcast_pmlock_state_changed(enum state_t state) -{ - int num_of_pmlock; + int nlock = 0; switch(state) { case S_LCDON: @@ -103,18 +222,19 @@ static void broadcast_pmlock_state_changed(enum state_t state) return; } - num_of_pmlock = g_list_length(g_display_lock_list[state]); - if (num_of_pmlock > 1) + nlock += g_list_length(g_display_fglock_list[state]); + nlock += g_list_length(g_display_bglock_list[state]); + if (nlock > 1) return; gdbus_signal_emit(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, DEVICED_SIGNAL_POWER_LOCK_STATE_CHANGED, - g_variant_new("(ii)", state, num_of_pmlock)); + g_variant_new("(ii)", state, nlock)); } -static void broadcast_pmlock_expired(pid_t pid, enum state_t state, const char* appid, time_t locktime) +static void broadcast_lock_watchdog_expired(pid_t pid, enum state_t state, const char* appid, time_t locktime) { time_t now; double diff; @@ -137,13 +257,13 @@ static void broadcast_pmlock_expired(pid_t pid, enum state_t state, const char* _E("Failed to send dbus pmlock_expired"); } -static void default_pmlock_check_cb(GVariant *var, void *user_data, GError *err) +static void app_status_callback(GVariant *var, void *user_data, GError *err) { pid_t pid = 0; int detected = 0; char *app_id = NULL; enum state_t state = (enum state_t) user_data; - PmLockNode *node; + struct display_lock *dl; if (!var) return; @@ -156,11 +276,11 @@ static void default_pmlock_check_cb(GVariant *var, void *user_data, GError *err) if (!detected) goto out; - node = find_node(state, pid); - if (!node) + dl = find_lock(state, pid); + if (!dl) goto out; - broadcast_pmlock_expired(pid, state, app_id, node->time); + broadcast_lock_watchdog_expired(pid, state, app_id, dl->time); out: if (app_id) @@ -168,43 +288,35 @@ out: g_variant_unref(var); } -static gboolean default_pmlock_check(void *data) +static gboolean lock_watchdog_callback(void *data) { char *str; - PmLockNode *node; - enum state_t state; - pid_t pid; + struct display_lock *dl; int ret; - if (!data) { - _E("Invalid parameter."); - return G_SOURCE_REMOVE; - } - - node = (PmLockNode *) data; - state = node->state; - pid = node->pid; + dl = (struct display_lock *) data; - if (state == S_LCDOFF && display_panel_get_dpms_cached_state() == DPMS_ON) { + if (dl->state == S_LCDOFF && display_panel_get_dpms_cached_state() == DPMS_ON) { _D("Lcd state is PM_LCD_POWER_ON"); return G_SOURCE_CONTINUE; } /* Stop checking lock if process had been terminated */ - if (kill(pid, 0) == -1) { - node = find_node(state, pid); - del_node(state, node); - _I("Process %d not found. Stop checking lock.", pid); + if (kill(dl->pid, 0) == -1) { + _I("Process %d not found. Stop checking lock.", dl->pid); + remove_lock(dl); + free_lock(dl); return G_SOURCE_REMOVE; } - if (!is_app(pid)) { + if (!is_app(dl->pid)) { /* For daemon, no need to ask resourced if it is abnormal lock */ - broadcast_pmlock_expired(pid, state, NULL, node->time); + // TODO: is it correct? + broadcast_lock_watchdog_expired(dl->pid, dl->state, NULL, dl->time); return G_SOURCE_CONTINUE; } - switch (state) { + switch (dl->state) { case S_NORMAL: str = "normal"; break; @@ -223,8 +335,8 @@ static gboolean default_pmlock_check(void *data) RESOURCED_PATH_PROCESS, RESOURCED_INTERFACE_PROCESS, METHOD_APP_STATUS, - g_variant_new("(is)", pid, str), - default_pmlock_check_cb, -1, (void *)(intptr_t)state); + g_variant_new("(is)", dl->pid, str), + app_status_callback, -1, (void *)(intptr_t)dl->state); if (ret < 0) _E("Failed to call dbus method"); @@ -232,374 +344,198 @@ static gboolean default_pmlock_check(void *data) } -PmLockNode *find_node(enum state_t s_index, pid_t pid) -{ - GList *elem; - PmLockNode *t = NULL; - - SYS_G_LIST_FOREACH(g_display_lock_list[s_index], elem, t) { - if (t->pid == pid) - return t; - } - - return NULL; -} - -/* FIXME: ambient call should handled later, to be removed or changed plugin interface way */ -static gboolean delete_state_cond_callback(void *data) +static gboolean lock_expired_callback(gpointer data) { - if (!data) - return G_SOURCE_REMOVE; - - PmLockNode *tmp = (PmLockNode *)data; - const char *state_name = NULL; - pid_t pid; - enum state_t state = tmp->state; + struct display_lock *dl = NULL; + const char *stname = NULL; + dl = (struct display_lock *) data; - /* A passed data is a pid_t type data, not a 64bit data. */ - pid = (pid_t)((intptr_t)tmp->pid); - display_plugin_state_get_name(state, &state_name); - _I("delete prohibit %s condition by timeout (%d)", state_name, pid); + display_plugin_state_get_name(dl->state, &stname); + _I("Display lock expired, state=%s pid=%d", stname, dl->pid); - if (pid == INTERNAL_LOCK_AMBIENT) - ambient_check_invalid_state(pid); + if (dl->pid == INTERNAL_LOCK_AMBIENT) + ambient_check_invalid_state(dl->pid); - tmp = find_node(state, pid); - del_node(state, tmp); - set_unlock_time(pid, state); + if (dl->state == S_LCDOFF) + set_process_active(false, dl->pid); - /* Change state only when the two conditions below are satisfied. - * 1. There should be no running state-transition timer - * 2. Released lock is one of the pm_cur_state's lock - * This emulates already expired transition timer */ - if (!display_state_transition_is_there_state_transition_timer() && (get_pm_cur_state() == state)) - display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT); + set_unlock_time(dl->pid, dl->state); - if (state == S_LCDOFF) - set_process_active(false, pid); + remove_lock(dl); + free_lock(dl); return G_SOURCE_REMOVE; } -static void remove_pmlock_node_timeout_callback_id(PmLockNode *target_node) -{ - if (!target_node) - return; - - if (target_node->timeout_id) - g_source_remove(target_node->timeout_id); - target_node->timeout_id = 0; -} - -static int add_delete_state_cond_callback(unsigned int timeout, PmLockNode *target_node) +/** + * Try to add lock of pid 'pid' on display state 'state' that lasting 'timeout' miliseconds + * Return 0 on success. + * negative on error. + */ +int display_lock_request_lock(enum state_t state, pid_t pid, unsigned int timeout) { - if (!target_node) - return -EINVAL; + struct display_lock *dl; - if (target_node->state < S_NORMAL || target_node->state > S_LCDOFF) + if (state < S_NORMAL || state > S_LCDOFF || timeout < 0) return -EINVAL; - if (timeout <= 0) { - remove_pmlock_node_timeout_callback_id(target_node); - return 0; - } - - assert(target_node->timeout_id == 0); - target_node->timeout_id = g_timeout_add(timeout, delete_state_cond_callback, (void*)target_node); - if (!(target_node->timeout_id)) - _W("Failed to register display timer"); + dl = find_lock(state, pid); + if (dl) + return -EALREADY; - return 0; -} - -static void handle_existing_pmlock_node(unsigned int timeout, PmLockNode *found_node) -{ - time_t now; + dl = calloc(1, sizeof(struct display_lock)); + if (!dl) + return -ENOMEM; - remove_pmlock_node_timeout_callback_id(found_node); + dl->state = state; + dl->pid = pid; if (timeout > 0) - add_delete_state_cond_callback(timeout, found_node); - - time(&now); - found_node->time = now; -} - -PmLockNode *display_lock_add_pmlock_node(enum state_t s_index, pid_t pid, unsigned int timeout) -{ - PmLockNode *n; - PmLockNode *found_node; - time_t now; - - assert(g_display_plugin.config); - - found_node = find_node(s_index, pid); - if (found_node) { - handle_existing_pmlock_node(timeout, found_node); - return found_node; - } - - n = (PmLockNode *) calloc(1, sizeof(PmLockNode)); - if (n == NULL) { - _E("Not enough memory, failed to alloc lock node."); - return NULL; - } - - time(&now); - n->state = s_index; - n->pid = pid; - add_delete_state_cond_callback(timeout, n); - n->time = now; - /* LCDOFF lock should be maintained regardless of fg/bg state */ - if (n->state == S_NORMAL || n->state == S_LCDDIM) { - n->app_background = is_app_background(n->pid); - if (n->app_background) - _W("App(%d) requested %d lock in background.", n->pid, n->state); - } - n->broadcast_warning = true; - + dl->timeout_id = g_timeout_add(timeout, lock_expired_callback, dl); + dl->time = time(NULL); + dl->broadcast_warning = true; + if (state == S_NORMAL || state == S_LCDDIM) + dl->background = is_app_background(pid); if (pid < INTERNAL_LOCK_BASE) - n->warning_id = g_timeout_add_seconds(g_display_plugin.config->lockcheck_timeout, - default_pmlock_check, (gpointer)n); - - SYS_G_LIST_APPEND(g_display_lock_list[s_index], n); - - refresh_app_cond(); + dl->warning_id = g_timeout_add_seconds(LOCK_WATCHDOG_PERIOD_SEC, lock_watchdog_callback, dl); - broadcast_pmlock_state_changed(s_index); + add_lock(dl); - return n; + return 0; } -int del_node(enum state_t s_index, PmLockNode *n) +int display_lock_update_lock(enum state_t state, pid_t pid, unsigned int timeout) { - if (n == NULL) - return 0; + struct display_lock *dl; - SYS_G_LIST_REMOVE(g_display_lock_list[s_index], n); + if (state < S_NORMAL || state > S_LCDOFF || timeout < 0) + return -EINVAL; - /* delete timer */ - remove_pmlock_node_timeout_callback_id(n); + dl = find_lock(state, pid); + if (!dl) + return -EINVAL; - if (n->warning_id) { - g_source_remove(n->warning_id); - n->warning_id = 0; - } - if (n->warning_param) { - g_variant_unref(n->warning_param); - n->warning_param = NULL; + if (dl->timeout_id > 0) { + g_source_remove(dl->timeout_id); + dl->timeout_id = 0; } - broadcast_pmlock_state_changed(s_index); + if (timeout > 0) + dl->timeout_id = g_timeout_add(timeout, lock_expired_callback, dl); - free(n); - refresh_app_cond(); return 0; } -int check_lock_condition(enum state_t state) +void display_lock_release_lock(enum state_t state, pid_t pid) { - GList *elem; - PmLockNode *t = NULL; - int ret = false; - pid_t owner = getpid(); - const char *state_name = NULL; + struct display_lock *dl = find_lock(state, pid); - display_plugin_state_get_name(state, &state_name); - - SYS_G_LIST_FOREACH(g_display_lock_list[state], elem, t) { - if (t->pid != owner && t->app_background == false) { - ret = true; - _I("state change was blocked by pid(%d)!", t->pid); - break; - } - } + if (!dl) + return; - return ret; + remove_lock(dl); + free_lock(dl); } -int delete_condition(enum state_t state) +static void free_lock_all(gpointer data, gpointer udata) { - GList *elem, *next; - PmLockNode *t = NULL; - const char *state_name = NULL; - - display_plugin_state_get_name(state, &state_name); - _I("delete condition : state of %s", state_name); + struct display_lock *dl = (struct display_lock *) data; - if (!g_display_lock_list[state]) - return 0; + if (dl->state == S_LCDOFF) + set_process_active(false, dl->pid); - SYS_G_LIST_FOREACH_SAFE(g_display_lock_list[state], elem, next, t) { - remove_pmlock_node_timeout_callback_id(t); - if (state == S_LCDOFF) - set_process_active(false, t->pid); - _I("delete node of pid(%d)", t->pid); - set_unlock_time(t->pid, state); - del_node(state, t); - } - - SYS_G_LIST_FREE_LIST(g_display_lock_list[state]); - g_display_lock_list[state] = NULL; + remove_lock(dl); + free_lock(dl); +} - broadcast_pmlock_state_changed(state); +void display_lock_release_lock_all(enum state_t state) +{ + g_list_foreach(g_display_fglock_list[state], free_lock_all, NULL); + g_display_fglock_list[state] = NULL; - return 0; + g_list_foreach(g_display_bglock_list[state], free_lock_all, NULL); + g_display_bglock_list[state] = NULL; } -void print_node(int next) +static void print_display_lock(gpointer data, gpointer udata) { int ret; - GList *elem; - PmLockNode *n; + struct display_lock *dl = (struct display_lock *) data; char buf[30]; - time_t now; double diff; - - if (next <= S_START || next >= S_END) - return; - - time(&now); - SYS_G_LIST_FOREACH(g_display_lock_list[next], elem, n) { - diff = difftime(now, n->time); - ctime_r(&n->time, buf); - buf[strlen(buf) - 1] = 0; - - if (diff > LOCK_TIME_WARNING) { - if (diff > LOCK_TIME_WARNING * 60 && n->pid < INTERNAL_LOCK_BASE && n->broadcast_warning) { - ret = gdbus_signal_emit(NULL, - DEVICED_PATH_DISPLAY, - DEVICED_INTERFACE_DISPLAY, - "pmlock_over", - g_variant_new("(i)", n->pid)); - if (ret < 0) - _E("Failed to send dbus signal pmlock_over."); - n->broadcast_warning = false; - } - _W("Over(%.0f s) pid( %5d) lock time(%s)", diff, n->pid, buf); - } else - _I("Pid(%5d) lock time(%s)", n->pid, buf); - } -} - -void makeup_trans_condition(void) -{ - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - check_processes(S_LCDOFF); - refresh_app_cond(); -} - -/* If a lock node in the given state had been dead, delete it form lock list, - * and returns 1, else returns 0 */ -int check_processes(enum state_t prohibit_state) -{ - GList *elem, *next; - PmLockNode *t = NULL; - int ret = 0; - - SYS_G_LIST_FOREACH_SAFE(g_display_lock_list[prohibit_state], elem, next, t) { - if (t->pid == -1 || (t->pid < INTERNAL_LOCK_BASE && kill(t->pid, 0) == -1)) { - _E("%d process does not exist, delete the REQ" - " - prohibit state %d ", - t->pid, prohibit_state); - ret = 1; - set_unlock_time(t->pid, prohibit_state); - del_node(prohibit_state, t); + diff = difftime(time(NULL), dl->time); + ctime_r(&dl->time, buf); + buf[strlen(buf) - 1] = 0; + + if (diff > LOCK_TIME_WARNING) { + if (diff > LOCK_TIME_WARNING * 60 && dl->pid < INTERNAL_LOCK_BASE && dl->broadcast_warning) { + ret = gdbus_signal_emit(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "pmlock_over", + g_variant_new("(i)", dl->pid)); + if (ret < 0) + _E("Failed to send dbus signal pmlock_over."); + dl->broadcast_warning = false; } - } + _W("Over(%.0f s) pid( %5d) state(%d), lock time(%s)", diff, dl->pid, dl->state, buf); + } else + _I("Pid(%5d) state(%d) lock time(%s)", dl->pid, dl->state, buf); - return ret; } -int get_trans_condition(void) +void display_lock_print_lock(enum state_t state) { - return trans_condition; + g_list_foreach(g_display_fglock_list[state], print_display_lock, NULL); + g_list_foreach(g_display_bglock_list[state], print_display_lock, NULL); } int display_app_background(void *data) { - pid_t pid; - PmLockNode *node; + struct display_lock *dl; + pid_t pid = *(pid_t *) data; - pid = *(pid_t *)data; + dl = find_lock(S_NORMAL, pid); + if (dl) + set_lock_background(dl); - node = find_node(S_NORMAL, pid); - if (node) { - node->app_background = true; - _I("App(%d) goes background. LCD_NORMAL will be unlocked.", pid); - } - - node = find_node(S_LCDDIM, pid); - if (node) { - node->app_background = true; - _I("App(%d) goes background. LCD_DIM will be unlocked.", pid); - } + dl = find_lock(S_LCDDIM, pid); + if (dl) + set_lock_background(dl); return 0; } int display_app_foreground(void *data) { - pid_t pid; - PmLockNode *node; + struct display_lock *dl; + pid_t pid = *(pid_t *) data; - pid = *(pid_t *)data; + dl = find_lock(S_NORMAL, pid); + if (dl) + set_lock_foreground(dl); - node = find_node(S_NORMAL, pid); - if (node) { - node->app_background = false; - _I("App(%d) goes foreground. LCD_NORMAL will be locked.", pid); - } - - node = find_node(S_LCDDIM, pid); - if (node) { - node->app_background = false; - _I("App(%d) goes foreground. LCD_DIM will be locked.", pid); - } + dl = find_lock(S_LCDDIM, pid); + if (dl) + set_lock_foreground(dl); return 0; } int display_app_terminated(void *data) { - pid_t pid; - PmLockNode *node; - enum state_t state; - enum state_t cur = get_pm_cur_state(); - bool current_unlocked = false; - - pid = *(pid_t *)data; - - /* release lock if it is holding locks */ - for (state = S_START; state < S_END; ++state) { - node = find_node(state, pid); - if (node) { - _W("App=%d is terminated without releasing lockstate=%d. deviced unlocks it.", pid, state); - del_node(state, node); - set_unlock_time(pid, state); - if (state == cur) - current_unlocked = true; - } - } + pid_t pid = *(pid_t *) data; - /* Change state only when all three conditions below are satisfied. - * 1. the lock released due to the termination of the application - * must be a lock for the current state - * 2. after releasing the lock, there is no foreground lock - * for the current state - * 3. there should be no running state-transition timer - * - * This emulates already expired transition timer */ - if (current_unlocked && no_foreground_lock(cur) && !display_state_transition_is_there_state_transition_timer()) - display_state_transition_reset_state_transition_timeout(0); + display_lock_release_lock(S_NORMAL, pid); + display_lock_release_lock(S_LCDDIM, pid); + display_lock_release_lock(S_LCDOFF, pid); return 0; } static void print_lock_info(gpointer data, gpointer udata) { - PmLockNode *t = (PmLockNode *) data; + struct display_lock *dl = (struct display_lock *) data; int **param = (int **) udata; int *index = param[0]; int fd = *(param[1]); @@ -610,11 +546,11 @@ static void print_lock_info(gpointer data, gpointer udata) const char *stname = NULL; int ret; - display_misc_get_process_name((pid_t)t->pid, pname); - ctime_r(&t->time, time); - display_plugin_state_get_name(t->state, &stname); + display_misc_get_process_name((pid_t)dl->pid, pname); + ctime_r(&dl->time, time); + display_plugin_state_get_name(dl->state, &stname); - snprintf(buf, sizeof(buf), " %d: [%s] locked by pid %d %s %s\n", *index, stname, t->pid, pname, time); + snprintf(buf, sizeof(buf), " %d: [%s] locked by pid %d %s %s\n", *index, stname, dl->pid, pname, time); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("Failed to write, %m"); @@ -631,8 +567,10 @@ int display_lock_print_lock_info(int fd) if (fd < 0) return -EINVAL; - for (s = S_NORMAL; s < S_END; ++s) - g_list_foreach(g_display_lock_list[s], print_lock_info, param); + for (s = S_NORMAL; s < S_END; ++s) { + g_list_foreach(g_display_fglock_list[s], print_lock_info, param); + g_list_foreach(g_display_bglock_list[s], print_lock_info, param); + } return 0; } diff --git a/src/display/display-lock.h b/src/display/display-lock.h index c39147d..c3379b1 100644 --- a/src/display/display-lock.h +++ b/src/display/display-lock.h @@ -25,36 +25,20 @@ #define __DISPLAY_LOCK_H__ #include - #include "core.h" -typedef struct _pm_lock_node { - enum state_t state; - pid_t pid; - guint timeout_id; - guint warning_id; - GVariant *warning_param; - time_t time; - bool app_background; - bool broadcast_warning; -} PmLockNode; - -bool check_lock_state(int state); -bool pmlock_get_lock_state(enum state_t state); enum state_t power_lock_type_to_pmlock(power_lock_e power_lock_type); -PmLockNode *find_node(enum state_t s_index, pid_t pid); -PmLockNode *display_lock_add_pmlock_node(enum state_t s_index, pid_t pid, unsigned int timeout); -int del_node(enum state_t s_index, PmLockNode *n); -int check_lock_condition(enum state_t state); -int delete_condition(enum state_t state); -void print_node(int next); -void makeup_trans_condition(void); -int check_processes(enum state_t prohibit_state); -int get_trans_condition(void); +void display_lock_print_lock(enum state_t state); + int display_app_background(void *data); int display_app_foreground(void *data); int display_app_terminated(void *data); +int display_lock_request_lock(enum state_t state, pid_t pid, unsigned int timeout); +int display_lock_update_lock(enum state_t state, pid_t pid, unsigned int timeout); +void display_lock_release_lock(enum state_t state, pid_t pid); +void display_lock_release_lock_all(enum state_t state); +int display_lock_is_state_locked(enum state_t state); int display_lock_print_lock_info(int fd); #endif /* __DISPLAY_LOCK_H__ */ diff --git a/src/display/display-misc.c b/src/display/display-misc.c index d606396..750ddea 100644 --- a/src/display/display-misc.c +++ b/src/display/display-misc.c @@ -175,9 +175,9 @@ static void print_info(int fd) display_plugin_state_get_name(S_LCDDIM, &dim_state_name); display_plugin_state_get_name(S_LCDOFF, &off_state_name); snprintf(buf, sizeof(buf), "Tran. Locked : %s %s %s\n", - (get_trans_condition() & MASK_NORMAL) ? normal_state_name : "-", - (get_trans_condition() & MASK_DIM) ? dim_state_name : "-", - (get_trans_condition() & MASK_OFF) ? off_state_name : "-"); + (display_lock_is_state_locked(S_NORMAL)) ? normal_state_name : "-", + (display_lock_is_state_locked(S_LCDDIM)) ? dim_state_name : "-", + (display_lock_is_state_locked(S_LCDOFF)) ? off_state_name : "-"); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("Write() failed: %d", errno); @@ -249,4 +249,4 @@ void display_misc_save_display_log(const char *path) print_info(fd); close(fd); } -} \ No newline at end of file +} diff --git a/src/display/display-state-transition.c b/src/display/display-state-transition.c index 1518b46..72ada04 100644 --- a/src/display/display-state-transition.c +++ b/src/display/display-state-transition.c @@ -250,35 +250,14 @@ bool display_state_transition_is_display_state_support_transition(enum state_t s int display_state_transition_check_state_transition_condition(enum state_t cur_state, enum state_t next_state) { - int trans_cond; - if (!display_state_transition_is_display_state_support_transition(cur_state)) return -EPERM; - makeup_trans_condition(); - - trans_cond = get_trans_condition() & MASK_BIT; - if (next_state == S_NORMAL) /* S_NORMAL is exceptional */ return 0; - switch (cur_state) { - case S_NORMAL: - trans_cond = trans_cond & MASK_NORMAL; - break; - case S_LCDDIM: - trans_cond = trans_cond & MASK_DIM; - break; - case S_LCDOFF: - trans_cond = trans_cond & MASK_OFF; - break; - default: - trans_cond = 0; - break; - } - - if (trans_cond != 0) { - print_node(cur_state); + if (display_lock_is_state_locked(cur_state)) { + display_lock_print_lock(cur_state); return -EPERM; } @@ -540,4 +519,4 @@ go_lcd_off: display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE); } return 0; -} \ No newline at end of file +} diff --git a/src/display/plugin-common/display-dbus.c b/src/display/plugin-common/display-dbus.c index 9cf4cd5..d826aaa 100644 --- a/src/display/plugin-common/display-dbus.c +++ b/src/display/plugin-common/display-dbus.c @@ -1287,7 +1287,7 @@ static GVariant *dbus_pmlockgetlockstate(GDBusConnection *conn, pmlock_type = power_lock_type_to_pmlock(power_lock_type); - pmlock_state = pmlock_get_lock_state(pmlock_type); + pmlock_state = display_lock_is_state_locked(pmlock_type); pid = gdbus_connection_get_sender_pid(conn, sender); _D("Pmlock get lock state pid=%d power lock state=%d", pid, pmlock_state); diff --git a/src/time/time-handler.c b/src/time/time-handler.c index 8207a65..1d4c377 100644 --- a/src/time/time-handler.c +++ b/src/time/time-handler.c @@ -363,7 +363,7 @@ static int time_lcd_changed_cb(void *data) if (lcd_state < S_LCDOFF) goto restart; - lcd_state = check_lock_condition(S_LCDOFF); + lcd_state = display_lock_is_state_locked(S_LCDOFF); if (lcd_state || !tfdh || tfd == -1) goto out; -- 2.7.4