From: Youngjae Cho Date: Tue, 13 Jun 2023 07:50:59 +0000 (+0900) Subject: display: Make diaplay lock data private X-Git-Tag: accepted/tizen/unified/dev/20230726.115933~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=333653e09525d784bb161a460694412d6e2a1efc;p=platform%2Fcore%2Fsystem%2Fdeviced.git 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 --- 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 = {