From e596b38a44897ec13d435de1b5abda068d9d8071 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 16 Jun 2023 10:39:49 +0900 Subject: [PATCH] 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