From a83bbab5d9f966dfecb729524b8bac831c3f6f73 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 14 Nov 2019 17:49:11 +0900 Subject: [PATCH 01/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 02/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 03/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 04/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 05/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 06/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 From 01d50816e19823d225a7f5ea191e3f12d80093e9 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 11 Dec 2019 14:23:42 +0900 Subject: [PATCH 07/16] Delete disabling hardkey sound while touchscreen pressed Change-Id: Ie0f358de9da8a6a54b65874b320255fe9977a7a9 Signed-off-by: Youngjae Cho --- plugins/iot/display/key-filter.c | 4 ---- plugins/mobile/display/key-filter.c | 4 ---- plugins/tv/display/key-filter.c | 4 ---- plugins/wearable/display/key-filter.c | 4 ---- 4 files changed, 16 deletions(-) diff --git a/plugins/iot/display/key-filter.c b/plugins/iot/display/key-filter.c index 5d16df7..5e19c95 100644 --- a/plugins/iot/display/key-filter.c +++ b/plugins/iot/display/key-filter.c @@ -581,10 +581,6 @@ static void process_hardkey_backlight(struct input_event *pinput) _E("pinput->value : %d", pinput->value); if (pinput->value == KEY_PRESSED) { - if (touch_pressed) { - _I("Touch is pressed, then hard key is not working!"); - return; - } if (!wearable_mode()) { /* Sound & Vibrate only in unlock state */ if (__get_lock_screen_state() == VCONFKEY_IDLE_UNLOCK diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index d63eff2..4d83dbb 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -570,10 +570,6 @@ static void process_hardkey_backlight(struct input_event *pinput) _E("pinput->value : %d", pinput->value); if (pinput->value == KEY_PRESSED) { - if (touch_pressed) { - _I("Touch is pressed, then hard key is not working!"); - return; - } if (!wearable_mode()) { /* Sound & Vibrate only in unlock state */ if (__get_lock_screen_state() == VCONFKEY_IDLE_UNLOCK diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index ddbb287..b926193 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -581,10 +581,6 @@ static void process_hardkey_backlight(struct input_event *pinput) _E("pinput->value : %d", pinput->value); if (pinput->value == KEY_PRESSED) { - if (touch_pressed) { - _I("Touch is pressed, then hard key is not working!"); - return; - } if (!wearable_mode()) { /* Sound & Vibrate only in unlock state */ if (__get_lock_screen_state() == VCONFKEY_IDLE_UNLOCK diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index a160641..086d233 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -570,10 +570,6 @@ static void process_hardkey_backlight(struct input_event *pinput) _E("pinput->value : %d", pinput->value); if (pinput->value == KEY_PRESSED) { - if (touch_pressed) { - _I("Touch is pressed, then hard key is not working!"); - return; - } if (!wearable_mode()) { /* Sound & Vibrate only in unlock state */ if (__get_lock_screen_state() == VCONFKEY_IDLE_UNLOCK -- 2.7.4 From e32e650b46a65bd172d7d6664b314dfa7429a1ce Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 12 Dec 2019 11:24:56 +0900 Subject: [PATCH 08/16] Fix typo Fix process_background(), process_foreground() log. Change-Id: If80620f63c0997b6339aa788656bd416b4fb5d66 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 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 421bbbb..4a3e570 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -2524,7 +2524,7 @@ static int process_background(void *data) node = find_node(S_NORMAL, pid); if (node) { node->background = true; - _I("%d pid is background, then PM will be unlocked LCD_NORMAL", pid); + _I("Process(%d) is background, then PM will be unlocked LCD_NORMAL.", pid); } return 0; @@ -2540,7 +2540,7 @@ static int process_foreground(void *data) node = find_node(S_NORMAL, pid); if (node) { node->background = false; - _I("Process(%d) is background, then PM will be unlocked LCD_NORMAL.", pid); + _I("Process(%d) is foreground, then PM will be locked LCD_NORMAL.", pid); } return 0; diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 649f4bd..14663cb 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -2534,7 +2534,7 @@ static int process_background(void *data) node = find_node(S_NORMAL, pid); if (node) { node->background = true; - _I("%d pid is background, then PM will be unlocked LCD_NORMAL", pid); + _I("Process(%d) is background, then PM will be unlocked LCD_NORMAL.", pid); } return 0; @@ -2550,7 +2550,7 @@ static int process_foreground(void *data) node = find_node(S_NORMAL, pid); if (node) { node->background = false; - _I("Process(%d) is background, then PM will be unlocked LCD_NORMAL.", pid); + _I("Process(%d) is foreground, then PM will be locked LCD_NORMAL.", pid); } return 0; diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 7069a6e..d493b9f 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -2521,7 +2521,7 @@ static int process_background(void *data) node = find_node(S_NORMAL, pid); if (node) { node->background = true; - _I("%d pid is background, then PM will be unlocked LCD_NORMAL", pid); + _I("Process(%d) is background, then PM will be unlocked LCD_NORMAL.", pid); } return 0; @@ -2537,7 +2537,7 @@ static int process_foreground(void *data) node = find_node(S_NORMAL, pid); if (node) { node->background = false; - _I("Process(%d) is background, then PM will be unlocked LCD_NORMAL.", pid); + _I("Process(%d) is foreground, then PM will be locked LCD_NORMAL.", pid); } return 0; diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 41a2ce6..1f0f345 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -2551,7 +2551,7 @@ static int process_background(void *data) node = find_node(S_NORMAL, pid); if (node) { node->background = true; - _I("%d pid is background, then PM will be unlocked LCD_NORMAL", pid); + _I("Process(%d) is background, then PM will be unlocked LCD_NORMAL.", pid); } return 0; @@ -2567,7 +2567,7 @@ static int process_foreground(void *data) node = find_node(S_NORMAL, pid); if (node) { node->background = false; - _I("Process(%d) is background, then PM will be unlocked LCD_NORMAL.", pid); + _I("Process(%d) is foreground, then PM will be locked LCD_NORMAL.", pid); } return 0; -- 2.7.4 From d4ff7a15553357fbdbd723fb37b0829990f645d4 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 12 Dec 2019 17:23:51 +0900 Subject: [PATCH 09/16] Refactoring display-dpms - Separate initialization from dpms_is_available() to init_dpms(). - Integrate dpms exit sequence into exit_dpms() for poweroff. - Delete pointer 'wl_glib_data' and use pointer 'info' instead, which are practically same. - Fix usage of disconnect_interface_with_dpms() considering GSource finalize. Change-Id: I7579b7338ee263b4c991cc8a055cefc0eb392f02 Signed-off-by: Youngjae Cho --- plugins/iot/display/core.c | 17 +++-- plugins/iot/display/device-interface.c | 3 +- plugins/mobile/display/core.c | 17 +++-- plugins/mobile/display/device-interface.c | 3 +- plugins/tv/display/core.c | 17 +++-- plugins/tv/display/device-interface.c | 3 +- plugins/wearable/display/core.c | 17 +++-- plugins/wearable/display/device-interface.c | 3 +- src/display/display-dpms.c | 106 ++++++++++++++++------------ src/display/display-dpms.h | 9 +-- 10 files changed, 97 insertions(+), 98 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 4a3e570..a9f332a 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -2640,11 +2640,11 @@ static int display_load_config(struct parse_result *result, void *user_data) return 0; } -static gboolean lcd_on_wm_ready(gpointer data) +static gboolean delayed_init_dpms(gpointer data) { int timeout; - if (!check_wm_ready()) + if (!init_dpms()) return G_SOURCE_CONTINUE; switch (pm_cur_state) { @@ -2666,11 +2666,11 @@ static gboolean lcd_on_wm_ready(gpointer data) return G_SOURCE_REMOVE; } -static void add_timer_for_wm_ready(void) +static void add_timer_for_init_dpms(void) { - guint id = g_timeout_add(500/* milliseconds */, lcd_on_wm_ready, NULL); + guint id = g_timeout_add(500/* milliseconds */, delayed_init_dpms, NULL); if (id == 0) - _E("Failed to add wm_ready timeout."); + _E("Failed to add init_dpms timeout."); } /** @@ -2750,7 +2750,6 @@ static void display_init(void *data) int ret, i; unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS); int timeout = 0; - bool wm_ready; _I("Start power manager."); @@ -2821,11 +2820,11 @@ static void display_init(void *data) /* wm_ready needs to be checked * since display manager can be launched later than deviced. * In the case, display cannot be turned on at the first booting */ - wm_ready = check_wm_ready(); - if (wm_ready) + // wm_ready = check_wm_ready(); + if (init_dpms()) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); else - add_timer_for_wm_ready(); + add_timer_for_init_dpms(); if (display_conf.lcd_always_on) { _I("LCD always on."); diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index 0c4c453..4064ee2 100644 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -1023,8 +1023,7 @@ int exit_sysfs(void) backlight_update(); - g_main_loop_unref(dpms_loop); - g_main_context_unref(dpms_context); + exit_dpms(); ops = find_device("touchscreen"); if (!check_default(ops)) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 14663cb..9d514d8 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -2650,11 +2650,11 @@ static int display_load_config(struct parse_result *result, void *user_data) return 0; } -static gboolean lcd_on_wm_ready(gpointer data) +static gboolean delayed_init_dpms(gpointer data) { int timeout; - if (!check_wm_ready()) + if (!init_dpms()) return G_SOURCE_CONTINUE; switch (pm_cur_state) { @@ -2676,11 +2676,11 @@ static gboolean lcd_on_wm_ready(gpointer data) return G_SOURCE_REMOVE; } -static void add_timer_for_wm_ready(void) +static void add_timer_for_init_dpms(void) { - guint id = g_timeout_add(500/* milliseconds */, lcd_on_wm_ready, NULL); + guint id = g_timeout_add(500/* milliseconds */, delayed_init_dpms, NULL); if (id == 0) - _E("Failed to add wm_ready timeout."); + _E("Failed to add init_dpms timeout."); } /** @@ -2760,7 +2760,6 @@ static void display_init(void *data) int ret, i; unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS); int timeout = 0; - bool wm_ready; _I("Start power manager."); @@ -2831,11 +2830,11 @@ static void display_init(void *data) /* wm_ready needs to be checked * since display manager can be launched later than deviced. * In the case, display cannot be turned on at the first booting */ - wm_ready = check_wm_ready(); - if (wm_ready) + // wm_ready = check_wm_ready(); + if (init_dpms()) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); else - add_timer_for_wm_ready(); + add_timer_for_init_dpms(); if (display_conf.lcd_always_on) { _I("LCD always on."); diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 0c4c453..4064ee2 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -1023,8 +1023,7 @@ int exit_sysfs(void) backlight_update(); - g_main_loop_unref(dpms_loop); - g_main_context_unref(dpms_context); + exit_dpms(); ops = find_device("touchscreen"); if (!check_default(ops)) diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index d493b9f..32c0fed 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -2637,11 +2637,11 @@ static int display_load_config(struct parse_result *result, void *user_data) return 0; } -static gboolean lcd_on_wm_ready(gpointer data) +static gboolean delayed_init_dpms(gpointer data) { int timeout; - if (!check_wm_ready()) + if (!init_dpms()) return G_SOURCE_CONTINUE; switch (pm_cur_state) { @@ -2663,11 +2663,11 @@ static gboolean lcd_on_wm_ready(gpointer data) return G_SOURCE_REMOVE; } -static void add_timer_for_wm_ready(void) +static void add_timer_for_init_dpms(void) { - guint id = g_timeout_add(500/* milliseconds */, lcd_on_wm_ready, NULL); + guint id = g_timeout_add(500/* milliseconds */, delayed_init_dpms, NULL); if (id == 0) - _E("Failed to add wm_ready timeout."); + _E("Failed to add init_dpms timeout."); } /** @@ -2747,7 +2747,6 @@ static void display_init(void *data) int ret, i; unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS); int timeout = 0; - bool wm_ready; _I("Start power manager."); @@ -2818,11 +2817,11 @@ static void display_init(void *data) /* wm_ready needs to be checked * since display manager can be launched later than deviced. * In the case, display cannot be turned on at the first booting */ - wm_ready = check_wm_ready(); - if (wm_ready) + // wm_ready = check_wm_ready(); + if (init_dpms()) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); else - add_timer_for_wm_ready(); + add_timer_for_init_dpms(); if (display_conf.lcd_always_on) { _I("LCD always on."); diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 0c4c453..4064ee2 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -1023,8 +1023,7 @@ int exit_sysfs(void) backlight_update(); - g_main_loop_unref(dpms_loop); - g_main_context_unref(dpms_context); + exit_dpms(); ops = find_device("touchscreen"); if (!check_default(ops)) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 1f0f345..4a20902 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -2667,11 +2667,11 @@ static int display_load_config(struct parse_result *result, void *user_data) return 0; } -static gboolean lcd_on_wm_ready(gpointer data) +static gboolean delayed_init_dpms(gpointer data) { int timeout; - if (!check_wm_ready()) + if (!init_dpms()) return G_SOURCE_CONTINUE; switch (pm_cur_state) { @@ -2693,11 +2693,11 @@ static gboolean lcd_on_wm_ready(gpointer data) return G_SOURCE_REMOVE; } -static void add_timer_for_wm_ready(void) +static void add_timer_for_init_dpms(void) { - guint id = g_timeout_add(500/* milliseconds */, lcd_on_wm_ready, NULL); + guint id = g_timeout_add(500/* milliseconds */, delayed_init_dpms, NULL); if (id == 0) - _E("Failed to add wm_ready timeout."); + _E("Failed to add init_dpms timeout."); } /** @@ -2777,7 +2777,6 @@ static void display_init(void *data) int ret, i; unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS); int timeout = 0; - bool wm_ready; _I("Start power manager."); @@ -2848,11 +2847,11 @@ static void display_init(void *data) /* wm_ready needs to be checked * since display manager can be launched later than deviced. * In the case, display cannot be turned on at the first booting */ - wm_ready = check_wm_ready(); - if (wm_ready) + // wm_ready = check_wm_ready(); + if (init_dpms()) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); else - add_timer_for_wm_ready(); + add_timer_for_init_dpms(); if (display_conf.lcd_always_on) { _I("LCD always on."); diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 9b5d656..eb6414d 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -1026,8 +1026,7 @@ int exit_sysfs(void) backlight_update(); - g_main_loop_unref(dpms_loop); - g_main_context_unref(dpms_context); + exit_dpms(); ops = find_device("touchscreen"); if (!check_default(ops)) diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c index bba880c..fb7659b 100644 --- a/src/display/display-dpms.c +++ b/src/display/display-dpms.c @@ -27,6 +27,7 @@ #include "core/log.h" #include "display/util.h" +#include "display/display-dpms.h" #define DPMS_GET_TIMEOUT 10 /* milisecond */ @@ -43,14 +44,13 @@ typedef struct { uint32_t dpms_mode; } wl_glib_info; -wl_glib_info *info = NULL; +static wl_glib_info *info = NULL; -bool wm_is_ready; +static bool wm_is_ready; static bool dpms_connected; -static GSource *wl_glib_data = NULL; -GMainLoop *dpms_loop; -GMainContext *dpms_context; +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) @@ -77,7 +77,7 @@ static gboolean dpms_loop_quit(void *data) return G_SOURCE_REMOVE; } -void disconnect_interface_with_dpms(void) +static void disconnect_interface_with_dpms(wl_glib_info *info) { if (!dpms_connected) return; @@ -108,12 +108,6 @@ void disconnect_interface_with_dpms(void) wl_display_disconnect(info->wl_disp); info->wl_disp= NULL; } - - if (wl_glib_data) { - g_source_destroy(wl_glib_data); - g_source_unref(wl_glib_data); - wl_glib_data = NULL; - } } static const struct tizen_dpms_manager_listener dpms_listener = { @@ -134,17 +128,21 @@ static void handle_global(void *data, struct wl_registry *registry, 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(); + g_source_destroy((GSource *)info); + exit_dpms(); + return; } _D("Get wl_output."); } else if (strcmp(interface, "tizen_dpms_manager") == 0) { 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(); - } else - tizen_dpms_manager_add_listener(info->tz_dpms_mng, &dpms_listener, info); + g_source_destroy((GSource *)info); + exit_dpms(); + return; + } + tizen_dpms_manager_add_listener(info->tz_dpms_mng, &dpms_listener, info); _D("Get dpms manager."); } } @@ -327,9 +325,8 @@ wl_glib_client_finalize(GSource *source) _E("Source is NULL."); return; } - info = (wl_glib_info *)source; - disconnect_interface_with_dpms(); + disconnect_interface_with_dpms((wl_glib_info *)source); return; } @@ -340,7 +337,7 @@ static GSourceFuncs wl_glib_client_funcs = { .finalize = wl_glib_client_finalize, }; -GSource* wl_glib_client_init(void) +static bool wl_glib_client_init(void) { int ret; @@ -362,9 +359,6 @@ 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; @@ -372,18 +366,16 @@ GSource* wl_glib_client_init(void) g_source_attach(&info->gsource, dpms_context); g_source_unref(&info->gsource); - return &info->gsource; + return true; err: - if (info) { - disconnect_interface_with_dpms(); + if (info) g_source_unref(&info->gsource); - } - return NULL; + return false; } -bool check_wm_ready(void) +static bool check_wm_ready(void) { if (access("/run/.wm_ready", F_OK) == 0) { _I("Window manager is ready."); @@ -395,17 +387,6 @@ bool check_wm_ready(void) 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; -} - static bool dpms_is_available(void) { /* Check window manager */ @@ -414,14 +395,7 @@ static bool dpms_is_available(void) return false; } - /* Try to connect interface with dpms, because window manager is ready */ - if (!dpms_connected) { - _D("call connect_interface_with_dpms()"); - dpms_connected = connect_interface_with_dpms(); - return dpms_connected; - } - - return true; + return dpms_connected; } void dpms_set_state(int on) @@ -475,3 +449,41 @@ int dpms_get_state(void) else return -ETIMEDOUT; } + +bool init_dpms(void) +{ + if (dpms_connected) + return true; + + if (!check_wm_ready()) + return false; + + _I("Init dpms."); + dpms_context = g_main_context_new(); + dpms_loop = g_main_loop_new(dpms_context, false); + + dpms_connected = wl_glib_client_init(); + if (!dpms_connected) { + g_main_loop_unref(dpms_loop); + dpms_loop = NULL; + + g_main_context_unref(dpms_context); + dpms_context = NULL; + } + + return dpms_connected; +} + +void exit_dpms(void) +{ + _I("Exit dpms."); + if (dpms_loop) { + g_main_loop_unref(dpms_loop); + dpms_loop = NULL; + } + + if (dpms_context) { + g_main_context_unref(dpms_context); + dpms_context = NULL; + } +} diff --git a/src/display/display-dpms.h b/src/display/display-dpms.h index 15b401d..6c401be 100644 --- a/src/display/display-dpms.h +++ b/src/display/display-dpms.h @@ -19,13 +19,8 @@ #ifndef __DISPLAY_DPMS_H__ #define __DISPLAY_DPMS_H__ -bool check_wm_ready(void); -bool dpms_is_available(void); -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; +bool init_dpms(void); +void exit_dpms(void); #endif /* __DISPLAY_DPMS_H__ */ -- 2.7.4 From e9f9dd9bbae3e5c143e9cb33105f4bdc9f0f02e5 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 16 Dec 2019 15:09:31 +0900 Subject: [PATCH 10/16] Separate context of DPMS get/set request Separate DPMS client into two, get/set, each of which is only in charge of get or set request. And attached to different context so that they can be handled in different context. * dpms_set_state() --> handled within the default context * dpms_get_state() --> handled within the dpms_context Change-Id: I34c7388f83d8bb54a8bfc12c65c2fc45455b9ce1 Signed-off-by: Youngjae Cho --- src/display/display-dpms.c | 105 ++++++++++++++++++++++++++++++++------------- 1 file changed, 75 insertions(+), 30 deletions(-) diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c index fb7659b..0a6cbed 100644 --- a/src/display/display-dpms.c +++ b/src/display/display-dpms.c @@ -42,12 +42,13 @@ typedef struct { struct tizen_dpms_manager *tz_dpms_mng; uint32_t dpms_mode; + bool connected; } wl_glib_info; -static wl_glib_info *info = NULL; +wl_glib_info *set_client = NULL; +wl_glib_info *get_client = NULL; static bool wm_is_ready; -static bool dpms_connected; static GMainLoop *dpms_loop; static GMainContext *dpms_context; @@ -56,13 +57,13 @@ 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); - info->dpms_mode = mode; + set_client->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; + get_client->dpms_mode = mode; dpms_get_state_done = true; if (g_main_loop_is_running(dpms_loop)) @@ -79,15 +80,15 @@ static gboolean dpms_loop_quit(void *data) static void disconnect_interface_with_dpms(wl_glib_info *info) { - if (!dpms_connected) - return; - if (!info) { _E("Info is NULL."); return; } - dpms_connected = false; + if (!info->connected) + return; + + info->connected = false; if (info->tz_dpms_mng) { tizen_dpms_manager_destroy(info->tz_dpms_mng); @@ -108,6 +109,14 @@ static void disconnect_interface_with_dpms(wl_glib_info *info) wl_display_disconnect(info->wl_disp); info->wl_disp= NULL; } + + if (info == set_client) { + set_client = NULL; + _D("Disconnect set client."); + } else if (info == get_client) { + get_client = NULL; + _D("Disconnect get clinet."); + } } static const struct tizen_dpms_manager_listener dpms_listener = { @@ -118,6 +127,7 @@ 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) { + wl_glib_info *info; if (!data) { _E("Data is NULL."); return; @@ -128,7 +138,6 @@ static void handle_global(void *data, struct wl_registry *registry, info->wl_output= wl_registry_bind(registry, name, &wl_output_interface, 2); if (!info->wl_output) { _E("Failed to bind registry."); - g_source_destroy((GSource *)info); exit_dpms(); return; } @@ -137,7 +146,6 @@ static void handle_global(void *data, struct wl_registry *registry, info->tz_dpms_mng = wl_registry_bind(registry, name, &tizen_dpms_manager_interface, 1); if (!info->tz_dpms_mng) { _E("Failed to bind registry."); - g_source_destroy((GSource *)info); exit_dpms(); return; } @@ -205,6 +213,8 @@ err: static gboolean wl_glib_client_prepare(GSource *source, gint *time) { + wl_glib_info *info; + if (!source) { _E("Source is NULL."); return FALSE; @@ -231,6 +241,7 @@ wl_glib_client_prepare(GSource *source, gint *time) static gboolean wl_glib_client_check(GSource *source) { + wl_glib_info *info; gboolean ret = FALSE; int wl_ret = 0; @@ -280,6 +291,7 @@ err: static gboolean wl_glib_client_dispatch(GSource *source, GSourceFunc cb, gpointer data) { + wl_glib_info *info; int ret = 0; if (!source) { @@ -337,9 +349,10 @@ static GSourceFuncs wl_glib_client_funcs = { .finalize = wl_glib_client_finalize, }; -static bool wl_glib_client_init(void) +static void wl_glib_client_init(wl_glib_info **client, GMainContext *context) { int ret; + wl_glib_info *info; info = (wl_glib_info *)g_source_new(&wl_glib_client_funcs, sizeof(wl_glib_info)); if (info == NULL) { @@ -363,16 +376,18 @@ static bool wl_glib_client_init(void) info->gfd.revents = 0; g_source_add_poll(&info->gsource, &info->gfd); - g_source_attach(&info->gsource, dpms_context); + g_source_attach(&info->gsource, context); g_source_unref(&info->gsource); - return true; + info->connected = true; + *client = info; + return; err: if (info) g_source_unref(&info->gsource); - return false; + *client = NULL; } static bool check_wm_ready(void) @@ -395,7 +410,7 @@ static bool dpms_is_available(void) return false; } - return dpms_connected; + return set_client && get_client; } void dpms_set_state(int on) @@ -408,8 +423,8 @@ void dpms_set_state(int on) } mode = (uint32_t)on; - tizen_dpms_manager_set_dpms(info->tz_dpms_mng, info->wl_output, mode); - wl_display_flush(info->wl_disp); + tizen_dpms_manager_set_dpms(set_client->tz_dpms_mng, set_client->wl_output, mode); + wl_display_flush(set_client->wl_disp); } int dpms_get_state(void) @@ -428,8 +443,8 @@ int dpms_get_state(void) 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); + tizen_dpms_manager_get_dpms(get_client->tz_dpms_mng, get_client->wl_output); + wl_display_flush(get_client->wl_disp); // Set a response timeout timeout = g_timeout_source_new(DPMS_GET_TIMEOUT); @@ -445,33 +460,57 @@ int dpms_get_state(void) g_source_unref(timeout); if (dpms_get_state_done) - return (int)info->dpms_mode; + return (int)get_client->dpms_mode; else return -ETIMEDOUT; } +/* + * Make two dpms client, + * each sends only set or get requests. + * + * set_client is attached to the default context, + * whereas get_client is attached to the dpms_context. + * + * return true only if both connection established successfully. + */ bool init_dpms(void) { - if (dpms_connected) + if (set_client && get_client) return true; if (!check_wm_ready()) return false; _I("Init dpms."); - dpms_context = g_main_context_new(); - dpms_loop = g_main_loop_new(dpms_context, false); + /* client for set request */ + if (!set_client) { + wl_glib_client_init(&set_client, NULL); - dpms_connected = wl_glib_client_init(); - if (!dpms_connected) { - g_main_loop_unref(dpms_loop); - dpms_loop = NULL; + if (!set_client) { + _E("Failed to init set client."); + exit_dpms(); + return false; + } + _I("Successfully initialized dpms set client."); + } - g_main_context_unref(dpms_context); - dpms_context = NULL; + /* client for get request */ + if (!get_client) { + dpms_context = g_main_context_new(); + dpms_loop = g_main_loop_new(dpms_context, false); + + wl_glib_client_init(&get_client, dpms_context); + + if (!get_client) { + _E("Failed to init get clinet."); + exit_dpms(); + return false; + } + _I("Successfully initialized dpms get client."); } - return dpms_connected; + return true; } void exit_dpms(void) @@ -486,4 +525,10 @@ void exit_dpms(void) g_main_context_unref(dpms_context); dpms_context = NULL; } + + if (set_client && !g_source_is_destroyed((GSource *)set_client)) + g_source_destroy((GSource *)set_client); + + if (get_client && !g_source_is_destroyed((GSource *)get_client)) + g_source_destroy((GSource *)get_client); } -- 2.7.4 From c3fe3c277f2a1c8beaa0734756acc87d543e996c Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 17 Dec 2019 09:50:11 +0900 Subject: [PATCH 11/16] Change DPMS_GET_TIMEOUT to 5 seconds Change-Id: I892308efa4c6c4cecdca9b5f1361d590e48ab660 Signed-off-by: Youngjae Cho --- src/display/display-dpms.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c index 0a6cbed..6b727d7 100644 --- a/src/display/display-dpms.c +++ b/src/display/display-dpms.c @@ -29,7 +29,7 @@ #include "display/util.h" #include "display/display-dpms.h" -#define DPMS_GET_TIMEOUT 10 /* milisecond */ +#define DPMS_GET_TIMEOUT 5 /* second */ typedef struct { GSource gsource; @@ -447,7 +447,7 @@ int dpms_get_state(void) wl_display_flush(get_client->wl_disp); // Set a response timeout - timeout = g_timeout_source_new(DPMS_GET_TIMEOUT); + timeout = g_timeout_source_new_seconds(DPMS_GET_TIMEOUT); g_source_set_callback(timeout, dpms_loop_quit, NULL, NULL); g_source_attach(timeout, dpms_context); @@ -459,10 +459,12 @@ int dpms_get_state(void) g_source_destroy(timeout); g_source_unref(timeout); - if (dpms_get_state_done) + if (dpms_get_state_done) { return (int)get_client->dpms_mode; - else + } else { + _E("No DPMS response for %d seconds.", DPMS_GET_TIMEOUT); return -ETIMEDOUT; + } } /* -- 2.7.4 From 3354cf2dc7c24c3cdab0c3cab17abc5b2c366dde Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 19 Dec 2019 07:18:43 +0000 Subject: [PATCH 12/16] Revert "Safe umount an sdcard partition (/opt/media/SDCardA1)" This reverts commit bf9160eaaae561158273f08316da80c857960286. Change-Id: Ia8c827d76ed4710891a27c0c97c938ca33353905 --- src/power-shutdown/shutdown.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/power-shutdown/shutdown.c b/src/power-shutdown/shutdown.c index b292719..ddf899e 100644 --- a/src/power-shutdown/shutdown.c +++ b/src/power-shutdown/shutdown.c @@ -46,7 +46,6 @@ enum { CMD_EXIT, }; -#define UMOUNT_RW_PATH_SDCARD "/opt/media/SDCardA1" #define UMOUNT_RW_PATH_USER "/opt/usr" #define UMOUNT_RW_PATH_SYSTEM "/opt" #define MAX_UMOUNT_KILL_RETRY 4 @@ -61,7 +60,6 @@ static int usage(void) static void umount_partitions(void) { - umount_partition_by_kill(UMOUNT_RW_PATH_SDCARD, MAX_UMOUNT_KILL_RETRY); umount_partition_by_kill(UMOUNT_RW_PATH_USER, MAX_UMOUNT_KILL_RETRY); umount_partition_by_kill(UMOUNT_RW_PATH_SYSTEM, MAX_UMOUNT_KILL_RETRY); } -- 2.7.4 From 75f1c607c4056424d7052c78e3f2524ea89111be Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 26 Dec 2019 21:33:09 +0900 Subject: [PATCH 13/16] Add deviced header in deviced.pc for product plugin modules BuildRequires: pkgconfig(deviced) Change-Id: I250f5780b646dd9b56d48b607a531249a8dbe62a Signed-off-by: Hyotaek Shim --- CMakeLists.txt | 4 ++++ packaging/deviced.spec | 1 + 2 files changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3721a6a..9268842 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -258,6 +258,10 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/deviced/ DESTINATION include/$ PATTERN "*_doc.h" EXCLUDE PATTERN "*.h") +INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/core/ DESTINATION include/${PROJECT_NAME}/core + FILES_MATCHING + PATTERN "*.h") + IF(BATTERY_MODULE STREQUAL on) INSTALL_CONF(conf battery) ENDIF() diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 87b1f68..53f2023 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -269,6 +269,7 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %files -n libdeviced-devel %defattr(-,root,root,-) %{_includedir}/deviced/*.h +%{_includedir}/deviced/core/*.h %{_libdir}/libdeviced.so %{_libdir}/pkgconfig/deviced.pc -- 2.7.4 From 01594655b358b871ad8beca387e41399c659a768 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 27 Dec 2019 14:52:36 +0900 Subject: [PATCH 14/16] Add /shared/.h files in deviced.pc Change-Id: I93b5166b898f54122e295ebbb93441b600be702f Signed-off-by: Hyotaek Shim --- CMakeLists.txt | 4 ++++ packaging/deviced.spec | 1 + 2 files changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9268842..315b542 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -262,6 +262,10 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/core/ DESTINATION include/${PR FILES_MATCHING PATTERN "*.h") +INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/shared/ DESTINATION include/${PROJECT_NAME}/shared + FILES_MATCHING + PATTERN "*.h") + IF(BATTERY_MODULE STREQUAL on) INSTALL_CONF(conf battery) ENDIF() diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 53f2023..cd1c67b 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -270,6 +270,7 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %defattr(-,root,root,-) %{_includedir}/deviced/*.h %{_includedir}/deviced/core/*.h +%{_includedir}/deviced/shared/*.h %{_libdir}/libdeviced.so %{_libdir}/pkgconfig/deviced.pc -- 2.7.4 From 3490c80e75a0c31ab0c09144c23906a7830e28fc Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 27 Dec 2019 15:01:06 +0900 Subject: [PATCH 15/16] Watchdog timeout 90 -> 30 sec to reduce delay from unexpected poweroff failure Change-Id: Ib86c4507fd127e046958ea63083500dcabdce881 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 1b0220f..e8d7218 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -331,7 +331,8 @@ static gboolean poweroff_timeout_cb(void *data) goto out; } - watchdog_notify(); + // Watchdog timeout 90 -> 30 sec to reduce delay from unexpected poweroff failure. + sd_notify(0, "WATCHDOG_USEC=%llu", (unsigned long long)POWEROFF_WAIT_SYSTEMD_MS*1000); make_power_flag(poweroff_opt.type, poweroff_opt.option); -- 2.7.4 From 1f29eaefef7fa5b6db5f70bc6aac07f76ffb824c Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 27 Dec 2019 15:22:54 +0900 Subject: [PATCH 16/16] Add a dbus policy rule for /csa partition Change-Id: I1e31836a350e14e1c5efa100493c5df15c3aa2d4 Signed-off-by: Hyotaek Shim --- conf/org.tizen.system.deviced.conf | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/conf/org.tizen.system.deviced.conf b/conf/org.tizen.system.deviced.conf index aa4a653..fb3076f 100644 --- a/conf/org.tizen.system.deviced.conf +++ b/conf/org.tizen.system.deviced.conf @@ -53,6 +53,8 @@ privilege="http://tizen.org/privilege/led"/> + @@ -76,7 +78,7 @@ -