From c92aa22d1c1e60905e8dbe6e8568b6c40fc42b57 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Tue, 8 Oct 2019 19:05:49 +0900 Subject: [PATCH 01/16] Remove unused code regarding /usr/bin/save_blenv Change-Id: If4418c367927abe2edef46afedb4831797eef154 Signed-off-by: Hyotaek Shim --- plugins/iot/display/core.c | 5 ----- plugins/mobile/display/core.c | 5 ----- plugins/tv/display/core.c | 5 ----- plugins/wearable/display/core.c | 5 ----- 4 files changed, 20 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 50e45f6..ad7e29c 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -66,7 +66,6 @@ * @{ */ -#define SET_BRIGHTNESS_IN_BOOTLOADER "/usr/bin/save_blenv SLP_LCD_BRIGHT" #define LOCK_SCREEN_INPUT_TIMEOUT 10000 #define LOCK_SCREEN_CONTROL_TIMEOUT 5000 #define ALWAYS_ON_TIMEOUT 360000000 @@ -2189,7 +2188,6 @@ static int poll_callback(int condition, PMMsg *data) static int update_setting(int key_idx, int val) { - char buf[PATH_MAX]; int ret; switch (key_idx) { @@ -2252,9 +2250,6 @@ static int update_setting(int key_idx, int val) "escape dim state."); } backlight_ops.set_default_brt(val); - snprintf(buf, sizeof(buf), "%d", val); - _D("Brightness set in bl(%d).", val); - launch_evenif_exist(SET_BRIGHTNESS_IN_BOOTLOADER, buf); break; case SETTING_LOCK_SCREEN: set_lock_screen_state(val); diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 7726cb5..6eaa984 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -68,7 +68,6 @@ * @{ */ -#define SET_BRIGHTNESS_IN_BOOTLOADER "/usr/bin/save_blenv SLP_LCD_BRIGHT" #define LOCK_SCREEN_INPUT_TIMEOUT 10000 #define LOCK_SCREEN_CONTROL_TIMEOUT 5000 #define ALWAYS_ON_TIMEOUT 360000000 @@ -2201,7 +2200,6 @@ static int poll_callback(int condition, PMMsg *data) static int update_setting(int key_idx, int val) { - char buf[PATH_MAX]; int ret; switch (key_idx) { @@ -2264,9 +2262,6 @@ static int update_setting(int key_idx, int val) "escape dim state."); } backlight_ops.set_default_brt(val); - snprintf(buf, sizeof(buf), "%d", val); - _D("Brightness set in bl(%d).", val); - launch_evenif_exist(SET_BRIGHTNESS_IN_BOOTLOADER, buf); break; case SETTING_LOCK_SCREEN: set_lock_screen_state(val); diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 35fb9e2..2d94505 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -66,7 +66,6 @@ * @{ */ -#define SET_BRIGHTNESS_IN_BOOTLOADER "/usr/bin/save_blenv SLP_LCD_BRIGHT" #define LOCK_SCREEN_INPUT_TIMEOUT 10000 #define LOCK_SCREEN_CONTROL_TIMEOUT 5000 #define ALWAYS_ON_TIMEOUT 360000000 @@ -2189,7 +2188,6 @@ static int poll_callback(int condition, PMMsg *data) static int update_setting(int key_idx, int val) { - char buf[PATH_MAX]; int ret; switch (key_idx) { @@ -2252,9 +2250,6 @@ static int update_setting(int key_idx, int val) "escape dim state."); } backlight_ops.set_default_brt(val); - snprintf(buf, sizeof(buf), "%d", val); - _D("Brightness set in bl(%d).", val); - launch_evenif_exist(SET_BRIGHTNESS_IN_BOOTLOADER, buf); break; case SETTING_LOCK_SCREEN: set_lock_screen_state(val); diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 0b984da..1e5998c 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -67,7 +67,6 @@ * @{ */ -#define SET_BRIGHTNESS_IN_BOOTLOADER "/usr/bin/save_blenv SLP_LCD_BRIGHT" #define LOCK_SCREEN_INPUT_TIMEOUT 10000 #define LOCK_SCREEN_CONTROL_TIMEOUT 5000 #define ALWAYS_ON_TIMEOUT 360000000 @@ -2211,7 +2210,6 @@ static int poll_callback(int condition, PMMsg *data) static int update_setting(int key_idx, int val) { - char buf[PATH_MAX]; int ret; switch (key_idx) { @@ -2274,9 +2272,6 @@ static int update_setting(int key_idx, int val) "escape dim state."); } backlight_ops.set_default_brt(val); - snprintf(buf, sizeof(buf), "%d", val); - _D("Brightness set in bl(%d).", val); - launch_evenif_exist(SET_BRIGHTNESS_IN_BOOTLOADER, buf); break; case SETTING_LOCK_SCREEN: set_lock_screen_state(val); -- 2.7.4 From 783da7891087a46182e45c93013579649880fa85 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Thu, 17 Oct 2019 20:03:12 +0900 Subject: [PATCH 02/16] Add config file of critical-log to iot and tv profiles. Because of "config-parser.c: config_parse(127) > Failed to read '/etc/deviced/critical-log.conf'. line=0" error on XU3. Change-Id: I9fef3ca3a21052544e9c00aa0ef831d46069bb32 --- packaging/deviced.spec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 97033a8..7ebba2c 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -306,6 +306,7 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %defattr(-,root,root,-) %config %{_sysconfdir}/deviced/tv-display.conf %config %{_sysconfdir}/deviced/display.conf +%config %{_sysconfdir}/deviced/critical-log.conf %{_libdir}/tv-display.so %files plugin-profile-iot @@ -313,4 +314,5 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %license LICENSE.Apache-2.0 %defattr(-,root,root,-) %config %{_sysconfdir}/deviced/display.conf +%config %{_sysconfdir}/deviced/critical-log.conf %{_libdir}/iot-display.so -- 2.7.4 From 5159c9a68c32b862217c40aa98df144945982928 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 17 Oct 2019 17:19:47 +0900 Subject: [PATCH 03/16] Stop checking lock if process had been terminated Change-Id: I960c850c033f6ab2297293ba092c101a1cf77775 Signed-off-by: Youngjae Cho --- plugins/iot/display/core.c | 88 +++++++++++++++++++++++++---------------- plugins/mobile/display/core.c | 88 +++++++++++++++++++++++++---------------- plugins/tv/display/core.c | 87 ++++++++++++++++++++++++---------------- plugins/wearable/display/core.c | 87 ++++++++++++++++++++++++---------------- 4 files changed, 215 insertions(+), 135 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index ad7e29c..ff8385e 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -133,9 +133,7 @@ static gboolean del_normal_cond(void *data); static gboolean del_dim_cond(void *data); static gboolean del_off_cond(void *data); -static gboolean pmlock_normal_check(void *data); -static gboolean pmlock_dim_check(void *data); -static gboolean pmlock_off_check(void *data); +static gboolean pmlock_check(void *data); 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; @@ -161,10 +159,6 @@ static int trans_table[S_END][EVENT_END] = { { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */ }; -static GSourceFunc warning_cb[S_END] = { - NULL, pmlock_normal_check, pmlock_dim_check, pmlock_off_check, -}; - enum signal_type { SIGNAL_INVALID = 0, SIGNAL_PRE, @@ -251,6 +245,7 @@ typedef struct _pm_lock_node { pid_t pid; guint timeout_id; guint warning_id; + GVariant *warning_param; time_t time; bool holdkey_block; bool background; @@ -686,6 +681,7 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, { guint warning_id = 0; PmLockNode *n; + GVariant *v = NULL; time_t now; n = (PmLockNode *) malloc(sizeof(PmLockNode)); @@ -694,14 +690,21 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, return NULL; } - if (pid < INTERNAL_LOCK_BASE) - warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, - warning_cb[s_index], (void *)((intptr_t)pid)); + if (pid < INTERNAL_LOCK_BASE) { + v = g_variant_new("(ii)", s_index, pid); + if (v) { + warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, + pmlock_check, (void *)v); + } else { + _E("Failed to make GVariant."); + } + } time(&now); n->pid = pid; n->timeout_id = timeout_id; n->warning_id = warning_id; + n->warning_param = v; n->time = now; n->holdkey_block = holdkey_block; n->background = false; @@ -728,6 +731,10 @@ static int del_node(enum state_t s_index, PmLockNode *n) g_source_remove(n->warning_id); n->warning_id = 0; } + if (n->warning_param) { + g_variant_unref(n->warning_param); + n->warning_param = NULL; + } free(n); refresh_app_cond(); @@ -873,26 +880,57 @@ out: * or good process. so infinity or more then 1 min lock process, deviced * will be checked it to resoured. And then, it will be asked quit or maintain to user. */ -static void pmlock_check(void *data, char *st) +static gboolean pmlock_check(void *data) { const char *arr[2]; char chr_pid[PID_MAX]; + PmLockNode *node; + GVariant *v; + enum state_t state; pid_t pid; int ret; - if (!data || !st) - return; + if (!data) { + _E("Invalid parameter."); + return G_SOURCE_REMOVE; + } + + v = (GVariant*)data; + g_variant_get(v, "(ii)", &state, &pid); + + _D("Process %d requested state %d lock.", pid, state); - if (!strncmp(st, "lcdoff", 4) && backlight_ops.get_lcd_power() == DPMS_ON) { + if (state == S_LCDOFF && backlight_ops.get_lcd_power() == DPMS_ON) { _D("Lcd state is PM_LCD_POWER_ON"); - return; + 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); + return G_SOURCE_REMOVE; } - pid = (pid_t)((intptr_t)data); snprintf(chr_pid, sizeof(chr_pid), "%d", pid); arr[0] = chr_pid; - arr[1] = st; + switch (state) { + case S_NORMAL: + arr[1] = "normal"; + break; + case S_LCDDIM: + arr[1] = "lcddim"; + break; + case S_LCDOFF: + arr[1] = "lcdoff"; + break; + default: + _E("Invalid state."); + g_variant_unref(v); + return G_SOURCE_REMOVE; + } ret = dbus_handle_method_async_with_reply(RESOURCED_BUS_NAME, RESOURCED_PATH_PROCESS, @@ -901,23 +939,7 @@ static void pmlock_check(void *data, char *st) "is", arr, pmlock_check_cb, -1, NULL); if (ret < 0) _E("Failed to call dbus method"); -} -static gboolean pmlock_normal_check(void *data) -{ - pmlock_check(data, "normal"); - return G_SOURCE_CONTINUE; -} - -static gboolean pmlock_dim_check(void *data) -{ - pmlock_check(data, "lcddim"); - return G_SOURCE_CONTINUE; -} - -static gboolean pmlock_off_check(void *data) -{ - pmlock_check(data, "lcdoff"); return G_SOURCE_CONTINUE; } diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 6eaa984..cb6e375 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -135,9 +135,7 @@ static gboolean del_normal_cond(void *data); static gboolean del_dim_cond(void *data); static gboolean del_off_cond(void *data); -static gboolean pmlock_normal_check(void *data); -static gboolean pmlock_dim_check(void *data); -static gboolean pmlock_off_check(void *data); +static gboolean pmlock_check(void *data); 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; @@ -163,10 +161,6 @@ static int trans_table[S_END][EVENT_END] = { { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */ }; -static GSourceFunc warning_cb[S_END] = { - NULL, pmlock_normal_check, pmlock_dim_check, pmlock_off_check, -}; - enum signal_type { SIGNAL_INVALID = 0, SIGNAL_PRE, @@ -253,6 +247,7 @@ typedef struct _pm_lock_node { pid_t pid; guint timeout_id; guint warning_id; + GVariant *warning_param; time_t time; bool holdkey_block; bool background; @@ -694,6 +689,7 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, { guint warning_id = 0; PmLockNode *n; + GVariant *v = NULL; time_t now; n = (PmLockNode *) malloc(sizeof(PmLockNode)); @@ -702,14 +698,22 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, return NULL; } - if (pid < INTERNAL_LOCK_BASE) - warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, - warning_cb[s_index], (void *)((intptr_t)pid)); + if (pid < INTERNAL_LOCK_BASE) { + v = g_variant_new("(ii)", s_index, pid); + if (v) { + warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, + pmlock_check, (void *)v); + } else { + _E("Failed to make GVariant."); + } + + } time(&now); n->pid = pid; n->timeout_id = timeout_id; n->warning_id = warning_id; + n->warning_param = v; n->time = now; n->holdkey_block = holdkey_block; n->background = false; @@ -736,6 +740,10 @@ static int del_node(enum state_t s_index, PmLockNode *n) g_source_remove(n->warning_id); n->warning_id = 0; } + if (n->warning_param) { + g_variant_unref(n->warning_param); + n->warning_param = NULL; + } free(n); refresh_app_cond(); @@ -881,26 +889,54 @@ out: * or good process. so infinity or more then 1 min lock process, deviced * will be checked it to resoured. And then, it will be asked quit or maintain to user. */ -static void pmlock_check(void *data, char *st) +static gboolean pmlock_check(void *data) { const char *arr[2]; char chr_pid[PID_MAX]; + PmLockNode *node; + GVariant *v; + enum state_t state; pid_t pid; int ret; - if (!data || !st) - return; + if (!data) { + _E("Invalid parameter."); + return G_SOURCE_REMOVE; + } + + v = (GVariant*)data; + g_variant_get(v, "(ii)", &state, &pid); - if (!strncmp(st, "lcdoff", 4) && backlight_ops.get_lcd_power() == DPMS_ON) { + if (state == S_LCDOFF && backlight_ops.get_lcd_power() == DPMS_ON) { _D("Lcd state is PM_LCD_POWER_ON"); - return; + return G_SOURCE_CONTINUE; } - pid = (pid_t)((intptr_t)data); - snprintf(chr_pid, sizeof(chr_pid), "%d", pid); + /* 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); + return G_SOURCE_REMOVE; + } + snprintf(chr_pid, sizeof(chr_pid), "%d", pid); arr[0] = chr_pid; - arr[1] = st; + switch (state) { + case S_NORMAL: + arr[1] = "normal"; + break; + case S_LCDDIM: + arr[1] = "lcddim"; + break; + case S_LCDOFF: + arr[1] = "lcdoff"; + break; + default: + _E("Invalid state."); + g_variant_unref(v); + return G_SOURCE_REMOVE; + } ret = dbus_handle_method_async_with_reply(RESOURCED_BUS_NAME, RESOURCED_PATH_PROCESS, @@ -909,23 +945,7 @@ static void pmlock_check(void *data, char *st) "is", arr, pmlock_check_cb, -1, NULL); if (ret < 0) _E("Failed to call dbus method"); -} -static gboolean pmlock_normal_check(void *data) -{ - pmlock_check(data, "normal"); - return G_SOURCE_CONTINUE; -} - -static gboolean pmlock_dim_check(void *data) -{ - pmlock_check(data, "lcddim"); - return G_SOURCE_CONTINUE; -} - -static gboolean pmlock_off_check(void *data) -{ - pmlock_check(data, "lcdoff"); return G_SOURCE_CONTINUE; } diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 2d94505..a520497 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -133,9 +133,7 @@ static gboolean del_normal_cond(void *data); static gboolean del_dim_cond(void *data); static gboolean del_off_cond(void *data); -static gboolean pmlock_normal_check(void *data); -static gboolean pmlock_dim_check(void *data); -static gboolean pmlock_off_check(void *data); +static gboolean pmlock_check(void *data); 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; @@ -161,10 +159,6 @@ static int trans_table[S_END][EVENT_END] = { { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */ }; -static GSourceFunc warning_cb[S_END] = { - NULL, pmlock_normal_check, pmlock_dim_check, pmlock_off_check, -}; - enum signal_type { SIGNAL_INVALID = 0, SIGNAL_PRE, @@ -251,6 +245,7 @@ typedef struct _pm_lock_node { pid_t pid; guint timeout_id; guint warning_id; + GVariant *warning_param; time_t time; bool holdkey_block; bool background; @@ -686,6 +681,7 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, { guint warning_id = 0; PmLockNode *n; + GVariant *v = NULL; time_t now; n = (PmLockNode *) malloc(sizeof(PmLockNode)); @@ -694,14 +690,21 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, return NULL; } - if (pid < INTERNAL_LOCK_BASE) - warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, - warning_cb[s_index], (void *)((intptr_t)pid)); + if (pid < INTERNAL_LOCK_BASE) { + v = g_variant_new("(ii)", s_index, pid); + if (v) { + warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, + pmlock_check, (void *)v); + } else { + _E("Failed to make GVariant."); + } + } time(&now); n->pid = pid; n->timeout_id = timeout_id; n->warning_id = warning_id; + n->warning_param = v; n->time = now; n->holdkey_block = holdkey_block; n->background = false; @@ -728,6 +731,10 @@ static int del_node(enum state_t s_index, PmLockNode *n) g_source_remove(n->warning_id); n->warning_id = 0; } + if (n->warning_param) { + g_variant_unref(n->warning_param); + n->warning_param = NULL; + } free(n); refresh_app_cond(); @@ -873,26 +880,54 @@ out: * or good process. so infinity or more then 1 min lock process, deviced * will be checked it to resoured. And then, it will be asked quit or maintain to user. */ -static void pmlock_check(void *data, char *st) +static gboolean pmlock_check(void *data) { const char *arr[2]; char chr_pid[PID_MAX]; + PmLockNode *node; + GVariant *v; + enum state_t state; pid_t pid; int ret; - if (!data || !st) - return; + if (!data) { + _E("Invalid parameter."); + return G_SOURCE_REMOVE; + } + + v = (GVariant*)data; + g_variant_get(v, "(ii)", &state, &pid); - if (!strncmp(st, "lcdoff", 4) && backlight_ops.get_lcd_power() == DPMS_ON) { + if (state == S_LCDOFF && backlight_ops.get_lcd_power() == DPMS_ON) { _D("Lcd state is PM_LCD_POWER_ON"); - return; + return G_SOURCE_CONTINUE; } - pid = (pid_t)((intptr_t)data); - snprintf(chr_pid, sizeof(chr_pid), "%d", pid); + /* 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); + return G_SOURCE_REMOVE; + } + snprintf(chr_pid, sizeof(chr_pid), "%d", pid); arr[0] = chr_pid; - arr[1] = st; + switch (state) { + case S_NORMAL: + arr[1] = "normal"; + break; + case S_LCDDIM: + arr[1] = "lcddim"; + break; + case S_LCDOFF: + arr[1] = "lcdoff"; + break; + default: + _E("Invalid state."); + g_variant_unref(v); + return G_SOURCE_REMOVE; + } ret = dbus_handle_method_async_with_reply(RESOURCED_BUS_NAME, RESOURCED_PATH_PROCESS, @@ -901,23 +936,7 @@ static void pmlock_check(void *data, char *st) "is", arr, pmlock_check_cb, -1, NULL); if (ret < 0) _E("Failed to call dbus method"); -} -static gboolean pmlock_normal_check(void *data) -{ - pmlock_check(data, "normal"); - return G_SOURCE_CONTINUE; -} - -static gboolean pmlock_dim_check(void *data) -{ - pmlock_check(data, "lcddim"); - return G_SOURCE_CONTINUE; -} - -static gboolean pmlock_off_check(void *data) -{ - pmlock_check(data, "lcdoff"); return G_SOURCE_CONTINUE; } diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 1e5998c..68cc5f8 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -134,9 +134,7 @@ static gboolean del_normal_cond(void *data); static gboolean del_dim_cond(void *data); static gboolean del_off_cond(void *data); -static gboolean pmlock_normal_check(void *data); -static gboolean pmlock_dim_check(void *data); -static gboolean pmlock_off_check(void *data); +static gboolean pmlock_check(void *data); 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; @@ -162,10 +160,6 @@ static int trans_table[S_END][EVENT_END] = { { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */ }; -static GSourceFunc warning_cb[S_END] = { - NULL, pmlock_normal_check, pmlock_dim_check, pmlock_off_check, -}; - enum signal_type { SIGNAL_INVALID = 0, SIGNAL_PRE, @@ -252,6 +246,7 @@ typedef struct _pm_lock_node { pid_t pid; guint timeout_id; guint warning_id; + GVariant *warning_param; time_t time; bool holdkey_block; bool background; @@ -693,6 +688,7 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, { guint warning_id = 0; PmLockNode *n; + GVariant *v = NULL; time_t now; n = (PmLockNode *) malloc(sizeof(PmLockNode)); @@ -701,14 +697,21 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, return NULL; } - if (pid < INTERNAL_LOCK_BASE) - warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, - warning_cb[s_index], (void *)((intptr_t)pid)); + if (pid < INTERNAL_LOCK_BASE) { + v = g_variant_new("(ii)", s_index, pid); + if (v) { + warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, + pmlock_check, (void *)v); + } else { + _E("Failed to make GVariant."); + } + } time(&now); n->pid = pid; n->timeout_id = timeout_id; n->warning_id = warning_id; + n->warning_param = v; n->time = now; n->holdkey_block = holdkey_block; n->background = false; @@ -735,6 +738,10 @@ static int del_node(enum state_t s_index, PmLockNode *n) g_source_remove(n->warning_id); n->warning_id = 0; } + if (n->warning_param) { + g_variant_unref(n->warning_param); + n->warning_param = NULL; + } free(n); refresh_app_cond(); @@ -880,26 +887,54 @@ out: * or good process. so infinity or more then 1 min lock process, deviced * will be checked it to resoured. And then, it will be asked quit or maintain to user. */ -static void pmlock_check(void *data, char *st) +static gboolean pmlock_check(void *data) { const char *arr[2]; char chr_pid[PID_MAX]; + PmLockNode *node; + GVariant *v; + enum state_t state; pid_t pid; int ret; - if (!data || !st) - return; + if (!data) { + _E("Invalid parameter."); + return G_SOURCE_REMOVE; + } + + v = (GVariant*)data; + g_variant_get(v, "(ii)", &state, &pid); - if (!strncmp(st, "lcdoff", 4) && backlight_ops.get_lcd_power() == DPMS_ON) { + if (state == S_LCDOFF && backlight_ops.get_lcd_power() == DPMS_ON) { _D("Lcd state is PM_LCD_POWER_ON"); - return; + return G_SOURCE_CONTINUE; } - pid = (pid_t)((intptr_t)data); - snprintf(chr_pid, sizeof(chr_pid), "%d", pid); + /* 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); + return G_SOURCE_REMOVE; + } + snprintf(chr_pid, sizeof(chr_pid), "%d", pid); arr[0] = chr_pid; - arr[1] = st; + switch (state) { + case S_NORMAL: + arr[1] = "normal"; + break; + case S_LCDDIM: + arr[1] = "lcddim"; + break; + case S_LCDOFF: + arr[1] = "lcdoff"; + break; + default: + _E("Invalid state."); + g_variant_unref(v); + return G_SOURCE_REMOVE; + } ret = dbus_handle_method_async_with_reply(RESOURCED_BUS_NAME, RESOURCED_PATH_PROCESS, @@ -908,23 +943,7 @@ static void pmlock_check(void *data, char *st) "is", arr, pmlock_check_cb, -1, NULL); if (ret < 0) _E("Failed to call dbus method"); -} -static gboolean pmlock_normal_check(void *data) -{ - pmlock_check(data, "normal"); - return G_SOURCE_CONTINUE; -} - -static gboolean pmlock_dim_check(void *data) -{ - pmlock_check(data, "lcddim"); - return G_SOURCE_CONTINUE; -} - -static gboolean pmlock_off_check(void *data) -{ - pmlock_check(data, "lcdoff"); return G_SOURCE_CONTINUE; } -- 2.7.4 From d2aed82ae874014230be093d72a688d9e5be43a1 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 28 Oct 2019 10:52:03 +0900 Subject: [PATCH 04/16] Delete trailing '\n' character in log of ctime_r Change-Id: I494de2e480bbc3aff092136f75d114560763f747 Signed-off-by: Youngjae Cho --- plugins/iot/display/core.c | 4 ++++ plugins/mobile/display/core.c | 4 ++++ plugins/tv/display/core.c | 4 ++++ plugins/wearable/display/core.c | 4 ++++ src/display/lock-detector.c | 3 +++ src/time/time-handler.c | 2 ++ 6 files changed, 21 insertions(+) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index ff8385e..421bbbb 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -757,6 +757,7 @@ static void print_node(int next) DD_LIST_FOREACH(cond_head[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) { @@ -1705,6 +1706,7 @@ void pm_history_print(int fd, int count) pm_history_log[index].log_type >= PM_LOG_MAX) continue; ctime_r(&pm_history_log[index].time, time_buf); + time_buf[strlen(time_buf) - 1] = 0; snprintf(buf, sizeof(buf), "[%3d] %15s %3d %s", index, history_string[pm_history_log[index].log_type], @@ -1767,6 +1769,7 @@ void print_info(int fd) DD_LIST_FOREACH(cond_head[s_index], elem, t) { get_pname((pid_t)t->pid, pname); ctime_r(&t->time, time_buf); + time_buf[strlen(time_buf) - 1] = 0; snprintf(buf, sizeof(buf), " %d: [%s] locked by pid %d %s %s", i++, states[s_index].name, t->pid, pname, time_buf); @@ -1794,6 +1797,7 @@ void save_display_log(char *path) time(&now_time); ctime_r(&now_time, time_buf); + time_buf[strlen(time_buf) - 1] = 0; fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0644); if (fd != -1) { diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index cb6e375..11faff5 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -766,6 +766,7 @@ static void print_node(int next) DD_LIST_FOREACH(cond_head[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) { @@ -1715,6 +1716,7 @@ void pm_history_print(int fd, int count) pm_history_log[index].log_type >= PM_LOG_MAX) continue; ctime_r(&pm_history_log[index].time, time_buf); + time_buf[strlen(time_buf) - 1] = 0; snprintf(buf, sizeof(buf), "[%3d] %15s %3d %s", index, history_string[pm_history_log[index].log_type], @@ -1777,6 +1779,7 @@ void print_info(int fd) DD_LIST_FOREACH(cond_head[s_index], elem, t) { get_pname((pid_t)t->pid, pname); ctime_r(&t->time, time_buf); + time_buf[strlen(time_buf) - 1] = 0; snprintf(buf, sizeof(buf), " %d: [%s] locked by pid %d %s %s", i++, states[s_index].name, t->pid, pname, time_buf); @@ -1804,6 +1807,7 @@ void save_display_log(char *path) time(&now_time); ctime_r(&now_time, time_buf); + time_buf[strlen(time_buf) - 1] = 0; fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0644); if (fd != -1) { diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index a520497..7069a6e 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -757,6 +757,7 @@ static void print_node(int next) DD_LIST_FOREACH(cond_head[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) { @@ -1702,6 +1703,7 @@ void pm_history_print(int fd, int count) pm_history_log[index].log_type >= PM_LOG_MAX) continue; ctime_r(&pm_history_log[index].time, time_buf); + time_buf[strlen(time_buf) - 1] = 0; snprintf(buf, sizeof(buf), "[%3d] %15s %3d %s", index, history_string[pm_history_log[index].log_type], @@ -1764,6 +1766,7 @@ void print_info(int fd) DD_LIST_FOREACH(cond_head[s_index], elem, t) { get_pname((pid_t)t->pid, pname); ctime_r(&t->time, time_buf); + time_buf[strlen(time_buf) - 1] = 0; snprintf(buf, sizeof(buf), " %d: [%s] locked by pid %d %s %s", i++, states[s_index].name, t->pid, pname, time_buf); @@ -1791,6 +1794,7 @@ void save_display_log(char *path) time(&now_time); ctime_r(&now_time, time_buf); + time_buf[strlen(time_buf) - 1] = 0; fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0644); if (fd != -1) { diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 68cc5f8..1a21d54 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -764,6 +764,7 @@ static void print_node(int next) DD_LIST_FOREACH(cond_head[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) { @@ -1724,6 +1725,7 @@ void pm_history_print(int fd, int count) pm_history_log[index].log_type >= PM_LOG_MAX) continue; ctime_r(&pm_history_log[index].time, time_buf); + time_buf[strlen(time_buf) - 1] = 0; snprintf(buf, sizeof(buf), "[%3d] %15s %3d %s", index, history_string[pm_history_log[index].log_type], @@ -1786,6 +1788,7 @@ void print_info(int fd) DD_LIST_FOREACH(cond_head[s_index], elem, t) { get_pname((pid_t)t->pid, pname); ctime_r(&t->time, time_buf); + time_buf[strlen(time_buf) - 1] = 0; snprintf(buf, sizeof(buf), " %d: [%s] locked by pid %d %s %s", i++, states[s_index].name, t->pid, pname, time_buf); @@ -1813,6 +1816,7 @@ void save_display_log(char *path) time(&now_time); ctime_r(&now_time, time_buf); + time_buf[strlen(time_buf) - 1] = 0; fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0644); if (fd != -1) { diff --git a/src/display/lock-detector.c b/src/display/lock-detector.c index b2fa365..bf2cf5f 100644 --- a/src/display/lock-detector.c +++ b/src/display/lock-detector.c @@ -266,6 +266,7 @@ void print_lock_info_list(int fd) cur_time = get_time(); ctime_r(&cur_time, cur_buf); + cur_buf[strlen(cur_buf) - 1] = 0; snprintf(buf, sizeof(buf), "current time : %s\n", cur_buf); ret = write(fd, buf, strlen(buf)); if (ret < 0) @@ -288,6 +289,7 @@ void print_lock_info_list(int fd) if (info->locktime) { ctime_r(&info->locktime, lock_buf); + lock_buf[strlen(lock_buf) - 1] = 0; tmp = strchr(lock_buf, '\n'); if (!tmp) continue; @@ -295,6 +297,7 @@ void print_lock_info_list(int fd) } if (info->unlocktime) { ctime_r(&info->unlocktime, unlock_buf); + unlock_buf[strlen(unlock_buf) - 1] = 0; tmp = strchr(unlock_buf, '\n'); if (!tmp) continue; diff --git a/src/time/time-handler.c b/src/time/time-handler.c index 82169e2..6ffebd1 100644 --- a/src/time/time-handler.c +++ b/src/time/time-handler.c @@ -109,6 +109,7 @@ int handle_timezone(char *str) ts2 = localtime_r(&now, &ts); if (ts2) { asctime_r(&ts, buf); + buf[strlen(buf) - 1] = 0; _D("Current local time is %s.", buf); } @@ -140,6 +141,7 @@ int handle_timezone(char *str) ts2 = localtime_r(&now, &ts); if (ts2) { asctime_r(&ts, buf); + buf[strlen(buf) - 1] = 0; _D("New local time is %s.", buf); } return 0; -- 2.7.4 From 815e0a9036fa91251970100734dfa6e477dfb7ae Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 5 Nov 2019 10:29:05 +0900 Subject: [PATCH 05/16] Remove pweroff_popup, shorten long key press interval Change-Id: Ic0ce8d155ec698265f582f813de5874dd8925416 Signed-off-by: Youngjae Cho --- plugins/mobile/display/core.c | 2 +- plugins/mobile/display/key-filter.c | 21 +++++---------------- plugins/wearable/display/core.c | 2 +- plugins/wearable/display/key-filter.c | 21 +++++---------------- 4 files changed, 12 insertions(+), 34 deletions(-) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 11faff5..649f4bd 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -201,7 +201,7 @@ static const char *lcdoff_sig_lookup[SIGNAL_MAX] = { #define INACTIVE_ACT "inactive" #define LOCK_SCREEN_WATING_TIME 300 /* 0.3 second */ -#define LONG_PRESS_INTERVAL 2 /* 2 seconds */ +#define LONG_PRESS_INTERVAL 400 /* 0.4 seconds */ #define SAMPLING_INTERVAL 1 /* 1 sec */ #define BRIGHTNESS_CHANGE_STEP 10 #define LCD_ALWAYS_ON 0 diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index ddbb287..d63eff2 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -51,8 +51,8 @@ #define PREDEF_LEAVESLEEP "leavesleep" #define POWEROFF_ACT "poweroff" -#define PWROFF_POPUP_ACT "pwroff_popup" #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 */ @@ -113,16 +113,6 @@ static inline void restore_custom_brightness(void) backlight_ops.custom_update(); } -static void pwroff_popup(void) -{ - int ret; - - pm_status_flag &= ~PWROFF_FLAG; - ret = launch_system_app(APP_POWERKEY, 2, APP_KEY_TYPE, APP_POWERKEY); - if (ret < 0) - _E("Failed to launch power off popup."); -} - static void longkey_pressed(void) { unsigned int caps; @@ -143,8 +133,7 @@ static void longkey_pressed(void) _D("No poweroff capability!"); return; } - - pwroff_popup(); + pm_status_flag &= ~PWROFF_FLAG; } static gboolean longkey_restore_cb(void *data) @@ -517,11 +506,11 @@ static int process_power_key(struct input_event *pinput) pressed_time.tv_usec = (pinput->time).tv_usec; if (key_combination == KEY_COMBINATION_POWERKEY) { /* add long key timer */ - longkey_timeout_id = g_timeout_add_seconds( + longkey_timeout_id = g_timeout_add( display_conf.longpress_interval, longkey_pressed_cb, NULL); /* add long key restore timer */ - longkey_restore_id = g_timeout_add_seconds( + longkey_restore_id = g_timeout_add( LONGKEY_PRESSED_TIME, longkey_restore_cb, NULL); } @@ -530,7 +519,7 @@ static int process_power_key(struct input_event *pinput) break; case KEY_BEING_PRESSED: if (timediff_usec(pressed_time, pinput->time) > - (display_conf.longpress_interval * USEC_PER_SEC)) + (display_conf.longpress_interval * USEC_PER_MSEC)) longkey_pressed(); break; } diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 1a21d54..e328df8 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -200,7 +200,7 @@ static const char *lcdoff_sig_lookup[SIGNAL_MAX] = { #define INACTIVE_ACT "inactive" #define LOCK_SCREEN_WATING_TIME 300 /* 0.3 second */ -#define LONG_PRESS_INTERVAL 2 /* 2 seconds */ +#define LONG_PRESS_INTERVAL 500 /* 0.5 seconds */ #define SAMPLING_INTERVAL 1 /* 1 sec */ #define BRIGHTNESS_CHANGE_STEP 10 #define LCD_ALWAYS_ON 0 diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index 7835a17..a160641 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -51,8 +51,8 @@ #define PREDEF_LEAVESLEEP "leavesleep" #define POWEROFF_ACT "poweroff" -#define PWROFF_POPUP_ACT "pwroff_popup" #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 */ @@ -113,16 +113,6 @@ static inline void restore_custom_brightness(void) backlight_ops.custom_update(); } -static void pwroff_popup(void) -{ - int ret; - - pm_status_flag &= ~PWROFF_FLAG; - ret = launch_system_app(APP_POWERKEY, 2, APP_KEY_TYPE, APP_POWERKEY); - if (ret < 0) - _E("Failed to launch power off popup."); -} - static void longkey_pressed(void) { unsigned int caps; @@ -143,8 +133,7 @@ static void longkey_pressed(void) _D("No poweroff capability!"); return; } - - pwroff_popup(); + pm_status_flag &= ~PWROFF_FLAG; } static gboolean longkey_restore_cb(void *data) @@ -517,11 +506,11 @@ static int process_power_key(struct input_event *pinput) pressed_time.tv_usec = (pinput->time).tv_usec; if (key_combination == KEY_COMBINATION_POWERKEY) { /* add long key timer */ - longkey_timeout_id = g_timeout_add_seconds( + longkey_timeout_id = g_timeout_add( display_conf.longpress_interval, longkey_pressed_cb, NULL); /* add long key restore timer */ - longkey_restore_id = g_timeout_add_seconds( + longkey_restore_id = g_timeout_add( LONGKEY_PRESSED_TIME, longkey_restore_cb, NULL); } @@ -530,7 +519,7 @@ static int process_power_key(struct input_event *pinput) break; case KEY_BEING_PRESSED: if (timediff_usec(pressed_time, pinput->time) > - (display_conf.longpress_interval * USEC_PER_SEC)) + (display_conf.longpress_interval * USEC_PER_MSEC)) longkey_pressed(); break; } -- 2.7.4 From 8698c1b8b0b0247e7cb3629d1c29d4c84ec0bf50 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 11 Nov 2019 11:13:52 +0900 Subject: [PATCH 06/16] Disable reboot option check Change-Id: If0ab215661dd131c04558ae055260b2fa72e1246 Signed-off-by: Hyotaek Shim --- src/power/power-handler.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 8bdba86..404b7e4 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -422,6 +422,7 @@ static int poweroff_option_valid(enum poweroff_type type_e, const char *option) if (elem->type != type_e) continue; + /* Do not match option if (option) { if (elem->option == NULL) continue; @@ -430,7 +431,7 @@ static int poweroff_option_valid(enum poweroff_type type_e, const char *option) } else { if (elem->option != NULL) continue; - } + } */ return 1; } -- 2.7.4 From f4b5c461351d5b207fb25633419c366a681f6b5d Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 8 Nov 2019 15:33:26 +0900 Subject: [PATCH 07/16] Exclude battery critical-log in case of -DBATTERY_MODULE=off Change-Id: I9adfd7018964fb14b73f1453876ee0fc3d5b78ea Signed-off-by: Youngjae Cho --- CMakeLists.txt | 4 +++- packaging/deviced.spec | 6 +++++- src/critical-log/critical-log.c | 13 +++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 10f7bb8..d47d10f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -223,7 +223,9 @@ ADD_DEFINITIONS("-DENABLE_PM_LOG") IF(ENGINEER_MODE STREQUAL on) ADD_DEFINITIONS("-DENGINEER_MODE") ENDIF(ENGINEER_MODE STREQUAL on) - +IF(BATTERY_MODULE STREQUAL on) +ADD_DEFINITIONS("-DBATTERY_MODULE") +ENDIF(ENGINEER_MODULE STREQUAL on) IF(USE_ARM) ADD_DEFINITIONS("-DTARGET") ENDIF() diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 7ebba2c..87b1f68 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -139,6 +139,8 @@ Plugin libraries for IoT devices %define engineer_mode off %endif +%define battery_module on + %cmake \ -DTZ_SYS_ETC=%TZ_SYS_ETC \ -DCMAKE_INSTALL_PREFIX=%{_prefix} \ @@ -146,7 +148,7 @@ Plugin libraries for IoT devices -DARCH_BIT=%{ARCH_BIT} \ -DDPMS=%{DPMS} \ -DENGINEER_MODE=%{engineer_mode} \ - -DBATTERY_MODULE=on \ + -DBATTERY_MODULE=%{battery_module} \ -DDISPLAY_MODULE=on \ -DEXTCON_MODULE=on \ -DIR_MODULE=on \ @@ -244,7 +246,9 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %config %{_sysconfdir}/dbus-1/system.d/org.tizen.system.deviced.conf %config %{_sysconfdir}/deviced/cpu.conf %config %{_sysconfdir}/deviced/power.conf +%if %{?battery_module} == on %config %{_sysconfdir}/deviced/battery.conf +%endif # usbhost_test %{_sysconfdir}/deviced/usb-host-test/test_gadget.gs %{_bindir}/usb-host-ffs-test-daemon diff --git a/src/critical-log/critical-log.c b/src/critical-log/critical-log.c index 154859a..d826833 100644 --- a/src/critical-log/critical-log.c +++ b/src/critical-log/critical-log.c @@ -28,7 +28,9 @@ #include "core/common.h" #include "core/config-parser.h" #include "core/device-notifier.h" +#ifdef BATTERY_MODULE #include "battery/power-supply.h" +#endif #include "power/power-handler.h" #define CLOG_SAVE_FILE "/var/log/critical-log.log" @@ -192,6 +194,7 @@ static int clog_execute(void *data) localtime_r((time_t *)&tspec.tv_sec, &tm_now); strftime(str_time, sizeof(str_time), CLOG_TIME_FORMAT, &tm_now); snprintf(str_msec, sizeof(str_msec), ":%03ld|", tspec.tv_nsec / 1000000); +#ifdef BATTERY_MODULE snprintf(str_buff, sizeof(str_buff), "%s%s[%d]%s BAT(P:%s S:%s C:%d M:%d Chg_ON:%d)\n", str_time, str_msec, getpid(), input, battery.power_source_s, @@ -199,6 +202,10 @@ static int clog_execute(void *data) battery.capacity, battery.misc, battery.charger_charging); +#else + snprintf(str_buff, sizeof(str_buff), "%s%s[%d]%s\n", + str_time, str_msec, getpid(), input); +#endif _D("%s", str_buff); msg->log = strdup(str_buff); msg->type = tag->type; @@ -231,6 +238,7 @@ out: return ret; } +#ifdef BATTERY_MODULE static int clog_battery_health(void *data) { char clog[CLOG_MSG_MAX] = {0,}; @@ -272,6 +280,7 @@ static int clog_battery_present(void *data) return clog_execute((void *)clog); } +#endif static void clog_save_log(void) { @@ -447,8 +456,10 @@ out: static void clog_init(void *none) { register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, clog_booting_done); +#ifdef BATTERY_MODULE register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, clog_battery_health); register_notifier(DEVICE_NOTIFIER_BATTERY_PRESENT, clog_battery_present); +#endif register_notifier(DEVICE_NOTIFIER_CRITICAL_LOG, clog_common_log); register_notifier(DEVICE_NOTIFIER_POWEROFF, clog_power_off); if (config_parse(CLOG_CONF_FILE, clog_load_config, NULL) < 0) @@ -457,8 +468,10 @@ static void clog_init(void *none) static void clog_exit(void *data) { +#ifdef BATTERY_MODULE unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, clog_battery_health); unregister_notifier(DEVICE_NOTIFIER_BATTERY_PRESENT, clog_battery_present); +#endif unregister_notifier(DEVICE_NOTIFIER_CRITICAL_LOG, clog_common_log); unregister_notifier(DEVICE_NOTIFIER_POWEROFF, clog_power_off); free_clog_data(); -- 2.7.4 From c4c53244669ab4d74f15c4ea79dbcd0910d04fa9 Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Fri, 8 Nov 2019 11:02:44 +0900 Subject: [PATCH 08/16] svace fix Change-Id: I520705e248ae242f8aba8c1821380d774cee3046 Signed-off-by: sanghyeok.oh --- src/battery/power-supply.c | 6 +++++- src/display/display-dbus.c | 9 ++++++--- src/touchscreen/sensitivity.c | 4 +++- src/usbhost/usb-host.c | 5 +++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index f375b0a..876fc94 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -525,7 +525,11 @@ static void update_present(enum battery_noti_status status) void remove_health_popup(void) { - launch_system_app(APP_REMOVE, 2, APP_KEY_TYPE, REMOVE_POPUP); + int ret; + + ret = launch_system_app(APP_REMOVE, 2, APP_KEY_TYPE, REMOVE_POPUP); + if (ret < 0) + _E("Failed to launch remove battery popup(%d)", ret); } static void update_health(enum battery_noti_status status) diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index d95e557..e2f38ec 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -987,8 +987,10 @@ static gboolean app_term(gpointer data) struct pmlock_expired_s *ex = data; if (ex) { - if (kill(ex->pid, 0) != -1) - kill(ex->pid, SIGKILL); + if (ex->pid > 0 && kill(ex->pid, 0) != -1) { + if (kill(ex->pid, SIGKILL) == -1) + _E("failed to kill pid(%d), err(%m)", ex->pid); + } free(ex); } return G_SOURCE_REMOVE; @@ -1029,7 +1031,8 @@ static void expired_deliver_result(void *data) g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(i)", 0)); if (value == 2) { - kill(item->pid, SIGTERM); + if (item->pid > 0 && kill(item->pid, SIGTERM) == -1) + _E("failed to kill pid(%d), err(%m)", item->pid); g_timeout_add(3000, app_term, (gpointer)item); item = NULL; } diff --git a/src/touchscreen/sensitivity.c b/src/touchscreen/sensitivity.c index d3d14d6..3eaacee 100644 --- a/src/touchscreen/sensitivity.c +++ b/src/touchscreen/sensitivity.c @@ -207,12 +207,14 @@ static void sensitivity_init(void *data) if (ret < 0) _E("Failed to init dbus method: %d", ret); - subscribe_dbus_signal(NULL, + ret = subscribe_dbus_signal(NULL, DEVICED_PATH_TOUCH, DEVICED_INTERFACE_TOUCH, DISABLE_SENSITIVITY_SIGNAL, disable_touch_sensitivity_handler, NULL, NULL); + if (ret <= 0) + _E("Failed to register signal handler: %d", ret); register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); } diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index 3f95ea9..bafc4c5 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -755,6 +755,11 @@ static int get_device_desc(const char *filepath, struct usb_device_descriptor *d } rdevpath = udev_device_get_devpath(udev_device); + if (!rdevpath) { + _E("Failed to get devpath from udev_device."); + ret = -errno; + goto out; + } strncpy(devpath, rdevpath, PATH_MAX); ret = asprintf(&path, "/sys/dev/char/%d:%d/descriptors", major(st.st_rdev), minor(st.st_rdev)); -- 2.7.4 From 1042afd91f11fca392e046e799b3e89b1688b858 Mon Sep 17 00:00:00 2001 From: Junkyeong Kim Date: Wed, 6 Nov 2019 16:31:14 +0900 Subject: [PATCH 09/16] display-dpms: use get_state listener to get get_dpms request event Change-Id: Iae31d9d3d95fcdd6c886c3be5988d7b19759bc72 Signed-off-by: Junkyeong Kim --- src/display/display-dpms.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c index ef62f03..1705b63 100644 --- a/src/display/display-dpms.c +++ b/src/display/display-dpms.c @@ -46,9 +46,15 @@ bool wm_is_ready; static bool dpms_connected; static GSource *wl_glib_data = NULL; -static void dpms_handle_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error) +static void dpms_handle_set_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error) { - _D("Dpms_state_cb - mode:%u, error:%u", mode, error); + _D("Dpms_state_cb set - mode:%u, error:%u", mode, error); + info->dpms_mode = mode; +} + +static void dpms_handle_get_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error) +{ + _D("Dpms_state_cb get - mode:%u, error:%u", mode, error); info->dpms_mode = mode; } @@ -88,7 +94,8 @@ void disconnect_interface_with_dpms(void) } static const struct tizen_dpms_manager_listener dpms_listener = { - dpms_handle_state + dpms_handle_set_state, + dpms_handle_get_state }; static void handle_global(void *data, struct wl_registry *registry, -- 2.7.4 From 78ebde4dcbbc063569685eb4ff56826509d6e594 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 12 Nov 2019 15:28:14 +0900 Subject: [PATCH 10/16] Add touchscreen execute Change-Id: Ia97235271addd8c10690e1b0dbfdc92b3b8c0231 Signed-off-by: Youngjae Cho --- src/touchscreen/touchscreen.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/touchscreen/touchscreen.c b/src/touchscreen/touchscreen.c index 45caf74..a2ef250 100644 --- a/src/touchscreen/touchscreen.c +++ b/src/touchscreen/touchscreen.c @@ -24,6 +24,7 @@ #include "core/log.h" static struct touchscreen_device *touchscreen_dev; +static int touchscreen_enable = DEVICE_OPS_STATUS_START; static int touchscreen_probe(void *data) { @@ -100,8 +101,17 @@ static int touchscreen_set_state(enum touchscreen_state state) return ret; } +static int touchscreen_execute(void *data) +{ + touchscreen_enable = (int)data; + return 0; +} + static int touchscreen_start(enum device_flags flags) { + if (touchscreen_enable != DEVICE_OPS_STATUS_START) + return 0; + return touchscreen_set_state(TOUCHSCREEN_ON); } @@ -139,6 +149,7 @@ static const struct device_ops touchscreen_device_ops = { .start = touchscreen_start, .stop = touchscreen_stop, .dump = touchscreen_dump, + .execute = touchscreen_execute, }; DEVICE_OPS_REGISTER(&touchscreen_device_ops) -- 2.7.4 From a83bbab5d9f966dfecb729524b8bac831c3f6f73 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 14 Nov 2019 17:49:11 +0900 Subject: [PATCH 11/16] Make get_lcd_power() use dpms to get lcd power Deviced used to set lcd power by requesting to dpms(dpms_set_state), but get lcd power by reading node directly through HAL(display_dev->get_state). To make this get/set machanism same, get mechanism changed to use dpms(dpms_get_state), removed all regarding HAL. Also, make dpms_get_state synchronous and dpms_set_state asynchronous to ensure latency issue. Change-Id: Ib93cb55d18f3e175a16c7138288b09ac76d25f05 Signed-off-by: Youngjae Cho --- plugins/iot/display/device-interface.c | 49 +++++++++++++-------------- plugins/mobile/display/device-interface.c | 49 +++++++++++++-------------- plugins/tv/display/device-interface.c | 49 +++++++++++++-------------- plugins/wearable/display/device-interface.c | 49 +++++++++++++-------------- src/display/display-dpms.c | 52 +++++++++++++++++++++++++++-- 5 files changed, 146 insertions(+), 102 deletions(-) diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index 37a86cb..abea4c3 100644 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -262,31 +262,30 @@ static int get_lcd_power(void) int ret; if (!display_dev || !display_dev->get_state) { - _E("There is no display device."); - return -ENOENT; - } - - ret = display_dev->get_state(&val); - if (ret < 0) - return ret; - - if (val == DISPLAY_ON && ambient_get_state()) - return DPMS_OFF; - - if (dpms_running_state != DPMS_SETTING_DONE) - return dpms_running_state; - - switch (val) { - case DISPLAY_ON: - return DPMS_ON; - case DISPLAY_STANDBY: - return DPMS_STANDBY; - case DISPLAY_SUSPEND: - return DPMS_SUSPEND; - case DISPLAY_OFF: - return DPMS_OFF; - default: - return -EINVAL; + return dpms_get_state(); + } else { + ret = display_dev->get_state(&val); + if (ret < 0) + return ret; + + if (val == DISPLAY_ON && ambient_get_state()) + return DPMS_OFF; + + if (dpms_running_state != DPMS_SETTING_DONE) + return dpms_running_state; + + switch (val) { + case DISPLAY_ON: + return DPMS_ON; + case DISPLAY_STANDBY: + return DPMS_STANDBY; + case DISPLAY_SUSPEND: + return DPMS_SUSPEND; + case DISPLAY_OFF: + return DPMS_OFF; + default: + return -EINVAL; + } } } diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 37a86cb..abea4c3 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -262,31 +262,30 @@ static int get_lcd_power(void) int ret; if (!display_dev || !display_dev->get_state) { - _E("There is no display device."); - return -ENOENT; - } - - ret = display_dev->get_state(&val); - if (ret < 0) - return ret; - - if (val == DISPLAY_ON && ambient_get_state()) - return DPMS_OFF; - - if (dpms_running_state != DPMS_SETTING_DONE) - return dpms_running_state; - - switch (val) { - case DISPLAY_ON: - return DPMS_ON; - case DISPLAY_STANDBY: - return DPMS_STANDBY; - case DISPLAY_SUSPEND: - return DPMS_SUSPEND; - case DISPLAY_OFF: - return DPMS_OFF; - default: - return -EINVAL; + return dpms_get_state(); + } else { + ret = display_dev->get_state(&val); + if (ret < 0) + return ret; + + if (val == DISPLAY_ON && ambient_get_state()) + return DPMS_OFF; + + if (dpms_running_state != DPMS_SETTING_DONE) + return dpms_running_state; + + switch (val) { + case DISPLAY_ON: + return DPMS_ON; + case DISPLAY_STANDBY: + return DPMS_STANDBY; + case DISPLAY_SUSPEND: + return DPMS_SUSPEND; + case DISPLAY_OFF: + return DPMS_OFF; + default: + return -EINVAL; + } } } diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 37a86cb..abea4c3 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -262,31 +262,30 @@ static int get_lcd_power(void) int ret; if (!display_dev || !display_dev->get_state) { - _E("There is no display device."); - return -ENOENT; - } - - ret = display_dev->get_state(&val); - if (ret < 0) - return ret; - - if (val == DISPLAY_ON && ambient_get_state()) - return DPMS_OFF; - - if (dpms_running_state != DPMS_SETTING_DONE) - return dpms_running_state; - - switch (val) { - case DISPLAY_ON: - return DPMS_ON; - case DISPLAY_STANDBY: - return DPMS_STANDBY; - case DISPLAY_SUSPEND: - return DPMS_SUSPEND; - case DISPLAY_OFF: - return DPMS_OFF; - default: - return -EINVAL; + return dpms_get_state(); + } else { + ret = display_dev->get_state(&val); + if (ret < 0) + return ret; + + if (val == DISPLAY_ON && ambient_get_state()) + return DPMS_OFF; + + if (dpms_running_state != DPMS_SETTING_DONE) + return dpms_running_state; + + switch (val) { + case DISPLAY_ON: + return DPMS_ON; + case DISPLAY_STANDBY: + return DPMS_STANDBY; + case DISPLAY_SUSPEND: + return DPMS_SUSPEND; + case DISPLAY_OFF: + return DPMS_OFF; + default: + return -EINVAL; + } } } diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 06e101d..70de2fe 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -263,31 +263,30 @@ static int get_lcd_power(void) int ret; if (!display_dev || !display_dev->get_state) { - _E("There is no display device."); - return -ENOENT; - } - - ret = display_dev->get_state(&val); - if (ret < 0) - return ret; - - if (val == DISPLAY_ON && ambient_get_state()) - return DPMS_OFF; - - if (dpms_running_state != DPMS_SETTING_DONE) - return dpms_running_state; - - switch (val) { - case DISPLAY_ON: - return DPMS_ON; - case DISPLAY_STANDBY: - return DPMS_STANDBY; - case DISPLAY_SUSPEND: - return DPMS_SUSPEND; - case DISPLAY_OFF: - return DPMS_OFF; - default: - return -EINVAL; + return dpms_get_state(); + } else { + ret = display_dev->get_state(&val); + if (ret < 0) + return ret; + + if (val == DISPLAY_ON && ambient_get_state()) + return DPMS_OFF; + + if (dpms_running_state != DPMS_SETTING_DONE) + return dpms_running_state; + + switch (val) { + case DISPLAY_ON: + return DPMS_ON; + case DISPLAY_STANDBY: + return DPMS_STANDBY; + case DISPLAY_SUSPEND: + return DPMS_SUSPEND; + case DISPLAY_OFF: + return DPMS_OFF; + default: + return -EINVAL; + } } } diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c index 1705b63..f1b4d26 100644 --- a/src/display/display-dpms.c +++ b/src/display/display-dpms.c @@ -27,6 +27,8 @@ #include "core/log.h" #include "display/util.h" +#define DPMS_GET_TIMEOUT 10 /* milisecond */ + typedef struct { GSource gsource; GPollFD gfd; @@ -46,6 +48,10 @@ bool wm_is_ready; static bool dpms_connected; static GSource *wl_glib_data = NULL; +static GMainLoop *dpms_loop; +static GMainContext *dpms_context; +static bool dpms_get_state_done; + static void dpms_handle_set_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error) { _D("Dpms_state_cb set - mode:%u, error:%u", mode, error); @@ -56,6 +62,18 @@ static void dpms_handle_get_state(void *data, struct tizen_dpms_manager *tz_dpms { _D("Dpms_state_cb get - mode:%u, error:%u", mode, error); info->dpms_mode = mode; + + dpms_get_state_done = true; + if (g_main_loop_is_running(dpms_loop)) + g_main_loop_quit(dpms_loop); +} + +static gboolean dpms_loop_quit(void *data) +{ + if (g_main_loop_is_running(dpms_loop)) + g_main_loop_quit(dpms_loop); + + return G_SOURCE_REMOVE; } void disconnect_interface_with_dpms(void) @@ -90,6 +108,8 @@ void disconnect_interface_with_dpms(void) wl_glib_data = NULL; } + g_main_loop_unref(dpms_loop); + g_main_context_unref(dpms_context); dpms_connected = false; } @@ -339,11 +359,14 @@ GSource* wl_glib_client_init(void) goto err; } + dpms_context = g_main_context_new(); + dpms_loop = g_main_loop_new(dpms_context, false); + info->gfd.events = G_IO_IN | G_IO_ERR; info->gfd.revents = 0; g_source_add_poll(&info->gsource, &info->gfd); - g_source_attach(&info->gsource, NULL); + g_source_attach(&info->gsource, dpms_context); g_source_unref(&info->gsource); return &info->gsource; @@ -414,13 +437,38 @@ void dpms_set_state(int on) int dpms_get_state(void) { + GSource* timeout; + if (!dpms_is_available()) { _E("Dpms is not available."); return -EINVAL; } + // clear pending events + while (g_main_context_pending(dpms_context)) + g_main_context_iteration(dpms_context, true); + + dpms_get_state_done = false; + + // request for a dpms state to dpms server tizen_dpms_manager_get_dpms(info->tz_dpms_mng, info->wl_output); wl_display_flush(info->wl_disp); - return (int)info->dpms_mode; + // Set a response timeout + timeout = g_timeout_source_new(DPMS_GET_TIMEOUT); + g_source_set_callback(timeout, dpms_loop_quit, NULL, NULL); + g_source_attach(timeout, dpms_context); + + // Start dpms_loop, waiting for a event + // dpms_loop stops running when + // 1. dpms_handle_get_state is invoked (by dpms server as a dpms response) + // 2. dpms_loop_quit is invoked (by timeout event) + g_main_loop_run(dpms_loop); + g_source_destroy(timeout); + g_source_unref(timeout); + + if (dpms_get_state_done) + return (int)info->dpms_mode; + else + return -ETIMEDOUT; } -- 2.7.4 From f215cf3ba0d1d40fbfc94480364c6d3074be716a Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Thu, 21 Nov 2019 14:33:43 +0900 Subject: [PATCH 12/16] Remove default value at systemd services https://www.freedesktop.org/software/systemd/man/systemd.service.html - Behavior of notify is similar to exec; ... If NotifyAccess= is missing or set to none, it will be forcibly set to main. - WatchdogSec= ... If NotifyAccess= is not set, it will be implicitly set to main. Change-Id: I6392252b39036367dc56c62854219b4df73e0ad2 --- systemd/deviced.service | 1 - 1 file changed, 1 deletion(-) diff --git a/systemd/deviced.service b/systemd/deviced.service index 69d25d8..db4f5e0 100644 --- a/systemd/deviced.service +++ b/systemd/deviced.service @@ -14,7 +14,6 @@ ExecStart=/usr/bin/deviced Restart=always RestartSec=0 KillSignal=SIGUSR1 -NotifyAccess=main WatchdogSec=90s [Install] -- 2.7.4 From dbe5ab5359dd041b254d1c831265c03a84c3667e Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 26 Nov 2019 18:06:10 +0900 Subject: [PATCH 13/16] Exit mainloop after poweroff call to systemd Change-Id: I150d0638026632c655f2f7280edb77070f7ce034 Signed-off-by: Youngjae Cho --- src/power/power-handler.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 404b7e4..d53d1d8 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -197,6 +198,8 @@ static void poweroff_request_shutdown(void) NULL, NULL, POWEROFF_WAIT_SYSTEMD_MS); + + raise(SIGUSR1); } void poweroff_prepare(void) -- 2.7.4 From 0dd5b269d059c3cc5cf523e3f262b03362a3cb6a Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 25 Nov 2019 17:43:04 +0900 Subject: [PATCH 14/16] Change unref location of dpms_loop, dpms_context Change-Id: I7272dfc095424b4a7d3bf7cd4a65f2e714e5c5df Signed-off-by: Youngjae Cho --- plugins/iot/display/device-interface.c | 4 +++- plugins/mobile/display/device-interface.c | 4 +++- plugins/tv/display/device-interface.c | 4 +++- plugins/wearable/display/device-interface.c | 4 +++- src/display/display-dpms.c | 17 ++++++++++------- src/display/display-dpms.h | 3 +++ src/power/power-handler.c | 4 ---- 7 files changed, 25 insertions(+), 15 deletions(-) diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index abea4c3..0c4c453 100644 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -1023,7 +1023,9 @@ int exit_sysfs(void) backlight_update(); - disconnect_interface_with_dpms(); + g_main_loop_unref(dpms_loop); + g_main_context_unref(dpms_context); + ops = find_device("touchscreen"); if (!check_default(ops)) ops->start(NORMAL_MODE); diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index abea4c3..0c4c453 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -1023,7 +1023,9 @@ int exit_sysfs(void) backlight_update(); - disconnect_interface_with_dpms(); + g_main_loop_unref(dpms_loop); + g_main_context_unref(dpms_context); + ops = find_device("touchscreen"); if (!check_default(ops)) ops->start(NORMAL_MODE); diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index abea4c3..0c4c453 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -1023,7 +1023,9 @@ int exit_sysfs(void) backlight_update(); - disconnect_interface_with_dpms(); + g_main_loop_unref(dpms_loop); + g_main_context_unref(dpms_context); + ops = find_device("touchscreen"); if (!check_default(ops)) ops->start(NORMAL_MODE); diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 70de2fe..d1b536f 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -1024,7 +1024,9 @@ int exit_sysfs(void) backlight_update(); - disconnect_interface_with_dpms(); + g_main_loop_unref(dpms_loop); + g_main_context_unref(dpms_context); + ops = find_device("touchscreen"); if (!check_default(ops)) ops->start(NORMAL_MODE); diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c index f1b4d26..bba880c 100644 --- a/src/display/display-dpms.c +++ b/src/display/display-dpms.c @@ -24,6 +24,7 @@ #include #include #include + #include "core/log.h" #include "display/util.h" @@ -48,8 +49,8 @@ bool wm_is_ready; static bool dpms_connected; static GSource *wl_glib_data = NULL; -static GMainLoop *dpms_loop; -static GMainContext *dpms_context; +GMainLoop *dpms_loop; +GMainContext *dpms_context; static bool dpms_get_state_done; static void dpms_handle_set_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error) @@ -78,11 +79,16 @@ static gboolean dpms_loop_quit(void *data) void disconnect_interface_with_dpms(void) { + if (!dpms_connected) + return; + if (!info) { _E("Info is NULL."); return; } + dpms_connected = false; + if (info->tz_dpms_mng) { tizen_dpms_manager_destroy(info->tz_dpms_mng); info->tz_dpms_mng = NULL; @@ -105,12 +111,9 @@ void disconnect_interface_with_dpms(void) if (wl_glib_data) { g_source_destroy(wl_glib_data); + g_source_unref(wl_glib_data); wl_glib_data = NULL; } - - g_main_loop_unref(dpms_loop); - g_main_context_unref(dpms_context); - dpms_connected = false; } static const struct tizen_dpms_manager_listener dpms_listener = { @@ -403,7 +406,7 @@ bool connect_interface_with_dpms(void) return true; } -bool dpms_is_available(void) +static bool dpms_is_available(void) { /* Check window manager */ if (!wm_is_ready) { diff --git a/src/display/display-dpms.h b/src/display/display-dpms.h index 3b4e2ae..15b401d 100644 --- a/src/display/display-dpms.h +++ b/src/display/display-dpms.h @@ -25,4 +25,7 @@ bool connect_interface_with_dpms(void); void disconnect_interface_with_dpms(void); void dpms_set_state(int on); int dpms_get_state(void); + +extern GMainLoop *dpms_loop; +extern GMainContext *dpms_context; #endif /* __DISPLAY_DPMS_H__ */ diff --git a/src/power/power-handler.c b/src/power/power-handler.c index d53d1d8..1b0220f 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -23,10 +23,6 @@ #include #include #include -#include -#include -#include -#include #include #include #include -- 2.7.4 From 81b33f94e84e7564748666eb8926846b27847010 Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Mon, 9 Dec 2019 18:01:31 +0900 Subject: [PATCH 15/16] remove cmake warning Change-Id: I2e164564262605f91b1aa0c0454b257c33628be9 Signed-off-by: sanghyeok.oh --- CMakeLists.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d47d10f..d686a33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -220,20 +220,25 @@ ADD_DEFINITIONS("-DLIBPATH=\"${LIB_INSTALL_DIR}\"") ADD_DEFINITIONS("-DENABLE_DEVICED_DLOG") ADD_DEFINITIONS("-DENABLE_LIBDEVICED_DLOG") ADD_DEFINITIONS("-DENABLE_PM_LOG") + IF(ENGINEER_MODE STREQUAL on) -ADD_DEFINITIONS("-DENGINEER_MODE") + ADD_DEFINITIONS("-DENGINEER_MODE") ENDIF(ENGINEER_MODE STREQUAL on) + IF(BATTERY_MODULE STREQUAL on) -ADD_DEFINITIONS("-DBATTERY_MODULE") -ENDIF(ENGINEER_MODULE STREQUAL on) + ADD_DEFINITIONS("-DBATTERY_MODULE") +ENDIF(BATTERY_MODULE STREQUAL on) + IF(USE_ARM) ADD_DEFINITIONS("-DTARGET") ENDIF() + IF(USE_32BIT) ADD_DEFINITIONS("-DARCH_32BIT") ELSEIF(USE_64BIT) ADD_DEFINITIONS("-DARCH_64BIT") ENDIF() + ADD_DEFINITIONS("-DDEBUG") ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) -- 2.7.4 From 0bc077074b57e84f7dc49f944a33532998bce635 Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Fri, 20 Sep 2019 21:10:55 +0900 Subject: [PATCH 16/16] battery-monitor: initial module Change-Id: Ib353d1baf71816e7cdfe89e9b879759d05504f9f Signed-off-by: sanghyeok.oh --- CMakeLists.txt | 1 + conf/org.tizen.system.deviced.conf | 4 + plugins/wearable/display/CMakeLists.txt | 4 +- plugins/wearable/display/core.c | 4 + plugins/wearable/display/device-interface.c | 2 + src/battery-monitor/CMakeLists.txt | 18 ++ src/battery-monitor/battery-monitor.c | 466 ++++++++++++++++++++++++++++ src/battery-monitor/battery-monitor.h | 35 +++ 8 files changed, 532 insertions(+), 2 deletions(-) create mode 100644 src/battery-monitor/CMakeLists.txt create mode 100644 src/battery-monitor/battery-monitor.c create mode 100644 src/battery-monitor/battery-monitor.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d686a33..3721a6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -300,6 +300,7 @@ IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on) DESTINATION lib/systemd/system) ENDIF() +ADD_SUBDIRECTORY(src/battery-monitor) ADD_SUBDIRECTORY(src/shared) ADD_SUBDIRECTORY(src/libdeviced) ADD_SUBDIRECTORY(src/devicectl) diff --git a/conf/org.tizen.system.deviced.conf b/conf/org.tizen.system.deviced.conf index 5ef074e..aa4a653 100644 --- a/conf/org.tizen.system.deviced.conf +++ b/conf/org.tizen.system.deviced.conf @@ -15,6 +15,10 @@ send_interface="org.tizen.system.deviced.Battery"/> + + + + diff --git a/plugins/wearable/display/CMakeLists.txt b/plugins/wearable/display/CMakeLists.txt index 00290fc..0a4f329 100644 --- a/plugins/wearable/display/CMakeLists.txt +++ b/plugins/wearable/display/CMakeLists.txt @@ -6,7 +6,7 @@ SET(SRCS ${ALL_SRCS}) ADD_SOURCE(${CMAKE_SOURCE_DIR}/src/display COMMON_SRCS) SET(SRCS ${SRCS} ${COMMON_SRCS}) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/display) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/display ${CMAKE_SOURCE_DIR}/src/battery-monitor) INCLUDE(FindPkgConfig) pkg_check_modules(libpkgs REQUIRED @@ -26,7 +26,7 @@ ENDFOREACH(flag) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_LIB_CFLAGS}") ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${libpkgs_LDFLAGS} shared) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${libpkgs_LDFLAGS} shared batterymonitor) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES OUTPUT_NAME wearable-display) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index e328df8..41a2ce6 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -59,6 +59,7 @@ #include "dd-display.h" #include "display/display-dpms.h" #include "display-info.h" +#include "battery-monitor.h" #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -2050,6 +2051,9 @@ static int default_action(int timeout) states[pm_cur_state].name, last_timeout, diff); } + /* update status for batter monitor */ + update_bds_record(pm_cur_state); + switch (pm_cur_state) { case S_NORMAL: /* diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index d1b536f..9b5d656 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -42,6 +42,7 @@ #include "core.h" #include "device-node.h" #include "display/display-dpms.h" +#include "battery-monitor.h" #define SET_SUSPEND_TIME 0.5 @@ -599,6 +600,7 @@ static int set_brightness(int val) * Thus real brightness need to be calculated */ val = val * max / 100; + update_bds_brightness_record(val); _I("set brightness %d (default:%d)", val, default_brightness); device_notify(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, (void *)&val); diff --git a/src/battery-monitor/CMakeLists.txt b/src/battery-monitor/CMakeLists.txt new file mode 100644 index 0000000..9937f06 --- /dev/null +++ b/src/battery-monitor/CMakeLists.txt @@ -0,0 +1,18 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +FILE(GLOB SHARED_SRCS "*.c") + +INCLUDE(FindPkgConfig) +pkg_check_modules(libshared REQUIRED + glib-2.0 + gio-2.0 + gio-unix-2.0 + dlog) + +FOREACH(flag ${libshared_CFLAGS}) + SET(SHARED_LIB_CFLAGS "${SHARED_LIB_CFLAGS} ${flag}") +ENDFOREACH(flag) + +ADD_LIBRARY(batterymonitor STATIC ${SHARED_SRCS}) +TARGET_LINK_LIBRARIES(batterymonitor ${libshared_LDFLAGS} "-ldl") +SET_TARGET_PROPERTIES(batterymonitor PROPERTIES COMPILE_FLAGS "-fPIC") diff --git a/src/battery-monitor/battery-monitor.c b/src/battery-monitor/battery-monitor.c new file mode 100644 index 0000000..9ceff29 --- /dev/null +++ b/src/battery-monitor/battery-monitor.c @@ -0,0 +1,466 @@ +/* + * deviced + * + * Copyright (c) 2019 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. + */ + +#include +#include +#include + +#include "battery-monitor.h" + +#include "core/log.h" +#include "core/devices.h" +#include "core/common.h" +#include "display/core.h" + +#define DBUS_DEVICED "org.tizen.system.deviced" +#define DBUS_DEVICED_BM_PATH "/Org/Tizen/System/DeviceD/BatteryMonitor" +#define DBUS_DEVICED_BM_IFACE "org.tizen.system.deviced.BatteryMonitor" +#define DBUS_DEVICED_BM_MEMBER "GetBMData" + +/* battery-monitor interface */ +_battery_monitor_ops bm_ops; + +typedef enum { + B_LOW = 0, + B_MED, + B_HIGH, + B_UNKNOWN, +} brightness_level; + +static char *prev_appid; +static char *cur_appid; + +static enum state_t prev_lcd_state = S_LCDOFF; + +/* + * hash map for app_time_map_st1 + * key(appid) : (char *) + * val(elapsed time/ms) : (unsigned int *) + */ +GHashTable *ht_apptime; + +static bool bm_started = false; +static time_t bm_time_start; +static time_t bm_time_end; + +/* elapsed time per brightness level(milliseconds) */ +static unsigned int brightness_time[B_UNKNOWN]; +static brightness_level prev_brightness_level = B_UNKNOWN; + +#define timeval_to_ms(time) ((time.tv_sec * 1000) + (time.tv_usec / 1000)) +#define timeval_diff_ms(tend, tstart) (timeval_to_ms(tend) - timeval_to_ms(tstart)) + +/* monitoring time */ +#define bds_init_monitoring_time() (bm_time_start = bm_time_end = 0) +#define bds_set_start_time() (time(&bm_time_start)) +#define bds_set_end_time() (time(&bm_time_end)) + +static struct timeval bds_time_prev; +#define bds_timer_init() (bds_time_prev.tv_sec = bds_time_prev.tv_usec = 0) +#define bds_timer_start() (gettimeofday(&bds_time_prev, NULL)) + +/* dbus signal subscription id : AppStatusChange */ +guint dbus_sub_id; + +static void _init_bds_brightness_time() +{ + int i; + + for (i = 0; i < B_UNKNOWN; ++i) + brightness_time[i] = 0; +} + +static void _update_bds_brightness_time(unsigned long elapsed_ms) +{ + if (prev_brightness_level >= B_UNKNOWN) + return; + + _I("update brightness time %lu elapsed", elapsed_ms); + + brightness_time[prev_brightness_level] += elapsed_ms; +} + +static unsigned long bds_timer_get_elapsed_ms() +{ + struct timeval cur_time; + unsigned long ret; + + if (bds_time_prev.tv_sec == 0) { + bds_timer_start(); + return 0; + } + + gettimeofday(&cur_time, NULL); + + ret = timeval_diff_ms(cur_time, bds_time_prev); + + /* update prev bds time */ + bds_time_prev.tv_sec = cur_time.tv_sec; + bds_time_prev.tv_usec = cur_time.tv_usec; + + return ret; +} + +static void update_apptime(const char *appid, unsigned long elapsed) +{ + unsigned int *ptime; + + if (!appid) { + _E("wrong input %s %lu", appid, elapsed); + return ; + } + if (elapsed == 0) { + _D("elaped time is 0. No update"); + return ; + } + /* display core is initialized at first */ + if (!ht_apptime) { + _D("battery-monitor moulde is not initialized"); + return ; + } + + _I("update apptime. %lu elapsed", elapsed); + + ptime = g_hash_table_lookup(ht_apptime, appid); + if (ptime) { + *ptime += elapsed; + return ; + } + + ptime = (unsigned int*)malloc(sizeof(unsigned int)); + if (!ptime) { + _E("failed to alloc memory"); + return ; + } + + *ptime = elapsed; + + g_hash_table_insert(ht_apptime, g_strdup(appid), ptime); +} + +static void update_appid(void) +{ + g_free(prev_appid); + prev_appid = g_strdup(cur_appid); +} + +int update_bds_record(enum state_t cur_lcd_state) +{ + unsigned long elapsed = 0; + + if (!bm_started) { + prev_lcd_state = cur_lcd_state; + update_appid(); + + bds_set_start_time(); + bds_timer_start(); + bm_started = true; + + _I("battery monitor started"); + + return 0; + } + + elapsed = bds_timer_get_elapsed_ms(); + + /* no effect : prev state(lcd off) -> on or off */ + if (prev_lcd_state >= S_LCDOFF) { + prev_lcd_state = cur_lcd_state; + _D("LCD OFF State. prev(%d)->cur(%d)", prev_lcd_state, cur_lcd_state); + + update_appid(); + _D("foreground app has changed %s->%s", prev_appid, cur_appid); + + return 0; + } + + if (prev_appid) + update_apptime(prev_appid, elapsed); + + _update_bds_brightness_time(elapsed); + + /* update previous state */ + prev_lcd_state = cur_lcd_state; + + update_appid(); + + return 0; +} + +static brightness_level get_brightness_level(unsigned int val) +{ + if (val > 100) + return B_UNKNOWN; + + val = val / 33; + if (val > 2) + val = 2; + + return (brightness_level)val; +} + +int update_bds_brightness_record(unsigned int val) +{ + brightness_level level = get_brightness_level(val); + + if (level == B_UNKNOWN) + return -1; + + _I("update brightness %u %d", val, (int)level); + + update_bds_record(prev_lcd_state); + + /* update previous state */ + prev_brightness_level = level; + + return 0; +} + +static void _set_current_appid(const char *appid, int foreground) +{ + if (!appid) + return; + + /* appid is not changed */ + if (cur_appid && strcmp(cur_appid, appid) == 0) + return; + + if (!foreground) { + /* if bg notification is different with cur_appid, ignore */ + if (cur_appid && strcmp(cur_appid, appid) != 0) { + _D("different appid has changed to bg. ignore"); + return; + } + + /* if bg, set null */ + appid = NULL; + } + + g_free(cur_appid); + cur_appid = g_strdup(appid); + + update_bds_record(prev_lcd_state); +} + +static void _builder_add_atm_data(GVariantBuilder *atm_builder) +{ + GHashTableIter iter; + gpointer key, value; + + g_hash_table_iter_init (&iter, ht_apptime); + while (g_hash_table_iter_next(&iter, &key, &value)) { + g_variant_builder_add(atm_builder, "(su)", (const char *)key, (*(unsigned int*)value)); + _D("value added %s, %u", (const char *)key, (*(unsigned int*)value)); + } + g_hash_table_remove_all(ht_apptime); +} + +static GVariant *_convert_bds_data_to_gvariant(void) +{ + GVariant *out_variant = NULL; + GVariantBuilder *bds_builder = NULL; + GVariantBuilder *atm_builder = NULL; + gint64 t_start; + gint64 t_end; + + t_start = bm_time_start; + t_end = bm_time_end; + + /* convert bm_display_st data to gvariant */ + bds_builder = g_variant_builder_new(G_VARIANT_TYPE("a(uuuxxa(su))")); + + for (int i = 0 ; i < 1; ++i) { + /* convert app_time_map_st1 to gvariant array */ + atm_builder = g_variant_builder_new(G_VARIANT_TYPE("a(su)")); + _builder_add_atm_data(atm_builder); + + g_variant_builder_add(bds_builder, "(uuuxxa(su))", + brightness_time[B_HIGH], + brightness_time[B_LOW], + brightness_time[B_MED], + t_start, + t_end, + atm_builder); + g_variant_builder_unref(atm_builder); + } + + out_variant = g_variant_new("(a(uuuxxa(su)))", bds_builder); + g_variant_builder_unref(bds_builder); + + _init_bds_brightness_time(); + + return out_variant; +} + +static void _init_bm_ops(void) +{ + bm_ops.update_bds_record = update_bds_record; +} + +static GVariant *dbus_get_bm_data(GDBusConnection *conn, + const gchar *sender, + const gchar *path, + const gchar *iface, + const gchar *name, + GVariant *param, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + GVariant *reply; + gchar *ret; + + update_bds_record(prev_lcd_state); + + bds_set_end_time(); + reply = _convert_bds_data_to_gvariant(); + bds_set_start_time(); + + ret = g_variant_print(reply, true); + _I("Reply battery monitor data:%s:%s", g_variant_get_type_string(reply), ret); + g_free(ret); + + return reply; +} + +/* dbus signal handler : AppStatusChange */ +static void _dbus_cb_AppStatusChange(GDBusConnection *conn, + const gchar *sender, + const gchar *path, + const gchar *iface, + const gchar *name, + GVariant *param, + gpointer data) +{ + int pid; + char *appid; + char *status; + + /* (issss) : pid, appid, pkgid, status, type */ + g_variant_get(param, "(issss)", &pid, &appid, NULL, &status, NULL); + + _I("pid:%d, appid:%s, status:%s", pid, appid, status); + + _set_current_appid(appid, strcmp(status, "fg") == 0); + + g_free(appid); + g_free(status); +} + +static const dbus_method_s bm_dbus_methods[] = { + {"GetBMData", NULL, "a(uuuxxa(su))", dbus_get_bm_data}, +}; + +static const dbus_interface_u bm_dbus_interface = { + .oh = NULL, + .name = DBUS_DEVICED_BM_IFACE, + .methods = bm_dbus_methods, + .nr_methods = ARRAY_SIZE(bm_dbus_methods), +}; + +static void bm_data_init(void) +{ + if (ht_apptime) { + g_hash_table_destroy(ht_apptime); + ht_apptime = NULL; + } + + bm_started = false; + + g_free(cur_appid); + cur_appid = NULL; + + g_free(prev_appid); + prev_appid = NULL; + + bds_timer_init(); + bds_init_monitoring_time(); + _init_bds_brightness_time(); +} + +static int bm_probe(void *data) +{ + _init_bm_ops(); + + return 0; +} + +static void _ht_key_destroy(gpointer data) +{ + char *pdata = (char *)data; + + if (!pdata) + return; + + g_free(pdata); +} + +static void _ht_val_destroy(gpointer data) +{ + unsigned int *pdata = (unsigned int *)data; + + if (!pdata) + return; + + free(pdata); +} + +static void bm_init(void *data) +{ + int ret; + + ht_apptime = g_hash_table_new_full(g_str_hash, g_str_equal, _ht_key_destroy, _ht_val_destroy); + if (!ht_apptime) + _E("Failed to init hash table"); + + ret = dbus_handle_add_dbus_object(NULL, DBUS_DEVICED_BM_PATH, &bm_dbus_interface); + if (ret < 0) + _E("Failed to init dbus method: %d", ret); + + dbus_sub_id = subscribe_dbus_signal(NULL, + "/Org/Tizen/Aul/AppStatus", + "org.tizen.aul.AppStatus", + "AppStatusChange", + _dbus_cb_AppStatusChange, + NULL, NULL); + if (dbus_sub_id <= 0) + _E("Failed to register signal handler: %d", dbus_sub_id); +} + +static void bm_exit(void *data) +{ + int ret; + + ret = dbus_handle_unregister_dbus_object(NULL, DBUS_DEVICED_BM_PATH); + if (ret < 0) + _E("Failed to unregister dbus object: %d", ret); + + if (dbus_sub_id > 0) + unsubscribe_dbus_signal(NULL, dbus_sub_id); + dbus_sub_id = 0; + + bm_data_init(); +} + +static const struct device_ops battery_monitor_ops = { + DECLARE_NAME_LEN("battery-monitor"), + .probe = bm_probe, + .init = bm_init, + .exit = bm_exit, +}; + +DEVICE_OPS_REGISTER(&battery_monitor_ops) diff --git a/src/battery-monitor/battery-monitor.h b/src/battery-monitor/battery-monitor.h new file mode 100644 index 0000000..25dde1e --- /dev/null +++ b/src/battery-monitor/battery-monitor.h @@ -0,0 +1,35 @@ +/* + * deviced + * + * Copyright (c) 2019 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 __BATTERY_MONITOR_H__ +#define __BATTERY_MONITOR_H__ + +#include "display/core.h" + +typedef struct { + int (*update_bds_record)(enum state_t lcd_state); + int (*update_bds_brightness_record)(unsigned int val); +} _battery_monitor_ops; + +extern _battery_monitor_ops bm_ops; + +int update_bds_record(enum state_t lcd_state); +int update_bds_brightness_record(unsigned int val); + +#endif /* __BATTERY_MONITOR_H__ */ \ No newline at end of file -- 2.7.4