From 498493b3915e95fa7f78cc26914ffa1dd8b31646 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 11 Jun 2019 18:11:14 +0900 Subject: [PATCH 01/16] Update battery.health_s in check_health_status battery.health_s is not synchronized with battery.health. So, update battery.health_s in check_health_status to synchronize them. Change-Id: I779b1c91e202198be62ef858d2fa774a067a2c7d Signed-off-by: lokilee73 --- src/battery/power-supply.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index c4eb7c8..2b092d6 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -636,6 +636,9 @@ static void check_health_status(const char *env_value) battery.health = HEALTH_GOOD; return; } + + snprintf(battery.health_s, sizeof(battery.health_s), "%s", env_value); + if (strncmp(env_value, OVERHEAT_NAME, sizeof(OVERHEAT_NAME)) == 0) battery.health = HEALTH_HIGH; -- 2.7.4 From b82336785cdd7abda7212b930c72e1521960bed5 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 14 Jun 2019 19:35:24 +0900 Subject: [PATCH 02/16] Initialize dpms_connected in disconnect_interface_with_dpms to protect crash Display can be controlled by devicectl command. ex) devicectl display stop/start After disconnect_interface_with_dpms is called by devicectl command, LCD_ON can be requested via dbus-send. At this time, dpms related functions and variables are initialized. So, crash can occur. Change-Id: I9fdbc0c27e612bbdc9d11309f2a0be6102112d66 Signed-off-by: lokilee73 --- src/display/display-dpms.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) mode change 100644 => 100755 src/display/display-dpms.c diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c old mode 100644 new mode 100755 index 37f5d1b..54127de --- a/src/display/display-dpms.c +++ b/src/display/display-dpms.c @@ -31,6 +31,7 @@ struct wl_output *wl_out; struct tizen_dpms_manager *tz_dpms_mng = NULL; int lcd_state = -1; bool wm_is_ready; +static bool dpms_connected; bool check_wm_ready(void) { @@ -60,6 +61,8 @@ void disconnect_interface_with_dpms(void) wl_display_disconnect(display); display = NULL; } + + dpms_connected = false; } static void dpms_handle_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error) @@ -141,8 +144,6 @@ error: bool dpms_is_available(void) { - static bool dpms_connected; - /* Check window manager */ if (!wm_is_ready) { _E("Window manager is not ready"); -- 2.7.4 From 3ced9b5f3d7f92aa3cf44cdafac51d334907c85b Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 17 Jun 2019 13:33:31 +0900 Subject: [PATCH 03/16] Temporarily allow org.tizen.system.deviced.Board in dbus policy Change-Id: I5ce697624c93a03bc8ae9af5184ec2456c21ee7a Signed-off-by: Hyotaek Shim --- conf/org.tizen.system.deviced.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/org.tizen.system.deviced.conf b/conf/org.tizen.system.deviced.conf index 709c909..58737c0 100644 --- a/conf/org.tizen.system.deviced.conf +++ b/conf/org.tizen.system.deviced.conf @@ -59,5 +59,6 @@ + -- 2.7.4 From 58569a2be3e8a7ac40317160b0700f5a0dc535ac Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 20 Jun 2019 11:46:34 +0900 Subject: [PATCH 04/16] Add display_staydim_check for commonly used code Change-Id: Ib3a5f23b2a93f48eafecb9fe5f1f7a43f19f6bf2 Signed-off-by: lokilee73 --- plugins/iot/display/device-interface.c | 15 +++++++++++---- plugins/mobile/display/device-interface.c | 15 +++++++++++---- plugins/tv/display/device-interface.c | 15 +++++++++++---- plugins/wearable/display/device-interface.c | 15 +++++++++++---- 4 files changed, 44 insertions(+), 16 deletions(-) mode change 100755 => 100644 plugins/iot/display/device-interface.c mode change 100755 => 100644 plugins/mobile/display/device-interface.c mode change 100755 => 100644 plugins/tv/display/device-interface.c mode change 100755 => 100644 plugins/wearable/display/device-interface.c diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c old mode 100755 new mode 100644 index c4c9c7d..764fb47 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -187,14 +187,21 @@ static int get_lcd_power(void) return dpms_get_state(); } +bool display_dimstay_check(void) +{ + if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) + return true; + + return false; +} + void change_brightness(int start, int end, int step) { int diff, val; int ret = -1; int prev; - if ((pm_status_flag & PWRSV_FLAG) && - !(pm_status_flag & BRTCH_FLAG)) + if (display_dimstay_check()) return; ret = backlight_ops.get_brightness(&prev); @@ -315,7 +322,7 @@ static int custom_backlight_update(void) custom_brightness > PM_MAX_BRIGHTNESS) return -EINVAL; - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) { + if (display_dimstay_check()) { ret = backlight_dim(); } else { _I("Custom brightness(%d) restored.", custom_brightness); @@ -343,7 +350,7 @@ static int backlight_update(void) _I("Custom brightness mode. brt no updated."); return 0; } - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) + if (display_dimstay_check()) ret = backlight_dim(); else ret = bl_brt(default_brightness, 0); diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c old mode 100755 new mode 100644 index c4c9c7d..764fb47 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -187,14 +187,21 @@ static int get_lcd_power(void) return dpms_get_state(); } +bool display_dimstay_check(void) +{ + if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) + return true; + + return false; +} + void change_brightness(int start, int end, int step) { int diff, val; int ret = -1; int prev; - if ((pm_status_flag & PWRSV_FLAG) && - !(pm_status_flag & BRTCH_FLAG)) + if (display_dimstay_check()) return; ret = backlight_ops.get_brightness(&prev); @@ -315,7 +322,7 @@ static int custom_backlight_update(void) custom_brightness > PM_MAX_BRIGHTNESS) return -EINVAL; - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) { + if (display_dimstay_check()) { ret = backlight_dim(); } else { _I("Custom brightness(%d) restored.", custom_brightness); @@ -343,7 +350,7 @@ static int backlight_update(void) _I("Custom brightness mode. brt no updated."); return 0; } - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) + if (display_dimstay_check()) ret = backlight_dim(); else ret = bl_brt(default_brightness, 0); diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c old mode 100755 new mode 100644 index c4c9c7d..764fb47 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -187,14 +187,21 @@ static int get_lcd_power(void) return dpms_get_state(); } +bool display_dimstay_check(void) +{ + if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) + return true; + + return false; +} + void change_brightness(int start, int end, int step) { int diff, val; int ret = -1; int prev; - if ((pm_status_flag & PWRSV_FLAG) && - !(pm_status_flag & BRTCH_FLAG)) + if (display_dimstay_check()) return; ret = backlight_ops.get_brightness(&prev); @@ -315,7 +322,7 @@ static int custom_backlight_update(void) custom_brightness > PM_MAX_BRIGHTNESS) return -EINVAL; - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) { + if (display_dimstay_check()) { ret = backlight_dim(); } else { _I("Custom brightness(%d) restored.", custom_brightness); @@ -343,7 +350,7 @@ static int backlight_update(void) _I("Custom brightness mode. brt no updated."); return 0; } - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) + if (display_dimstay_check()) ret = backlight_dim(); else ret = bl_brt(default_brightness, 0); diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c old mode 100755 new mode 100644 index 69fd7d5..5f4717e --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -187,14 +187,21 @@ static int get_lcd_power(void) return dpms_get_state(); } +bool display_dimstay_check(void) +{ + if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) + return true; + + return false; +} + void change_brightness(int start, int end, int step) { int diff, val; int ret = -1; int prev; - if ((pm_status_flag & PWRSV_FLAG) && - !(pm_status_flag & BRTCH_FLAG)) + if (display_dimstay_check()) return; ret = backlight_ops.get_brightness(&prev); @@ -315,7 +322,7 @@ static int custom_backlight_update(void) custom_brightness > PM_MAX_BRIGHTNESS) return -EINVAL; - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) { + if (display_dimstay_check()) { ret = backlight_dim(); } else { _I("Custom brightness(%d) restored.", custom_brightness); @@ -343,7 +350,7 @@ static int backlight_update(void) _I("Custom brightness mode. brt no updated."); return 0; } - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) + if (display_dimstay_check()) ret = backlight_dim(); else ret = bl_brt(default_brightness, 0); -- 2.7.4 From 38fd26bb86e677e7c428d5ad771ad3647d4d9174 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 30 May 2019 21:13:52 +0900 Subject: [PATCH 05/16] Add battery_health_changed to keep dim in case of bad battery health LCD dim has to be kept for bad battery health like HEALTH_LOW, HEALTH_HIGH, HEALTH_OVP. Battery_health_changed adds DIMSTAY_FLAG to pm_status_flag. It protects LCD change from dim to LCD_OFF by request of other applications or daemons. ex) lockstate, changestate in dbus-send Change-Id: I544259e07eb36967df11c1d709508651c214f079 Signed-off-by: lokilee73 --- plugins/mobile/display/core.c | 23 +++++++++++++++++++++++ plugins/wearable/display/core.c | 23 +++++++++++++++++++++++ src/display/core.h | 3 ++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index fe4d69b..f07c7fd 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -58,6 +58,7 @@ #include "dd-display.h" #include "display/display-dpms.h" #include "battery/battery.h" +#include "battery/power-supply.h" #define PM_STATE_LOG_FILE tzplatform_mkpath(TZ_SYS_ALLLOGS, "pm_state.log") #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -2105,6 +2106,26 @@ static int process_foreground(void *data) return 0; } +static int battery_health_changed(void *data) +{ + int health = DATA_VALUE_INT(data); + + _I("battery health change %d", health); + + if (health == HEALTH_GOOD) { + pm_status_flag &= ~BATTERY_FLAG; + pm_status_flag &= ~DIMSTAY_FLAG; + } else if (health == HEALTH_LOW || health == HEALTH_HIGH || health == HEALTH_OVP) { + pm_status_flag |= BATTERY_FLAG; + pm_status_flag |= DIMSTAY_FLAG; + } + + if (backlight_ops.get_lcd_power() == DPMS_ON) + backlight_ops.update(); + + return 0; +} + static int display_load_config(struct parse_result *result, void *user_data) { struct display_config *c = user_data; @@ -2246,6 +2267,7 @@ static void display_init(void *data) register_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); register_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); register_notifier(DEVICE_NOTIFIER_POWEROFF, device_poweroff); + register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); for (i = INIT_SETTING; i < INIT_END; i++) { switch (i) { @@ -2363,6 +2385,7 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); unregister_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); unregister_notifier(DEVICE_NOTIFIER_POWEROFF, device_poweroff); + unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); exit_input(); break; diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 4823071..776ccf6 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -58,6 +58,7 @@ #include "dd-display.h" #include "display/display-dpms.h" #include "battery/battery.h" +#include "battery/power-supply.h" #define PM_STATE_LOG_FILE tzplatform_mkpath(TZ_SYS_ALLLOGS, "pm_state.log") #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -2093,6 +2094,26 @@ static int process_background(void *data) return 0; } +static int battery_health_changed(void *data) +{ + int health = DATA_VALUE_INT(data); + + _I("battery health change %d", health); + + if (health == HEALTH_GOOD) { + pm_status_flag &= ~BATTERY_FLAG; + pm_status_flag &= ~DIMSTAY_FLAG; + } else if (health == HEALTH_LOW || health == HEALTH_HIGH || health == HEALTH_OVP) { + pm_status_flag |= BATTERY_FLAG; + pm_status_flag |= DIMSTAY_FLAG; + } + + if (backlight_ops.get_lcd_power() == DPMS_ON) + backlight_ops.update(); + + return 0; +} + static int process_foreground(void *data) { pid_t pid; @@ -2250,6 +2271,7 @@ static void display_init(void *data) register_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); register_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); register_notifier(DEVICE_NOTIFIER_POWEROFF, device_poweroff); + register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); for (i = INIT_SETTING; i < INIT_END; i++) { switch (i) { @@ -2367,6 +2389,7 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); unregister_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); unregister_notifier(DEVICE_NOTIFIER_POWEROFF, device_poweroff); + unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); exit_input(); break; diff --git a/src/display/core.h b/src/display/core.h index eb2b1b4..bd83cdc 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -39,7 +39,8 @@ #define PWRSV_FLAG 0x00000400 #define BRTCH_FLAG 0x00002000 #define PWROFF_FLAG 0x00004000 -#define DIMSTAY_FLAG 0x00008000 +#define DIMSTAY_FLAG 0x00008000 +#define BATTERY_FLAG 0x00020000 #define DEFAULT_NORMAL_TIMEOUT 30 -- 2.7.4 From 6a5ed5f88298b9ba95e238bfc5ff3506b8de73c0 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 25 Jun 2019 17:11:24 +0900 Subject: [PATCH 06/16] Change dpms_get_state to use HAL for lcd get state Change-Id: I465f01f4e8b2f4119fc8b2828ea2a909305d4bd2 Signed-off-by: lokilee73 --- plugins/iot/display/device-interface.c | 21 +++++++++++++++++---- plugins/mobile/display/device-interface.c | 21 +++++++++++++++++---- plugins/tv/display/device-interface.c | 21 +++++++++++++++++---- plugins/wearable/display/device-interface.c | 21 +++++++++++++++++---- 4 files changed, 68 insertions(+), 16 deletions(-) diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index 764fb47..d652988 100644 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -176,15 +176,28 @@ out: static int get_lcd_power(void) { + enum display_state val; + int ret; + if (ambient_get_state()) return DPMS_OFF; - if (!dpms_is_available()) { - _E("Dpms is not available."); + ret = display_dev->get_state(&val); + if (ret < 0) + return ret; + + 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(); } bool display_dimstay_check(void) diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 764fb47..d652988 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -176,15 +176,28 @@ out: static int get_lcd_power(void) { + enum display_state val; + int ret; + if (ambient_get_state()) return DPMS_OFF; - if (!dpms_is_available()) { - _E("Dpms is not available."); + ret = display_dev->get_state(&val); + if (ret < 0) + return ret; + + 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(); } bool display_dimstay_check(void) diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 764fb47..d652988 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -176,15 +176,28 @@ out: static int get_lcd_power(void) { + enum display_state val; + int ret; + if (ambient_get_state()) return DPMS_OFF; - if (!dpms_is_available()) { - _E("Dpms is not available."); + ret = display_dev->get_state(&val); + if (ret < 0) + return ret; + + 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(); } bool display_dimstay_check(void) diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 5f4717e..6aa4d48 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -176,15 +176,28 @@ out: static int get_lcd_power(void) { + enum display_state val; + int ret; + if (ambient_get_state()) return DPMS_OFF; - if (!dpms_is_available()) { - _E("Dpms is not available."); + ret = display_dev->get_state(&val); + if (ret < 0) + return ret; + + 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(); } bool display_dimstay_check(void) -- 2.7.4 From dcb52dce1e081e63ca35484835bdcec9bb35d599 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Tue, 25 Jun 2019 11:51:39 +0900 Subject: [PATCH 07/16] Add display(dpms) reply handling and retry Change-Id: I2a1c8dd3646c6b215b1c95c3fb53e5cf07561136 Signed-off-by: Hyotaek Shim Signed-off-by: lokilee73 Signed-off-by: Hyotaek Shim --- src/display/display-dpms.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) mode change 100755 => 100644 src/display/display-dpms.c diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c old mode 100755 new mode 100644 index 54127de..5a0220e --- a/src/display/display-dpms.c +++ b/src/display/display-dpms.c @@ -27,11 +27,13 @@ #include struct wl_display *display; +static struct wl_event_queue *queue; struct wl_output *wl_out; struct tizen_dpms_manager *tz_dpms_mng = NULL; int lcd_state = -1; bool wm_is_ready; static bool dpms_connected; +static int dpms_retry; bool check_wm_ready(void) { @@ -69,6 +71,7 @@ static void dpms_handle_state(void *data, struct tizen_dpms_manager *tz_dpms, ui { _D("dpms_state_cb - mode:%d, error:%d", mode, error); lcd_state = mode; + dpms_retry = 0; } static const struct tizen_dpms_manager_listener dpms_listener = { @@ -123,8 +126,19 @@ bool connect_interface_with_dpms(void) goto error; } + queue = wl_display_create_queue(display); + if (queue == NULL) { + printf(" failed wl_display_create_queue\n"); + goto error; + } + + wl_proxy_set_queue((struct wl_proxy *)display, queue); + wl_proxy_set_queue((struct wl_proxy *)registry, queue); + wl_registry_add_listener(registry, ®istry_listener, NULL); - wl_display_roundtrip(display); + + wl_display_dispatch_queue(display, queue); + wl_display_roundtrip_queue(display, queue); if (!wl_out || !tz_dpms_mng) { _E("Roundtrip failed."); @@ -161,14 +175,26 @@ bool dpms_is_available(void) void dpms_set_state(int on) { + dpms_retry = 1; + tizen_dpms_manager_set_dpms(tz_dpms_mng, wl_out, on); wl_display_roundtrip(display); + + while (dpms_retry) { + wl_display_dispatch_queue(display, queue); + } } int dpms_get_state(void) { + dpms_retry = 1; + tizen_dpms_manager_get_dpms(tz_dpms_mng, wl_out); wl_display_roundtrip(display); + while (dpms_retry) { + wl_display_dispatch_queue(display, queue); + } + return lcd_state; } -- 2.7.4 From 948b8c053fba45df77a293f1b29c52dc48c38031 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Tue, 25 Jun 2019 17:35:00 +0900 Subject: [PATCH 08/16] Fix build warning Change-Id: Ieb07f2399a87bba41c1f519791cb7172aa8f7764 --- src/usbhost/usb-host.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index 0e419b7..d3d46c2 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -455,7 +455,6 @@ static GVariant *get_device_list(GDBusConnection *conn, GVariant *gvar = NULL; dd_list *elem; struct usbhost_device *usbhost; - const char *str; int baseclass; GVariantBuilder *builder = NULL; const char *error = NULL; -- 2.7.4 From c229e2723ee6f442c8de4007bda994253cfa83d8 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 27 Jun 2019 13:48:23 +0900 Subject: [PATCH 09/16] Add protection code to prevent crash If there are not HAL for display_dev->get_state, crash occurs. So, add protection code for it. Change-Id: Ibe14f9dfa049dfbe3fd7f7cac1ad4b0cfc608ecf Signed-off-by: lokilee73 --- plugins/iot/display/device-interface.c | 5 +++++ plugins/mobile/display/device-interface.c | 5 +++++ plugins/tv/display/device-interface.c | 5 +++++ plugins/wearable/display/device-interface.c | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index d652988..e92582e 100644 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -182,6 +182,11 @@ static int get_lcd_power(void) if (ambient_get_state()) return DPMS_OFF; + 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; diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index d652988..e92582e 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -182,6 +182,11 @@ static int get_lcd_power(void) if (ambient_get_state()) return DPMS_OFF; + 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; diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index d652988..e92582e 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -182,6 +182,11 @@ static int get_lcd_power(void) if (ambient_get_state()) return DPMS_OFF; + 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; diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 6aa4d48..44d5f90 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -182,6 +182,11 @@ static int get_lcd_power(void) if (ambient_get_state()) return DPMS_OFF; + 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; -- 2.7.4 From 81ca7e5c0dc85ff98766ae074db01e15d3f1de36 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Fri, 28 Jun 2019 10:47:45 +0900 Subject: [PATCH 10/16] Add information about the relationship between unit dependencies Change-Id: Ia6f196c854933e5323ef6e7f4011541bd42494c1 --- systemd/deviced.service | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/systemd/deviced.service b/systemd/deviced.service index 3a286d9..69d25d8 100644 --- a/systemd/deviced.service +++ b/systemd/deviced.service @@ -1,6 +1,11 @@ [Unit] Description=System device daemon +# Caution: never uncomment belwo "Wants=" and "After=" entries. +# Just information, deviced internally wait for /run/.wm_ready +# Wants=display-manager.service +# After=display-manager.service + [Service] Type=notify SmackProcessLabel=System::Privileged -- 2.7.4 From 165cba04a67189aa95c78374ea3be355dce70c74 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 27 Jun 2019 20:50:32 +0900 Subject: [PATCH 11/16] Change function names and add lcd_on_procedure for changed ambient mode 1. change function names for unification ex) start_clock -> ambient_start_clock end_clock -> ambient_end_clock 2. add lcd_on_procedure for changed ambient mode Change-Id: I740ea105e41ef1199e40a0f9db70b3ba675df848 Signed-off-by: lokilee73 --- src/display/ambient-mode.c | 18 ++++++++++++------ src/display/core.h | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index b15fd56..f07a34a 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -65,14 +65,20 @@ int ambient_get_state(void) static void ambient_set_condition(keynode_t *key_nodes, void *data) { - int state; + int state, val; if (key_nodes == NULL) { _E("Wrong parameter, key_nodes is null."); return; } - ambient_condition = vconf_keynode_get_bool(key_nodes); + val = vconf_keynode_get_bool(key_nodes); + if (val != ambient_condition) { + if (backlight_ops.get_lcd_power() != DPMS_ON) + lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); + } + + ambient_condition = val; _I("Ambient mode condition is %d.", ambient_condition); state = (ambient_condition == 0 ? 0 : 1); @@ -130,7 +136,7 @@ void ambient_check_invalid_state(pid_t pid) backlight_ops.off(NORMAL_MODE); } -static void start_clock(void) +static void ambient_start_clock(void) { if (pm_cur_state == S_NORMAL || pm_cur_state == S_LCDDIM || @@ -142,7 +148,7 @@ static void start_clock(void) AMBIENT_CLOCK_WAITING_TIME); } -static void end_clock(pid_t pid) +static void ambient_end_clock(pid_t pid) { if (pm_cur_state == S_NORMAL || pm_cur_state == S_LCDDIM || @@ -170,9 +176,9 @@ int ambient_set_screen(char *screen, pid_t pid) return -EINVAL; if (!strncmp(screen, CLOCK_START, strlen(CLOCK_START))) - start_clock(); + ambient_start_clock(); else if (!strncmp(screen, CLOCK_END, strlen(CLOCK_END))) - end_clock(pid); + ambient_end_clock(pid); return 0; } diff --git a/src/display/core.h b/src/display/core.h index bd83cdc..3f656eb 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -193,6 +193,7 @@ int custom_lcdon(int timeout); void set_stay_touchscreen_off(int val); void set_lcd_paneloff_mode(int val); void lcd_on_direct(enum device_flags flags); +void lcd_on_procedure(int state, enum device_flags flag); void lcd_off_procedure(enum device_flags flag); int check_holdkey_block(enum state_t state); bool touch_event_blocked(void); -- 2.7.4 From 1573e8d1cbcc97e0cd2be348264864da001f14fd Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 2 Jul 2019 21:57:11 +0900 Subject: [PATCH 12/16] Apply changes for ambient mode 1. add ambient_lcdoff_signal_handler for signal from clock-viewer 2. change broadcasted signal from integer to string ex) 0, 1 -> ALPMOff, ALPMOn 3. move ambient_check_invalid_state to del_state_cond 4. add lcd_direct_control for lcd control Change-Id: Ice5f37124ad90f49ea21b618b99dade6901b8686 Signed-off-by: lokilee73 --- plugins/wearable/display/core.c | 26 ++++++++++++-- src/display/ambient-mode.c | 79 ++++++++++++++++++++++++++++++++++------- src/display/core.h | 2 ++ src/display/poll.h | 2 +- 4 files changed, 92 insertions(+), 17 deletions(-) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 776ccf6..2c171f6 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -383,6 +383,26 @@ bool touch_event_blocked(void) return touch_blocked; } +void lcd_direct_control(enum dpms_state state, int flags) +{ + const struct device_ops *ops = NULL; + dd_list *l = NULL; + + switch (state) { + case DPMS_ON: + DD_LIST_FOREACH(lcdon_ops, l, ops) + ops->start(flags); + break; + case DPMS_OFF: + DD_LIST_FOREACH(lcdon_ops, l, ops) + ops->stop(flags); + break; + default: + _E("state is wrong value %d", state); + break; + } +} + void lcd_on_procedure(int state, enum device_flags flag) { dd_list *l = NULL; @@ -648,6 +668,9 @@ static void del_state_cond(void *data, enum state_t state) pid = (pid_t)((intptr_t)data); _I("Delete process(%d)'s prohibit dim condition by timeout.", pid); + if (pid == INTERNAL_LOCK_AMBIENT) + ambient_check_invalid_state(pid); + tmp = find_node(state, pid); del_node(state, tmp); get_pname(pid, pname); @@ -1027,9 +1050,6 @@ static void proc_condition_unlock(PMMsg *data) if (state == S_LCDOFF) set_process_active(FALSE, pid); - if (ambient_get_state()) - ambient_check_invalid_state(pid); - _SD("[%s] Unlocked by pid=%d process=%s\n", states[state].name, pid, pname); set_unlock_time(pname, state); diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index f07a34a..4223dc5 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -30,7 +30,10 @@ #define ON "on" #define OFF "off" -#define SIGNAL_AMBIENT_MODE "AmbientMode" +#define SIGNAL_ALPMLCDOFF "ALPMLCDOff" +#define SIGNAL_ALPM_ON "ALPMOn" +#define SIGNAL_ALPM_OFF "ALPMOff" + #define CLOCK_START "clockstart" #define CLOCK_END "clockend" #define TIMEOUT_NONE (-1) @@ -44,13 +47,15 @@ static unsigned int update_count; void broadcast_ambient_state(int state) { int ret; + char *signal; + signal = (state == true ? SIGNAL_ALPM_ON : SIGNAL_ALPM_OFF); ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, - SIGNAL_AMBIENT_MODE, - g_variant_new("(i)", (state == 0 ? 0 : 1))); + signal, + NULL); if (ret < 0) - _E("Failed to send dbus signal(%s)", SIGNAL_AMBIENT_MODE); + _E("Failed to send dbus signal(%s)", signal); } int ambient_get_condition(void) @@ -96,7 +101,17 @@ int ambient_set_state(int on) update_count = 0; - if (!on) + /** + * When display is turned off before going to AOD, Generally pm receives + * clock signal or ALPMLCDOFF signal and decides to go to AOD or not. + * But a specific case, the signal is not received. + * So at that time deviced should turn off display to match the pair. + */ + if (on) { + if (disp_plgn.pm_lock_internal) + disp_plgn.pm_lock_internal(INTERNAL_LOCK_AMBIENT, + LCD_OFF, STAY_CUR_STATE, AMBIENT_CLOCK_WAITING_TIME); + } else ambient_pid = 0; _D("AMBIENT is %s.", (on ? ON : OFF)); @@ -113,9 +128,6 @@ void ambient_check_invalid_state(pid_t pid) if (pid != INTERNAL_LOCK_AMBIENT) return; - if (backlight_ops.get_lcd_power() == DPMS_OFF) - return; - if (is_emulator()) { /* In emulator, deviced does not turn off the display. */ if (backlight_ops.get_lcd_power() == DPMS_ON) @@ -132,8 +144,11 @@ void ambient_check_invalid_state(pid_t pid) * deviced doesn't get the clock signal. * deviced just turns off lcd in this case. */ + reset_timeout(TIMEOUT_NONE); ambient_set_state(false); - backlight_ops.off(NORMAL_MODE); + lcd_direct_control(DPMS_OFF, NORMAL_MODE); + + broadcast_lcd_off_late(LCD_OFF_LATE_MODE); } static void ambient_start_clock(void) @@ -155,11 +170,14 @@ static void ambient_end_clock(pid_t pid) ambient_state == false) return; - if (update_count == 0) - broadcast_lcd_off_late(LCD_OFF_LATE_MODE); + if (update_count == 0) { + _D("lcd off"); - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, PM_SLEEP_MARGIN); + backlight_ops.off(NORMAL_MODE); + broadcast_lcd_off_late(LCD_OFF_LATE_MODE); + if (disp_plgn.pm_unlock_internal) + disp_plgn.pm_unlock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, PM_SLEEP_MARGIN); + } update_count++; if (update_count == UINT_MAX) @@ -183,6 +201,32 @@ int ambient_set_screen(char *screen, pid_t pid) return 0; } +static void ambient_lcdoff_signal_handler(GDBusConnection *conn, + const gchar *sender, + const gchar *path, + const gchar *iface, + const gchar *name, + GVariant *param, + gpointer data) +{ + if (ambient_state == false) { + _E("It is not alpm mode"); + return; + } + + if (disp_plgn.pm_lock_internal) + disp_plgn.pm_lock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, GOTO_STATE_NOW, 0); + + _I("Display off in suspend state"); + + ambient_set_state(false); + lcd_direct_control(DPMS_OFF, NORMAL_MODE); + + broadcast_lcd_off_late(LCD_OFF_LATE_MODE); + if (disp_plgn.pm_unlock_internal) + disp_plgn.pm_unlock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, PM_SLEEP_MARGIN); +} + static void ambient_init(void *data) { int ret; @@ -197,6 +241,15 @@ static void ambient_init(void *data) vconf_notify_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, ambient_set_condition, NULL); + + ret = subscribe_dbus_signal(NULL, + DEVICED_OBJECT_PATH, + DEVICED_INTERFACE_NAME, + SIGNAL_ALPMLCDOFF, + ambient_lcdoff_signal_handler, + NULL, NULL); + if (ret <= 0) + _E("Failed to register signal handler: %d", ret); } static void ambient_exit(void *data) diff --git a/src/display/core.h b/src/display/core.h index 3f656eb..a58543c 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -195,11 +195,13 @@ void set_lcd_paneloff_mode(int val); void lcd_on_direct(enum device_flags flags); void lcd_on_procedure(int state, enum device_flags flag); void lcd_off_procedure(enum device_flags flag); +void lcd_direct_control(enum dpms_state state, int flags); int check_holdkey_block(enum state_t state); bool touch_event_blocked(void); int device_poweroff(void *data); void broadcast_lcd_off_late(enum device_flags flags); void set_dim_state(bool on); +void reset_timeout(int timeout); /* poll.c */ int check_dimstay(int next_state, int flag); diff --git a/src/display/poll.h b/src/display/poll.h index 736e20f..93afe57 100644 --- a/src/display/poll.h +++ b/src/display/poll.h @@ -42,6 +42,7 @@ enum { enum { INTERNAL_LOCK_BASE = 100000, + INTERNAL_LOCK_AMBIENT, INTERNAL_LOCK_BATTERY, INTERNAL_LOCK_BATTERY_FULL, INTERNAL_LOCK_BOOTING, @@ -61,7 +62,6 @@ enum { INTERNAL_LOCK_POWERKEY, INTERNAL_LOCK_PM, INTERNAL_LOCK_HALLIC, - INTERNAL_LOCK_AMBIENT, INTERNAL_LOCK_SWIM, }; -- 2.7.4 From 9b49485e9fb358f558df6a5642b9781e654d0c63 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 4 Jul 2019 15:30:28 +0900 Subject: [PATCH 13/16] Fix error while loading display.so ex) Failed to open module: /usr/lib/deviced/display.so: undefined symbol: lcd_direct_control Change-Id: I2f9ddc746fea3170bdaeb8faad10233595323733 Signed-off-by: lokilee73 --- plugins/iot/display/core.c | 2 +- plugins/mobile/display/core.c | 2 +- plugins/tv/display/core.c | 2 +- plugins/wearable/display/core.c | 22 +------------------ src/display/ambient-mode.c | 1 + src/display/core.h | 2 +- src/display/display.c | 47 +++++++++++++++++++++++++++++++++++++++++ src/display/display.h | 27 +++++++++++++++++++++++ 8 files changed, 80 insertions(+), 25 deletions(-) create mode 100644 src/display/display.c create mode 100644 src/display/display.h diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index fe4d69b..42ef795 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -103,9 +103,9 @@ static int lock_screen_timeout = LOCK_SCREEN_INPUT_TIMEOUT; static struct timeval lcdon_tv; static int lcd_paneloff_mode = false; static int stay_touchscreen_off = false; -static dd_list *lcdon_ops; static bool lcdon_broadcast = true; static bool touch_blocked = false; +dd_list *lcdon_ops; /* default transition, action fuctions */ static int default_trans(int evt); diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index f07c7fd..d38d9ac 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -104,9 +104,9 @@ static int lock_screen_timeout = LOCK_SCREEN_INPUT_TIMEOUT; static struct timeval lcdon_tv; static int lcd_paneloff_mode = false; static int stay_touchscreen_off = false; -static dd_list *lcdon_ops; static bool lcdon_broadcast = true; static bool touch_blocked = false; +dd_list *lcdon_ops; /* default transition, action fuctions */ static int default_trans(int evt); diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 5bf09f7..7529349 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -105,9 +105,9 @@ static int lock_screen_timeout = LOCK_SCREEN_INPUT_TIMEOUT; static struct timeval lcdon_tv; static int lcd_paneloff_mode = false; static int stay_touchscreen_off = false; -static dd_list *lcdon_ops; static bool lcdon_broadcast = true; static bool touch_blocked = false; +dd_list *lcdon_ops; /* default transition, action fuctions */ static int default_trans(int evt); diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 2c171f6..bf6ff62 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -104,9 +104,9 @@ static int lock_screen_timeout = LOCK_SCREEN_INPUT_TIMEOUT; static struct timeval lcdon_tv; static int lcd_paneloff_mode = false; static int stay_touchscreen_off = false; -static dd_list *lcdon_ops; static bool lcdon_broadcast = true; static bool touch_blocked = false; +dd_list *lcdon_ops; /* default transition, action fuctions */ static int default_trans(int evt); @@ -383,26 +383,6 @@ bool touch_event_blocked(void) return touch_blocked; } -void lcd_direct_control(enum dpms_state state, int flags) -{ - const struct device_ops *ops = NULL; - dd_list *l = NULL; - - switch (state) { - case DPMS_ON: - DD_LIST_FOREACH(lcdon_ops, l, ops) - ops->start(flags); - break; - case DPMS_OFF: - DD_LIST_FOREACH(lcdon_ops, l, ops) - ops->stop(flags); - break; - default: - _E("state is wrong value %d", state); - break; - } -} - void lcd_on_procedure(int state, enum device_flags flag) { dd_list *l = NULL; diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index 4223dc5..9254100 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -23,6 +23,7 @@ #include "util.h" #include "core.h" +#include "display.h" #include "display-ops.h" #include "core/device-notifier.h" #include "core/devices.h" diff --git a/src/display/core.h b/src/display/core.h index a58543c..1bb77df 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -158,6 +158,7 @@ struct display_keyfilter_ops { }; extern const struct display_keyfilter_ops *keyfilter_ops; +extern dd_list *lcdon_ops; /* If the bit in a condition variable is set, * we cannot transit the state until clear this bit. */ @@ -195,7 +196,6 @@ void set_lcd_paneloff_mode(int val); void lcd_on_direct(enum device_flags flags); void lcd_on_procedure(int state, enum device_flags flag); void lcd_off_procedure(enum device_flags flag); -void lcd_direct_control(enum dpms_state state, int flags); int check_holdkey_block(enum state_t state); bool touch_event_blocked(void); int device_poweroff(void *data); diff --git a/src/display/display.c b/src/display/display.c new file mode 100644 index 0000000..de55369 --- /dev/null +++ b/src/display/display.c @@ -0,0 +1,47 @@ +/* + * 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 "util.h" +#include "core.h" +#include "display-ops.h" +#include "core/list.h" +#include "core/common.h" + +void lcd_direct_control(enum dpms_state state, int flags) +{ + const struct device_ops *ops = NULL; + dd_list *l = NULL; + + switch (state) { + case DPMS_ON: + DD_LIST_FOREACH(lcdon_ops, l, ops) + ops->start(flags); + break; + case DPMS_OFF: + DD_LIST_FOREACH(lcdon_ops, l, ops) + ops->stop(flags); + break; + default: + _E("state is wrong value %d", state); + break; + } +} + diff --git a/src/display/display.h b/src/display/display.h new file mode 100644 index 0000000..3b14241 --- /dev/null +++ b/src/display/display.h @@ -0,0 +1,27 @@ +/* + * 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 __DISPLAY_H__ +#define __DISPLAY_H__ + +#include "device-interface.h" +#include "core/common.h" + +void lcd_direct_control(enum dpms_state state, int flags); +#endif -- 2.7.4 From 09393e2c3a133c4a3e7a1f54d84918fcb9f32376 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Fri, 5 Jul 2019 14:35:35 +0900 Subject: [PATCH 14/16] Add omitted dependency (zlib) Change-Id: I4b4ec163a271a2da0909dd9e379b016962710367 Signed-off-by: Inkyun Kil --- CMakeLists.txt | 1 + packaging/deviced.spec | 1 + 2 files changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a90dec1..33ca1c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -179,6 +179,7 @@ SET(PKG_MODULES wayland-client tizen-extension-client tizen-dpms-client + zlib ) IF(DISPLAY_MODULE STREQUAL on) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index b895131..fd8a375 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -40,6 +40,7 @@ BuildRequires: pkgconfig(capi-system-device) BuildRequires: pkgconfig(wayland-client) BuildRequires: pkgconfig(tizen-extension-client) BuildRequires: pkgconfig(tizen-dpms-client) +BuildRequires: pkgconfig(zlib) Requires: %{name}-tools = %{version}-%{release} %{?systemd_requires} -- 2.7.4 From 140d39399ef70fe38eb55a408c2e317cf35bd9f8 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Mon, 8 Jul 2019 20:11:20 +0900 Subject: [PATCH 15/16] Fix memory leak Change-Id: Ie34f039aeab698ba33f8edb9611a82b22ffc6de6 Signed-off-by: lokilee73 --- src/core/launch.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/launch.c b/src/core/launch.c index 0f97efd..136ed47 100644 --- a/src/core/launch.c +++ b/src/core/launch.c @@ -47,10 +47,11 @@ static int set_current_lang(void) } ret = setenv("LANG", lang, 1); + free(lang); if (ret < 0) return -1; - free(lang); - return 0; + else + return 0; } -- 2.7.4 From ed64d48ff1bdfbbbbee0515dadaa7acebb8b696e Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 5 Jul 2019 10:46:34 +0900 Subject: [PATCH 16/16] Apply async for dpms change communication method with dpms, from sync to async. Change-Id: I50894dc5b2b3420d0fb9335e298601a400eb120a Signed-off-by: lokilee73 --- plugins/iot/display/device-interface.c | 5 - plugins/mobile/display/device-interface.c | 5 - plugins/tv/display/device-interface.c | 5 - plugins/wearable/display/device-interface.c | 5 - src/display/display-dpms.c | 374 ++++++++++++++++++++++------ 5 files changed, 291 insertions(+), 103 deletions(-) diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index e92582e..01b98ac 100644 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -74,11 +74,6 @@ static struct display_device *display_dev; static int bl_onoff(int on) { - if (!dpms_is_available()) { - _E("Dpms is not available."); - return -EINVAL; - } - dpms_set_state(on); return 0; } diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index e92582e..01b98ac 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -74,11 +74,6 @@ static struct display_device *display_dev; static int bl_onoff(int on) { - if (!dpms_is_available()) { - _E("Dpms is not available."); - return -EINVAL; - } - dpms_set_state(on); return 0; } diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index e92582e..01b98ac 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -74,11 +74,6 @@ static struct display_device *display_dev; static int bl_onoff(int on) { - if (!dpms_is_available()) { - _E("Dpms is not available."); - return -EINVAL; - } - dpms_set_state(on); return 0; } diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 44d5f90..f44c51a 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -74,11 +74,6 @@ static struct display_device *display_dev; static int bl_onoff(int on) { - if (!dpms_is_available()) { - _E("Dpms is not available."); - return -EINVAL; - } - dpms_set_state(on); return 0; } diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c index 5a0220e..b1a6221 100644 --- a/src/display/display-dpms.c +++ b/src/display/display-dpms.c @@ -20,58 +20,71 @@ #include #include #include -#include "core/log.h" -#include "display/util.h" +#include #include #include #include +#include "core/log.h" +#include "display/util.h" + +typedef struct { + GSource gsource; + GPollFD gfd; + gboolean prepared; + + struct wl_display *wl_disp; + struct wl_registry *wl_registry; + struct wl_output *wl_output; + struct tizen_dpms_manager *tz_dpms_mng; + + uint32_t dpms_mode; +} wl_glib_info; + +wl_glib_info *info = NULL; -struct wl_display *display; -static struct wl_event_queue *queue; -struct wl_output *wl_out; -struct tizen_dpms_manager *tz_dpms_mng = NULL; -int lcd_state = -1; bool wm_is_ready; static bool dpms_connected; -static int dpms_retry; +static GSource *wl_glib_data = NULL; -bool check_wm_ready(void) +static void dpms_handle_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error) { - if (access("/run/.wm_ready", F_OK) == 0) { - _I("Window manager is ready."); - wm_is_ready = true; - return true; - } - - _I("Window manager is not ready."); - return false; + _D("Dpms_state_cb - mode:%u, error:%u", mode, error); + info->dpms_mode = mode; } void disconnect_interface_with_dpms(void) { - if (tz_dpms_mng) { - tizen_dpms_manager_destroy(tz_dpms_mng); - tz_dpms_mng = NULL; + if (!info) { + _E("Info is NULL."); + return; } - if (wl_out) { - wl_output_destroy(wl_out); - wl_out = NULL; + if (info->tz_dpms_mng) { + tizen_dpms_manager_destroy(info->tz_dpms_mng); + info->tz_dpms_mng = NULL; } - if (display) { - wl_display_disconnect(display); - display = NULL; + if (info->wl_output) { + wl_output_destroy(info->wl_output); + info->wl_output = NULL; } - dpms_connected = false; -} + if (info->wl_registry) { + wl_registry_destroy(info->wl_registry); + info->wl_registry= NULL; + } -static void dpms_handle_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error) -{ - _D("dpms_state_cb - mode:%d, error:%d", mode, error); - lcd_state = mode; - dpms_retry = 0; + if (info->wl_disp) { + wl_display_disconnect(info->wl_disp); + info->wl_disp= NULL; + } + + if (wl_glib_data) { + g_source_destroy(wl_glib_data); + wl_glib_data = NULL; + } + + dpms_connected = false; } static const struct tizen_dpms_manager_listener dpms_listener = { @@ -81,20 +94,26 @@ static const struct tizen_dpms_manager_listener dpms_listener = { static void handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { + if (!data) { + _E("Data is NULL."); + return; + } + info = (wl_glib_info *)data; + if (strcmp(interface, "wl_output") == 0) { - wl_out = wl_registry_bind(registry, name, &wl_output_interface, 2); - if (!wl_out) { - _E("Handle wl_output bind failed."); + info->wl_output= wl_registry_bind(registry, name, &wl_output_interface, 2); + if (!info->wl_output) { + _E("Failed to bind registry."); disconnect_interface_with_dpms(); } _D("Get wl_output."); } else if (strcmp(interface, "tizen_dpms_manager") == 0) { - tz_dpms_mng = wl_registry_bind(registry, name, &tizen_dpms_manager_interface, 1); - if (!tz_dpms_mng) { - _E("Handle tizen_dpms_manager bind failed."); + info->tz_dpms_mng = wl_registry_bind(registry, name, &tizen_dpms_manager_interface, 1); + if (!info->tz_dpms_mng) { + _E("Failed to bind registry."); disconnect_interface_with_dpms(); - } - tizen_dpms_manager_add_listener(tz_dpms_mng, &dpms_listener, NULL); + } else + tizen_dpms_manager_add_listener(info->tz_dpms_mng, &dpms_listener, info); _D("Get dpms manager."); } @@ -110,52 +129,240 @@ static const struct wl_registry_listener registry_listener = { handle_global_remove }; -bool connect_interface_with_dpms(void) +static int +wl_glib_wayland_init(wl_glib_info *info) { - struct wl_registry *registry = NULL; + int ret; - display = wl_display_connect(NULL); - if (display == NULL) { - _E("Display is NULL."); - goto error; + info->wl_disp = wl_display_connect(NULL); + if (info->wl_disp == NULL) { + _E("Failed to connect display."); + goto err; } - registry = wl_display_get_registry(display); - if (registry == NULL) { - _E("Registry is NULL."); - goto error; + info->wl_registry = wl_display_get_registry(info->wl_disp); + if (info->wl_registry == NULL) { + _E("Failed to get display registry."); + goto err; } - queue = wl_display_create_queue(display); - if (queue == NULL) { - printf(" failed wl_display_create_queue\n"); - goto error; + ret = wl_registry_add_listener(info->wl_registry, ®istry_listener, info); + if (ret) { + _E("Failed to add registry listener."); + goto err; } - wl_proxy_set_queue((struct wl_proxy *)display, queue); - wl_proxy_set_queue((struct wl_proxy *)registry, queue); + ret = wl_display_roundtrip(info->wl_disp); + if (ret < 0 || info->wl_output == NULL) { + _E("Failed to roundtrip display."); + goto err; + } - wl_registry_add_listener(registry, ®istry_listener, NULL); + return 0; - wl_display_dispatch_queue(display, queue); - wl_display_roundtrip_queue(display, queue); +err: + return -1; +} - if (!wl_out || !tz_dpms_mng) { - _E("Roundtrip failed."); - goto error; +static gboolean +wl_glib_client_prepare(GSource *source, gint *time) +{ + if (!source) { + _E("Source is NULL."); + return FALSE; } + info = (wl_glib_info *)source; - wl_registry_destroy(registry); - _D("Setup with dpms is done."); - return true; + /* If info is already prepared, do nothing in this function. */ + if (info->prepared == TRUE) + return FALSE; + + while (wl_display_prepare_read(info->wl_disp) != 0) { + if (wl_display_dispatch_pending(info->wl_disp) == -1) + _E("Failed to dispatch display pending."); + } + + info->prepared = TRUE; + + wl_display_flush(info->wl_disp); + *time = -1; + + return FALSE; +} + +static gboolean +wl_glib_client_check(GSource *source) +{ + gboolean ret = FALSE; + int wl_ret = 0; + + if (!source) { + _E("Source is NULL."); + return FALSE; + } + info = (wl_glib_info *)source; + if (g_source_is_destroyed(source)) { + if (info && info->wl_disp && info->prepared) + wl_display_cancel_read(info->wl_disp); + _E("Display source(%p) already destroyed.", source); + return ret; + } + + if (!info->prepared) + return ret; + + if (info->gfd.revents & (G_IO_HUP|G_IO_ERR)) { + wl_display_cancel_read(info->wl_disp); + goto err; + } + + if (info->gfd.revents & G_IO_IN) { + wl_ret = wl_display_read_events(info->wl_disp); + if (wl_ret < 0) { + _E("Failed to read display events: %d", wl_ret); + goto err; + } + ret = TRUE; + } else + wl_display_cancel_read(info->wl_disp); + + info->prepared = FALSE; + + return ret; + +err: + _E("Get ERROR in check: revent:0x%x, wl_err:%d", info->gfd.revents, wl_ret); + + info->prepared = FALSE; + g_source_destroy(source); + + return FALSE; +} + +static gboolean +wl_glib_client_dispatch(GSource *source, GSourceFunc cb, gpointer data) +{ + int ret = 0; + + if (!source) { + _E("Source is NULL."); + return G_SOURCE_REMOVE; + } + info = (wl_glib_info *)source; + + if (g_source_is_destroyed(source)) { + _E("Display source(%p) already destroyed.", source); + return G_SOURCE_REMOVE; + } + + if (info->gfd.revents & (G_IO_HUP|G_IO_ERR)) + goto err; + + if (info->gfd.revents & G_IO_IN) { + ret = wl_display_dispatch_pending(info->wl_disp); + if (ret == -1) { + _E("Failed to dispatch display pending: %d", ret); + goto err; + } + } + + ret = wl_display_flush(info->wl_disp); + if (ret == -1) { + _E("Failed to flush display: %d", ret); + goto err; + } + + return G_SOURCE_CONTINUE; + +err: + _E("Err in dispatch: revent:0x%x, wl_err:%d", info->gfd.revents, ret); + + return G_SOURCE_REMOVE; +} + +static void +wl_glib_client_finalize(GSource *source) +{ + if (!source) { + _E("Source is NULL."); + return; + } + info = (wl_glib_info *)source; -error: - if (registry) - wl_registry_destroy(registry); disconnect_interface_with_dpms(); + return; +} + +static GSourceFuncs wl_glib_client_funcs = { + .prepare = wl_glib_client_prepare, + .check = wl_glib_client_check, + .dispatch = wl_glib_client_dispatch, + .finalize = wl_glib_client_finalize, +}; + +GSource* wl_glib_client_init(void) +{ + int ret; + + info = (wl_glib_info *)g_source_new(&wl_glib_client_funcs, sizeof(wl_glib_info)); + if (info == NULL) { + _E("Failed to make g_source_new."); + goto err; + } + + ret = wl_glib_wayland_init(info); + if (ret < 0) { + _E("Failed to init wayland."); + goto err; + } + + info->gfd.fd = wl_display_get_fd(info->wl_disp); + if (info->gfd.fd < 0) { + _E("Failed to get display fd"); + goto err; + } + + 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_unref(&info->gsource); + + return &info->gsource; + +err: + if (info) { + disconnect_interface_with_dpms(); + g_source_unref(&info->gsource); + } + + return NULL; +} + +bool check_wm_ready(void) +{ + if (access("/run/.wm_ready", F_OK) == 0) { + _I("Window manager is ready."); + wm_is_ready = true; + return true; + } + + _I("Window manager is not ready."); return false; } +bool connect_interface_with_dpms(void) +{ + wl_glib_data = wl_glib_client_init(); + if (!wl_glib_data) { + _E("Failed to init client."); + return false; + } + + return true; +} + bool dpms_is_available(void) { /* Check window manager */ @@ -175,26 +382,27 @@ bool dpms_is_available(void) void dpms_set_state(int on) { - dpms_retry = 1; + uint32_t mode; - tizen_dpms_manager_set_dpms(tz_dpms_mng, wl_out, on); - wl_display_roundtrip(display); - - while (dpms_retry) { - wl_display_dispatch_queue(display, queue); + if (!dpms_is_available()) { + _E("Dpms is not available."); + return; } + + mode = (uint32_t)on; + tizen_dpms_manager_set_dpms(info->tz_dpms_mng, info->wl_output, mode); + wl_display_flush(info->wl_disp); } int dpms_get_state(void) { - dpms_retry = 1; - - tizen_dpms_manager_get_dpms(tz_dpms_mng, wl_out); - wl_display_roundtrip(display); - - while (dpms_retry) { - wl_display_dispatch_queue(display, queue); + if (!dpms_is_available()) { + _E("Dpms is not available."); + return -EINVAL; } - return lcd_state; + tizen_dpms_manager_get_dpms(info->tz_dpms_mng, info->wl_output); + wl_display_flush(info->wl_disp); + + return (int)info->dpms_mode; } -- 2.7.4