From bd3264a548c708c55527aecbef36e20ed166b4af Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Thu, 28 Feb 2019 08:16:03 +0900 Subject: [PATCH 01/16] auto-test: battery: fix bug Change-Id: Iea6d5dd82f705585b0ffd1d4c9f279148fdae287 Signed-off-by: sanghyeok.oh --- src/auto-test/battery.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/auto-test/battery.c b/src/auto-test/battery.c index f9b9920..4ef6fe8 100644 --- a/src/auto-test/battery.c +++ b/src/auto-test/battery.c @@ -283,7 +283,7 @@ static bool get_battery_health() static bool get_battery_info() { GVariant *msg; - int val[6]; + int val[9]; bool ret = FALSE; char *argv[3]; @@ -313,7 +313,10 @@ static bool get_battery_info() if (val[0] < 0) { _E("Failed to call dbus method(%s): Return fail", METHOD_BATTERY_GETINFO); } else { - _I("Success: %s %s %s %d %d %d %d %d", argv[0], argv[1], argv[2], val[1], val[2], val[3], val[4], val[5]); + _I("Success: %s %s %s %d %d %d %d %d %d %d %d", + argv[0], argv[1], argv[2], val[1], val[2], + val[3], val[4], val[5], val[6], val[7], + val[8]); ret = TRUE; } g_free(argv[0]); -- 2.7.4 From caff30dc3147865452d0300a3a468343191714ef Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Wed, 27 Feb 2019 11:31:45 +0900 Subject: [PATCH 02/16] power: remove duplicated dbus methods Change-Id: Ib4b1b94559cf702a1f6823414a5379861146cb8e Signed-off-by: sanghyeok.oh --- conf/org.tizen.system.deviced.conf | 2 +- src/auto-test/power.c | 30 +++++++++++------------------- src/devicectl/devicectl.c | 2 +- src/libdeviced/deviced-noti.c | 8 ++++---- src/power/power-handler.c | 33 +++++---------------------------- 5 files changed, 22 insertions(+), 53 deletions(-) diff --git a/conf/org.tizen.system.deviced.conf b/conf/org.tizen.system.deviced.conf index f8c03e0..49877ee 100644 --- a/conf/org.tizen.system.deviced.conf +++ b/conf/org.tizen.system.deviced.conf @@ -33,7 +33,7 @@ privilege="http://tizen.org/privilege/display"/> - diff --git a/src/auto-test/power.c b/src/auto-test/power.c index 6f0eeef..a2c2a78 100644 --- a/src/auto-test/power.c +++ b/src/auto-test/power.c @@ -17,13 +17,12 @@ */ #include "test.h" -#define METHOD_REBOOT "reboot" -#define METHOD_REBOOTWITHOPTION "RebootWithOption" -#define METHOD_REBOOT2 "Reboot" +#define METHOD_POWEROFF "Poweroff" +#define METHOD_POWEROFF_WITH_OPTION "PoweroffWithOption" -#define METHOD_LOWPOWER_START "Start" -#define METHOD_LOWPOWER_STOP "Stop" -#define METHOD_LOWPOWER_GETSTATE "GetState" +#define METHOD_LOWPOWER_START "Start" +#define METHOD_LOWPOWER_STOP "Stop" +#define METHOD_LOWPOWER_GETSTATE "GetState" static bool set_reboot_method(const char *method, GVariant *param) { @@ -32,8 +31,8 @@ static bool set_reboot_method(const char *method, GVariant *param) bool ret = FALSE; msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, - DEVICED_PATH_REBOOT, - DEVICED_INTERFACE_REBOOT, + DEVICED_PATH_POWEROFF, + DEVICED_INTERFACE_POWEROFF, method, param); if (!msg) { @@ -61,17 +60,12 @@ static bool set_reboot_method(const char *method, GVariant *param) static bool set_reboot(char *type) { - return set_reboot_method(METHOD_REBOOT, g_variant_new("(si)", type, 0)); + return set_reboot_method(METHOD_POWEROFF, g_variant_new("(s)", type)); } static bool set_reboot_with_option(char *type, char *option) { - return set_reboot_method(METHOD_REBOOTWITHOPTION, g_variant_new("(ss)", type, option)); -} - -static bool set_Reboot() -{ - return set_reboot_method(METHOD_REBOOT2, g_variant_new("(s)", "not_used")); + return set_reboot_method(METHOD_POWEROFF_WITH_OPTION, g_variant_new("(ss)", type, option)); } static bool request_lowpower_method(const char *method, GVariant *param) @@ -171,12 +165,10 @@ static int power_unit(int argc, char **argv) _I("start test"); lowpower_test_all(&success, &fail); _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail); - } else if (0 == strcmp(argv[3], METHOD_REBOOT)) + } else if (0 == strcmp(argv[3], METHOD_POWEROFF)) set_reboot(argv[4]); - else if (0 == strcasecmp(argv[3], METHOD_REBOOTWITHOPTION)) + else if (0 == strcasecmp(argv[3], METHOD_POWEROFF_WITH_OPTION)) set_reboot_with_option(argv[4], argv[5]); - else if (0 == strcmp(argv[3], METHOD_REBOOT2)) - set_Reboot(); else if (0 == strcasecmp(argv[3], "lowpower")) { if (0 == strcasecmp(argv[4], METHOD_LOWPOWER_START)) set_lowpower_start(); diff --git a/src/devicectl/devicectl.c b/src/devicectl/devicectl.c index 4b820d5..04d5093 100644 --- a/src/devicectl/devicectl.c +++ b/src/devicectl/devicectl.c @@ -57,7 +57,7 @@ static const struct device { { DEVICE_PASS, "pass", DEVICED_PATH_PASS, DEVICED_INTERFACE_PASS }, { DEVICE_USB, "usb", DEVICED_PATH_USB, DEVICED_INTERFACE_USB }, { DEVICE_EXTCON, "extcon", DEVICED_PATH_EXTCON, DEVICED_INTERFACE_EXTCON }, - { DEVICE_POWER, "power", DEVICED_PATH_REBOOT, DEVICED_INTERFACE_REBOOT }, + { DEVICE_POWER, "power", DEVICED_PATH_POWEROFF, DEVICED_INTERFACE_POWEROFF }, { DEVICE_USB_HOST_TEST, "usb-host-test", DEVICED_PATH_USB_HOST_TEST, DEVICED_INTERFACE_USB_HOST_TEST}, }; diff --git a/src/libdeviced/deviced-noti.c b/src/libdeviced/deviced-noti.c index 5741fe6..f02f5e8 100644 --- a/src/libdeviced/deviced-noti.c +++ b/src/libdeviced/deviced-noti.c @@ -114,10 +114,10 @@ static int dbus_power_handler(char* type) int val; msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, - DEVICED_PATH_REBOOT, - DEVICED_INTERFACE_REBOOT, - type, - g_variant_new("(si)", type, 0)); + DEVICED_PATH_POWEROFF, + DEVICED_INTERFACE_POWEROFF, + "Poweroff", + g_variant_new("(s)", type)); if (!msg) return -EBADMSG; diff --git a/src/power/power-handler.c b/src/power/power-handler.c index b4f3581..e07f18f 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -544,7 +544,7 @@ static GVariant *dbus_power_handler(GDBusConnection *conn, int ret; char *type_str; - g_variant_get(param, "(si)", &type_str, NULL); + g_variant_get(param, "(s)", &type_str); ret = check_sender_process(conn, sender); if (ret < 0) @@ -580,27 +580,6 @@ out: return g_variant_new("(i)", ret); } -static GVariant *request_reboot(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *str; - int ret; - - g_variant_get(param, "(s)", &str); - - ret = check_sender_process(conn, sender); - if (ret < 0) - goto out; - - _I("Poweroff PID(%d) requests reboot with command(%s).", ret, str); - ret = power_execute_pid(POWER_REBOOT, NULL); - -out: - g_free(str); - return g_variant_new("(i)", ret); -} - static GVariant *add_poweroff_time(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) @@ -689,10 +668,9 @@ out: } static const dbus_method_s dbus_methods[] = { - { POWER_REBOOT, "si", "i", dbus_power_handler }, - { "RebootWithOption", "ss", "i", dbus_power_option_handler }, + { "Poweroff", "s", "i", dbus_power_handler }, + { "PoweroffWithOption", "ss", "i", dbus_power_option_handler }, /* Public API device_power_reboot() calls this dbus method. */ - { "Reboot", "s", "i", request_reboot }, { "AddPoweroffWait", NULL, "i", add_poweroff_time }, { "RemovePoweroffWait", NULL, "i", remove_poweroff_time }, /* Add methods here */ @@ -700,7 +678,7 @@ static const dbus_method_s dbus_methods[] = { static const dbus_interface_u dbus_interface = { .oh = NULL, - .name = DEVICED_INTERFACE_REBOOT, + .name = DEVICED_INTERFACE_POWEROFF, .methods = dbus_methods, .nr_methods = ARRAY_SIZE(dbus_methods), }; @@ -773,7 +751,7 @@ static void power_init(void *data) int ret; /* init dbus interface */ - ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_REBOOT, &dbus_interface); + ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_POWEROFF, &dbus_interface); if (ret < 0) _E("Failed to init dbus method: %d", ret); @@ -784,7 +762,6 @@ static void power_init(void *data) add_poweroff_option(POWEROFF_TYPE_POWEROFF, NULL); add_poweroff_option(POWEROFF_TYPE_RESTART, NULL); add_poweroff_option(POWEROFF_TYPE_POPUP, NULL); - add_poweroff_option(POWEROFF_TYPE_RESTART, NULL); ret = config_parse(POWER_CONF_FILE, load_config, NULL); if (ret < 0) -- 2.7.4 From f4f03d3fc9c2e779567760bb3f82138a5a72e033 Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Tue, 5 Mar 2019 20:28:42 +0900 Subject: [PATCH 03/16] power: change to case-sensitive name Change-Id: I98b61040294f367a96674b7b02e2bf68fb8cc115 Signed-off-by: sanghyeok.oh --- src/auto-test/power.c | 4 ++-- src/libdeviced/deviced-noti.c | 2 +- src/power/power-handler.c | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/auto-test/power.c b/src/auto-test/power.c index a2c2a78..96a6a85 100644 --- a/src/auto-test/power.c +++ b/src/auto-test/power.c @@ -17,8 +17,8 @@ */ #include "test.h" -#define METHOD_POWEROFF "Poweroff" -#define METHOD_POWEROFF_WITH_OPTION "PoweroffWithOption" +#define METHOD_POWEROFF "PowerOff" +#define METHOD_POWEROFF_WITH_OPTION "PowerOffWithOption" #define METHOD_LOWPOWER_START "Start" #define METHOD_LOWPOWER_STOP "Stop" diff --git a/src/libdeviced/deviced-noti.c b/src/libdeviced/deviced-noti.c index f02f5e8..c244a15 100644 --- a/src/libdeviced/deviced-noti.c +++ b/src/libdeviced/deviced-noti.c @@ -116,7 +116,7 @@ static int dbus_power_handler(char* type) msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, DEVICED_PATH_POWEROFF, DEVICED_INTERFACE_POWEROFF, - "Poweroff", + "PowerOff", g_variant_new("(s)", type)); if (!msg) return -EBADMSG; diff --git a/src/power/power-handler.c b/src/power/power-handler.c index e07f18f..8422fa5 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -668,11 +668,11 @@ out: } static const dbus_method_s dbus_methods[] = { - { "Poweroff", "s", "i", dbus_power_handler }, - { "PoweroffWithOption", "ss", "i", dbus_power_option_handler }, + { "PowerOff", "s", "i", dbus_power_handler }, + { "PowerOffWithOption", "ss", "i", dbus_power_option_handler }, /* Public API device_power_reboot() calls this dbus method. */ - { "AddPoweroffWait", NULL, "i", add_poweroff_time }, - { "RemovePoweroffWait", NULL, "i", remove_poweroff_time }, + { "AddPowerOffWait", NULL, "i", add_poweroff_time }, + { "RemovePowerOffWait", NULL, "i", remove_poweroff_time }, /* Add methods here */ }; @@ -715,7 +715,7 @@ static int load_config(struct parse_result *result, void *user_data) enum poweroff_type type; int ret; - if (MATCH(result->section, "Poweroff")) + if (MATCH(result->section, "PowerOff")) type = POWEROFF_TYPE_DIRECT; else if (MATCH(result->section, "Reboot")) type = POWEROFF_TYPE_RESTART; -- 2.7.4 From 1428872df9b4bc04d9a59d09d4a310e12bc2b667 Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Tue, 5 Mar 2019 21:04:20 +0900 Subject: [PATCH 04/16] svace: power-shutdown: fix leak Change-Id: Ieadd4f8a25c78775877847a065d811d4d83a5314 Signed-off-by: sanghyeok.oh --- src/power-shutdown/shutdown.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/power-shutdown/shutdown.c b/src/power-shutdown/shutdown.c index bc4bd0d..9c6032d 100644 --- a/src/power-shutdown/shutdown.c +++ b/src/power-shutdown/shutdown.c @@ -85,8 +85,8 @@ static void autoboot(void) if (ret < 0) { ret = -errno; printf("%s: fail to read reboot data(%d)\n", progname, ret); - } else - close(fd); + } + close(fd); } printf("%s: reboot param is <%s>\n", progname, buf); -- 2.7.4 From 7cdbffb6ff2a97820be590041632f94af6d53ff0 Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Mon, 11 Mar 2019 14:56:27 +0900 Subject: [PATCH 05/16] power: re-enable exit option Change-Id: I7aca911ea44c1e896c06d504e888cf1544363afa Signed-off-by: sanghyeok.oh --- 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 8422fa5..1dbbbb8 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -201,7 +201,7 @@ static void poweroff_request_shutdown() method = "Reboot"; else if (poweroff_opt.type == POWEROFF_TYPE_POWEROFF) method = "PowerOff"; - else if (poweroff_opt.type == POWEROFF_TYPE_RESTART) + else if (poweroff_opt.type == POWEROFF_TYPE_EXIT) method = "Exit"; else { _E("Poweroff invalid type(%d).", poweroff_opt.type); @@ -762,6 +762,7 @@ static void power_init(void *data) add_poweroff_option(POWEROFF_TYPE_POWEROFF, NULL); add_poweroff_option(POWEROFF_TYPE_RESTART, NULL); add_poweroff_option(POWEROFF_TYPE_POPUP, NULL); + add_poweroff_option(POWEROFF_TYPE_EXIT, NULL); ret = config_parse(POWER_CONF_FILE, load_config, NULL); if (ret < 0) -- 2.7.4 From aafdb5fb6ae0eca5676b633efe683e6cfb9f36f0 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Wed, 6 Mar 2019 15:06:52 +0900 Subject: [PATCH 06/16] Support plugin module. Deviced will load "/usr/lib/deviced/*.so". If someone wants to add their own device, make plugin with DEVICE_PRIORITY_HIGH and place it in the lib folder. Change-Id: I58b95b55a4c297c93b4f1e5bb17c9927d8d5d3c4 Signed-off-by: Yunmi Ha --- src/core/main.c | 2 ++ src/shared/plugin.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 3 deletions(-) mode change 100644 => 100755 src/shared/plugin.c diff --git a/src/core/main.c b/src/core/main.c index 0ff129b..31d835d 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -126,6 +126,8 @@ static int deviced_main(int argc, char **argv) g_main_loop_unref(mainloop); devices_exit(NULL); + unload_plugins(); + return 0; } diff --git a/src/shared/plugin.c b/src/shared/plugin.c old mode 100644 new mode 100755 index 72f291d..bcca658 --- a/src/shared/plugin.c +++ b/src/shared/plugin.c @@ -37,9 +37,10 @@ #ifndef LIBPATH #error LIBPATH is not defined. #endif -#define MODULE_PATH LIBPATH"/deviced" +#define MODULE_PATH LIBPATH"/deviced/" struct display_plugin disp_plgn; +GList *plgn_list; int load_plugin(const char *id, void **h) { @@ -52,7 +53,7 @@ int load_plugin(const char *id, void **h) } /* Find matched module path */ - snprintf(path, sizeof(path), "%s/%s.so", MODULE_PATH, id); + snprintf(path, sizeof(path), "%s%s", MODULE_PATH, id); if (access(path, R_OK) != 0) { _E("There is no %s device", id); return -ENODEV; @@ -80,7 +81,45 @@ int unload_plugin(void *h) void load_plugins() { - load_plugin("display", &disp_plgn.handle); + DIR *dir; + void *handle = NULL; + struct dirent *ent; + + if ((dir = opendir(MODULE_PATH)) == NULL) { + _I("There is no plugin."); + return ; + } + + while ((ent = readdir(dir)) != NULL) { + // skip (/.)(/..)(.so) + if (strlen(ent->d_name) < 4) + continue; + + if (strcmp((ent->d_name + strlen(ent->d_name)-3), ".so")) + continue; + + if (!load_plugin(ent->d_name, &handle)) { + _I("Plugin(%s) is loaded. handle=0x%x", ent->d_name, (unsigned int)handle); + plgn_list = g_list_append(plgn_list, handle); + if (!strncmp(ent->d_name, "display", strlen("display"))) + disp_plgn.handle = handle; + } + } + closedir(dir); return; } + +void unload_plugins() +{ + GList *plugin = plgn_list; + void *handle = NULL; + + for ( ; plugin != NULL; plugin = g_list_next(plugin)) { + handle = (void *)plugin->data; + _I("Plugin(0x%x) is unloaded.", (unsigned int)handle); + unload_plugin(handle); + } + + g_list_free(plgn_list); +} -- 2.7.4 From 095b8f131203e28fee52706521fa92b98a8961ca Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Thu, 14 Mar 2019 19:29:07 +0900 Subject: [PATCH 07/16] coverity fix Change-Id: I20c613f763a46473d0ed3eb4f12bf8d6cc014e98 Signed-off-by: sanghyeok.oh --- src/tzip/tzip-utility.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/tzip/tzip-utility.c b/src/tzip/tzip-utility.c index 4a2ca5f..a958023 100644 --- a/src/tzip/tzip-utility.c +++ b/src/tzip/tzip-utility.c @@ -155,17 +155,16 @@ static void fileinfo_to_stat(unz_file_info *file_info, struct stat *file_stat, m static int add_path_dirs_info(struct tzip_mount_entry *entry, const char *path, unz_file_info *file_info, mode_t mode) { - char *dir; - char *cpy_path; - char *next_dir; - char *parent_dir; - char *save_ptr; + char *dir = NULL; + char *cpy_path = NULL; + char *next_dir = NULL; + char *parent_dir = NULL; + char *save_ptr = NULL; int ret = 0; if (!strchr(path, '/')) { /* file or directory in root directory */ - ret = add_dir_info(entry, ".", path, file_info, mode); - return ret; + return add_dir_info(entry, ".", path, file_info, mode); } /* add info about each directory in path */ parent_dir = malloc(strlen(path) + 1); @@ -177,16 +176,27 @@ static int add_path_dirs_info(struct tzip_mount_entry *entry, const char *path, /* needed copy, because of strtok_r modify cstring */ cpy_path = strndup(path, strlen(path) + 1); if (!cpy_path) { - free(parent_dir); _E("Failed to malloc."); - return -ENOMEM; + ret = -ENOMEM; + goto err; } dir = strtok_r(cpy_path, "/", &save_ptr); + if (dir == NULL) { + _E("Failed to strtok_r."); + ret = -EINVAL; + goto err; + } ret = add_dir_info(entry, ".", dir, file_info, S_IFDIR); strncpy(parent_dir, dir, strlen(dir) + 1); dir = strtok_r(NULL, "/", &save_ptr); + if (dir == NULL) { + _E("Failed to strtok_r."); + ret = -EINVAL; + goto err; + } + next_dir = strtok_r(NULL, "/", &save_ptr); while (next_dir && !ret) { @@ -197,13 +207,9 @@ static int add_path_dirs_info(struct tzip_mount_entry *entry, const char *path, next_dir = strtok_r(NULL, "/", &save_ptr); } - if (ret) { - free(cpy_path); - free(parent_dir); - return ret; - } - - ret = add_dir_info(entry, parent_dir, dir, file_info, mode); + if (!ret) + ret = add_dir_info(entry, parent_dir, dir, file_info, mode); +err: free(cpy_path); free(parent_dir); -- 2.7.4 From 8bcbd2e65b860ebc74c144636faa43c7fe24fab7 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 15 Mar 2019 10:49:42 +0900 Subject: [PATCH 08/16] Reorganize cool-down structure Cool-down algorithm is changed as below. 1. Cool-down is changed from broadcasting signal to sending dbus method. 2. Deviced don't have to request pop-ups to system-servant. Because SIOP or PASS will do it according to it's own scenarios. Change-Id: I8cf6c949911533c77620dd38087836b4eaaf36f8 Signed-off-by: lokilee73 --- CMakeLists.txt | 5 - conf/temperature.conf | 6 - conf/wearable-temperature.conf | 6 - packaging/deviced.spec | 5 - src/shared/plugin.h | 2 +- src/thermal/thermal.c | 457 +++++++++++++++-------------------------- src/thermal/thermal.h | 41 ++-- 7 files changed, 184 insertions(+), 338 deletions(-) delete mode 100644 conf/temperature.conf delete mode 100644 conf/wearable-temperature.conf diff --git a/CMakeLists.txt b/CMakeLists.txt index 67e2d8a..472aebe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -246,11 +246,6 @@ IF(POWER_MODULE STREQUAL on) INSTALL_CONF(conf power) ENDIF() -IF(THERMAL_MODULE STREQUAL on) - INSTALL_CONF(conf temperature) - INSTALL_CONF(conf wearable-temperature) -ENDIF() - # USB connection IF(USB_MODULE STREQUAL on) # USB (Manual setting) diff --git a/conf/temperature.conf b/conf/temperature.conf deleted file mode 100644 index db8a158..0000000 --- a/conf/temperature.conf +++ /dev/null @@ -1,6 +0,0 @@ -[THERMAL] -#Level is Celsius -Normal=70 -Warning=75 -Limit=80 -Shutdown=85 diff --git a/conf/wearable-temperature.conf b/conf/wearable-temperature.conf deleted file mode 100644 index ceb68b2..0000000 --- a/conf/wearable-temperature.conf +++ /dev/null @@ -1,6 +0,0 @@ -[THERMAL] -#Level is Celsius -Normal=44 -Warning=46 -Limit=48 -Shutdown=53 diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 91a1bc8..a08c88a 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -215,7 +215,6 @@ mv %{_libdir}/mobile-display.so %{_libdir}/deviced/display.so mv %{_sysconfdir}/deviced/wearable-display.conf %{_sysconfdir}/deviced/display.conf mkdir -p %{_libdir}/deviced mv %{_libdir}/wearable-display.so %{_libdir}/deviced/display.so -mv %{_sysconfdir}/deviced/wearable-temperature.conf %{_sysconfdir}/deviced/temperature.conf %post plugin-profile-tv mkdir -p %{_libdir}/deviced @@ -283,7 +282,6 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %license LICENSE.Apache-2.0 %defattr(-,root,root,-) %config %{_sysconfdir}/deviced/mobile-display.conf -%config %{_sysconfdir}/deviced/temperature.conf %{_libdir}/mobile-display.so %files plugin-profile-wearable @@ -291,7 +289,6 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %license LICENSE.Apache-2.0 %defattr(-,root,root,-) %config %{_sysconfdir}/deviced/wearable-display.conf -%config %{_sysconfdir}/deviced/wearable-temperature.conf %{_libdir}/wearable-display.so %files plugin-profile-tv @@ -299,7 +296,6 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %license LICENSE.Apache-2.0 %defattr(-,root,root,-) %config %{_sysconfdir}/deviced/display.conf -%config %{_sysconfdir}/deviced/temperature.conf %{_libdir}/tv-display.so %files plugin-profile-iot @@ -307,5 +303,4 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %license LICENSE.Apache-2.0 %defattr(-,root,root,-) %config %{_sysconfdir}/deviced/display.conf -%config %{_sysconfdir}/deviced/temperature.conf %{_libdir}/iot-display.so diff --git a/src/shared/plugin.h b/src/shared/plugin.h index ba9c633..488589c 100644 --- a/src/shared/plugin.h +++ b/src/shared/plugin.h @@ -22,5 +22,5 @@ int load_plugin(const char *id, void **h); int unload_plugin(void *h); void load_plugins(); - +void unload_plugins(); #endif /* __DD_PLUGIN_H__ */ diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c index 78195e9..ca8e1d9 100644 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -22,326 +22,245 @@ #include #include +#include #include "apps/apps.h" #include "core/devices.h" #include "core/log.h" #include "core/device-notifier.h" #include "core/devices.h" +#include "display/display-ops.h" +#include "battery/power-supply.h" +#include "power/power-handler.h" #include "thermal.h" -#include "core/config-parser.h" static struct thermal_device *thermal_dev; -static int noti; +static int cool_down_level = COOL_DOWN_NONE_INIT; +static guint shut_down_timer; -#define THERMAL_CONF_FILE "/etc/deviced/temperature.conf" - -static struct thermal_config_info thermal_table = { - .normal = TEMPERATURE_NORMAL, - .warning = TEMPERATURE_WARNING, - .limit = TEMPERATURE_LIMIT, - .shutdown = TEMPERATURE_SHUTDOWN -}; - -static int power_off(void) +static int booting_done(void *data) { - const struct device_ops *power; + static int done; - power = find_device("power"); - if (check_default(power)) - return -ENODEV; + if (data == NULL) + return done; - return power->execute("poweroff"); + done = *(int *)data; + if (done == 0) + return done; + + _I("Booting done."); + return done; } -static void thermal_remove_noti(void) +static int get_action_id(char *string) { - int ret = 0; + int temp = COOL_DOWN_NONE_INIT; - if (noti) { - ret = remove_notification("TempCooldownNotiOff", noti); - if (ret < 0) - _E("Failed to remove cooldown noti(%d).", noti); - else - noti = 0; + if (!string) { + _E("Invalid temp level"); + return temp; } + + if (!strncmp(string, RELEASE_ACTION, strlen(RELEASE_ACTION))) + temp = COOL_DOWN_RELEASE; + else if (!strncmp(string, WARNING_ACTION, strlen(WARNING_ACTION))) + temp = COOL_DOWN_WARNING_ACTION; + else if (!strncmp(string, LIMIT_ACTION, strlen(LIMIT_ACTION))) + temp = COOL_DOWN_LIMIT_ACTION; + else if (!strncmp(string, SHUTDOWN_ACTION, strlen(SHUTDOWN_ACTION))) + temp = COOL_DOWN_SHUT_DOWN; + else + temp = -EINVAL; + + return temp; } -static void thermal_remove_popup(void) +void cool_down_wakeup(int level) { - int temp; - - temp = launch_system_app(APP_DEFAULT, 2, - APP_KEY_TYPE, "remove_cooldown_popups"); - if (temp < 0) - _E("Failed to launch remove_cooldown_popups."); + if (level >= COOL_DOWN_LIMIT_ACTION || battery.health == HEALTH_BAD) { + _D("Dim."); + if (disp_plgn.pm_change_internal) + disp_plgn.pm_change_internal(INTERNAL_LOCK_COOL_DOWN, LCD_DIM); + } else { + _D("Normal."); + if (disp_plgn.pm_change_internal) + disp_plgn.pm_change_internal(INTERNAL_LOCK_COOL_DOWN, LCD_NORMAL); + } } -static void thermal_noti_cb(GVariant *var, void *user_data, GError *err) +void cool_down_release(void) { - int id = 0; + device_notify(DEVICE_NOTIFIER_COOL_DOWN, (void *)&cool_down_level); +} - if (!var) { - if (err) - _E("%s", err->message); - return; - } +void cool_down_warning(void) +{ + device_notify(DEVICE_NOTIFIER_COOL_DOWN, (void *)&cool_down_level); +} - if (!dh_get_param_from_var(var, "(i)", &id)) { - _E("Failed to get var(%s): no message", g_variant_get_type_string(var)); - goto out; +void cool_down_limit(void) +{ + if (disp_plgn.pm_lock_internal) { + disp_plgn.pm_lock_internal(INTERNAL_LOCK_COOL_DOWN, LCD_DIM, STAY_CUR_STATE, 65000); + disp_plgn.pm_lock_internal(INTERNAL_LOCK_COOL_DOWN, LCD_OFF, STAY_CUR_STATE, 65000); } - noti = id; - _D("Thermal noti(%d).", noti); - -out: - g_variant_unref(var); + device_notify(DEVICE_NOTIFIER_COOL_DOWN, (void *)&cool_down_level); } -static void thermal_add_noti(void) +void cool_down_poweroff(void) { - int ret = 0; - - thermal_remove_noti(); - if (!noti) { - ret = add_async_notification("TempCooldownNotiOn", thermal_noti_cb, NULL, NULL); - if (ret < 0) - _E("Failed to show notification for temperature."); + if (disp_plgn.pm_change_internal) + disp_plgn.pm_change_internal(INTERNAL_LOCK_COOL_DOWN, LCD_DIM); + if (disp_plgn.pm_lock_internal) { + disp_plgn.pm_lock_internal(INTERNAL_LOCK_COOL_DOWN, LCD_DIM, STAY_CUR_STATE, 30000); + disp_plgn.pm_lock_internal(INTERNAL_LOCK_COOL_DOWN, LCD_OFF, STAY_CUR_STATE, 30000); } + + device_notify(DEVICE_NOTIFIER_COOL_DOWN, (void *)&cool_down_level); } -static void broadcast_thermal_state_legacy(const char *action_type) +static int power_execute(void *data) { - if (!action_type) { - _E("Invalid action type."); - return; - } + static const struct device_ops *ops; - _D("action_type = %s", action_type); - dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_SYSNOTI, - DEVICED_INTERFACE_SYSNOTI, - "CoolDownChanged", - g_variant_new("(s)", action_type)); + FIND_DEVICE_INT(ops, POWER_OPS_NAME); + + return ops->execute(data); } -static gboolean thermal_overheat_time_broadcast(void *data) +static gboolean shut_down_timer_cb(void *data) { int ret; - static int time = OVERHEAT_POWEROFF_TIME; - /* Transfer Time by Signal */ - ret = dbus_handle_broadcast_dbus_signal_var(POPUP_OVERHEAT_PATH, POPUP_OVERHEAT_INTERFACE, - SIGNAL_OVERHEAT_TIME, g_variant_new("(i)", time)); - if (ret < 0) - _E("Failed in updating overheat time."); - - time -= 1; - if (time < 0) { - time = OVERHEAT_POWEROFF_TIME; - ret = launch_system_app(APP_OVERHEAT, 2, - APP_KEY_TYPE, "remove_overheat_popups"); - if (ret < 0) - _E("Failed to remove overheat popups."); - - ret = power_off(); - if (ret < 0) - _E("Failed to power off."); - return G_SOURCE_REMOVE; - } else - return G_SOURCE_CONTINUE; + shut_down_timer = 0; + ret = power_execute(POWER_POWEROFF); + if (ret != 0) + _E("Failed to request poweroff."); + + return G_SOURCE_REMOVE; } -static void thermal_overheat_popup(void) +void shut_down_timer_stop(void) { - int ret; - guint timer; - - ret = launch_system_app(APP_OVERHEAT, 2, - APP_KEY_TYPE, "overheat"); + if (!shut_down_timer) + return; - if (ret < 0) - _E("Failed to launch overheat popup."); - else { - timer = g_timeout_add_seconds(OVERHEAT_CALLBACK_TIME, thermal_overheat_time_broadcast, NULL); - if (!timer) - _E("Failed to set over temp timer."); - } + g_source_remove(shut_down_timer); + shut_down_timer = 0; + _I("Stop cool down power off."); } -static void thermal_add_recovery_popup(void) +void shut_down_timer_start(void) { - int temp; + if (shut_down_timer) + shut_down_timer_stop(); - temp = launch_system_app(APP_DEFAULT, 2, - APP_KEY_TYPE, "cooled_down"); - if (temp < 0) - _E("Failed to launch recovery popup."); + shut_down_timer = g_timeout_add_seconds( + SHUTDOWN_FORCE_WAIT, + shut_down_timer_cb, NULL); } -static void thermal_action(int state) +static int cool_down_execute(int state) { - char *action = NULL; + int ret; + static int old_state = COOL_DOWN_NONE_INIT; + + cool_down_level = state; + if (vconf_set_int(VCONFKEY_SYSMAN_COOL_DOWN_MODE, cool_down_level) != 0) + _E("Failed to set VCONFKEY_SYSMAN_COOL_DOWN_MODE : %d", cool_down_level); + + if (old_state == cool_down_level) { + if (cool_down_level == COOL_DOWN_SHUT_DOWN) { + _I("Force cool down power off by multiple shutdown request."); + ret = power_execute(POWER_POWEROFF); + if (ret != 0) + _E("Failed to request poweroff."); + } + return 0; + } + + if (!booting_done(NULL)) { + _E("Booting is not done."); + return 0; + } switch (state) { - case NORMAL: - thermal_remove_noti(); - thermal_add_recovery_popup(); - action = strdup(RELEASE_ACTION); + case COOL_DOWN_RELEASE: + shut_down_timer_stop(); + cool_down_release(); break; - case WARNING: + case COOL_DOWN_WARNING_ACTION: + cool_down_warning(); _I("State is WARNING."); - action = strdup(WARNING_ACTION); break; - case LIMIT: - thermal_remove_popup(); - thermal_add_noti(); - action = strdup(LIMIT_ACTION); + case COOL_DOWN_LIMIT_ACTION: + cool_down_limit(); + cool_down_wakeup(COOL_DOWN_LIMIT_ACTION); break; - case SHUTDOWN: - thermal_remove_popup(); - thermal_remove_noti(); - thermal_overheat_popup(); - action = strdup(SHUTDOWN_ACTION); + case COOL_DOWN_SHUT_DOWN: + cool_down_wakeup(COOL_DOWN_SHUT_DOWN); + cool_down_poweroff(); + shut_down_timer_start(); break; - } - - broadcast_thermal_state_legacy(action); - free(action); -} -/* Action Table --------------------------------------------------- -Current Previous Action --------------------------------------------------- -NORMAL NORMAL X - WARNING X - LIMIT ReleaseAction - SHUTDOWN X --------------------------------------------------- -WARNING NORMAL print log - WARNING X - LIMIT X - SHUTDOWN X --------------------------------------------------- -LIMIT NORMAL LimitAction - WARNING LimitAction - LIMIT X - SHUTDOWN X --------------------------------------- -SHUTDOWN NORMAL ShutdownAction - WARNING ShutdownAction - LIMIT ShutdownAction - SHUTDOWN X --------------------------------------------------- -*/ -static bool is_action_needed(int old_state, int new_state) -{ - bool ret = false; - - if (new_state == NORMAL) { - if (old_state == WARNING || old_state == LIMIT) - ret = true; - } else if (new_state == WARNING) { - if (old_state == NORMAL) - ret = true; - } else if (new_state == LIMIT) { - if (old_state == NORMAL || old_state == WARNING) - ret = true; - } else if (new_state == SHUTDOWN) { - if (old_state != SHUTDOWN) - ret = true; + default: + _E("Invalid state : %d", state); } - return ret; -} + _D("Last old_state = %d, new_state = %d", old_state, state); + old_state = state; -static int thermal_get_temp_enum(int temp) -{ - int ret = -1; - - if (temp <= thermal_table.normal) - ret = NORMAL; - else if (temp >= thermal_table.shutdown) - ret = SHUTDOWN; - else if (temp >= thermal_table.limit) - ret = LIMIT; - else if (temp >= thermal_table.warning) - ret = WARNING; - - return ret; + return 0; } -static int thermal_get_average(int temp) +static int check_sender_process(GDBusConnection *conn, const char *sender) { - static int buf[SAMPLE_CNT] = {25, 25, 25, 25}; - static int index = 0; - int i, avg_temp = 0; - - buf[index++] = temp; - index %= SAMPLE_CNT; - - for (i = 0; i < SAMPLE_CNT; i++) - avg_temp += buf[i]; + pid_t pid; - avg_temp /= SAMPLE_CNT; - return avg_temp; -} - -static void thermal_handler(struct thermal_info *info, void *data) -{ - static int old_state = NORMAL; - int avg_temp, new_state; - bool action_needed = false; - - avg_temp = thermal_get_average(info->temp); - new_state = thermal_get_temp_enum(avg_temp); - if (new_state == -1) { - _I("Keep current state: %d", old_state); - return; + if (sender == NULL || g_dbus_is_name(sender) == FALSE) { + _E("Invalid sender."); + return -EINVAL; } - action_needed = is_action_needed(old_state, new_state); - _I("Action=%d old_state=%d new_state=%d", action_needed, old_state, new_state); - if (action_needed) - thermal_action(new_state); - - old_state = new_state; -} - -static int thermal_service_start(void) -{ - int ret; - - if (!thermal_dev) { - _E("Thermal service is not supported."); - return -ENOTSUP; + pid = dbus_connection_get_sender_pid(conn, sender); + if (kill(pid, 0) == -1) { + _E("Process(%d) does not exist, dbus ignored.", pid); + return -ESRCH; } - ret = thermal_dev->register_changed_event(thermal_handler, NULL); - if (ret < 0) - _E("Failed to register thermal event: %d", ret); - - return ret; + return pid; } -static int thermal_service_stop(void) +static GVariant *dbus_cooldown_handler(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) { - int ret; - - if (!thermal_dev) { - _E("Thermal service is not supported."); - return -ENOTSUP; - } + int ret = 0; + int val; + char *string; - ret = thermal_dev->unregister_changed_event(thermal_handler); + g_variant_get(param, "(s)", &string); + _D("Cooldown string : %s", string); + ret = check_sender_process(conn, sender); if (ret < 0) - _E("Failed to unregister thermal event: %d", ret); + goto out; + + val = get_action_id(string); + if (val < 0) { + _E("Invalid value : %d", val); + ret = val; + goto out; + } else + ret = cool_down_execute(val); - return ret; +out: + free(string); + return g_variant_new("(i)", ret); } static GVariant *dbus_get_temperature(GDBusConnection *conn, @@ -368,6 +287,7 @@ exit: static const dbus_method_s dbus_methods[] = { { "GetTemperature", "i", "i", dbus_get_temperature}, + { "ChangedCooldownMode", "s", "i", dbus_cooldown_handler}, /* Add methods here */ }; @@ -378,62 +298,10 @@ static const dbus_interface_u dbus_interface = { .nr_methods = ARRAY_SIZE(dbus_methods), }; -static int booting_done(void *data) -{ - static int done; - - if (data == NULL) - return done; - done = *(int *)data; - if (done == 0) - return done; - - _I("Booting done."); - thermal_service_start(); - - return done; -} - -static int load_config(struct parse_result *result, void *user_data) -{ - struct thermal_config_info *info = user_data; - char *name; - char *value; - - _D("Load config. section=%s name=%s value=%s", result->section, result->name, result->value); - - if (!info) - return -EINVAL; - - if (!MATCH(result->section, "THERMAL")) - return -EINVAL; - - name = result->name; - value = result->value; - if (MATCH(name, "Normal")) - info->normal = atoi(value); - else if (MATCH(name, "Warning")) - info->warning = atoi(value); - else if (MATCH(name, "Limit")) - info->limit = atoi(value); - else if (MATCH(name, "Shutdown")) - info->shutdown = atoi(value); - - return 0; -} - static void thermal_init(void *data) { int ret; - /* load thermal configuration file */ - ret = config_parse(THERMAL_CONF_FILE, load_config, &thermal_table); - if (ret < 0) - _E("Failed to load power off config: %d", ret); - - _I("Temperature conf normal=%d warning=%d limit=%d shutdown=%d", thermal_table.normal, thermal_table.warning, - thermal_table.limit, thermal_table.shutdown); - ret = register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); if (ret < 0) _E("Failed to register booting done notifier."); @@ -441,6 +309,9 @@ static void thermal_init(void *data) ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_TEMPERATURE, &dbus_interface); if (ret < 0) _E("Failed to init dbus method: %d", ret); + + if (vconf_set_int(VCONFKEY_SYSMAN_COOL_DOWN_MODE, COOL_DOWN_NONE_INIT) != 0) + _E("Failed to set VCONFKEY_SYSMAN_COOL_DOWN_MODE : %d", COOL_DOWN_NONE_INIT); } static void thermal_exit(void *data) @@ -450,8 +321,6 @@ static void thermal_exit(void *data) ret = unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); if (ret < 0) _E("Failed to unregister booting done notifier."); - - thermal_service_stop(); } static int thermal_probe(void *data) diff --git a/src/thermal/thermal.h b/src/thermal/thermal.h index 19b8d3b..bb65ed9 100644 --- a/src/thermal/thermal.h +++ b/src/thermal/thermal.h @@ -16,6 +16,14 @@ * limitations under the License. */ +/* Vconf */ +#define VCONFKEY_SYSMAN_COOL_DOWN_MODE "db/private/sysman/cool_down_mode" +#define SHUTDOWN_FORCE_WAIT 30 + +/* Dbus Interfaces */ +#define THERMAL_PATH "/Org/Tizen/System/Pass/Monitor/Thermal" +#define THERMAL_INTERFACE "org.tizen.system.pass.monitor.thermal" +#define THERMAL_METHOD_TEMP_CHANGED "thermal_scenario" /* Action types */ #define RELEASE_ACTION "ReleaseAction" @@ -23,27 +31,18 @@ #define LIMIT_ACTION "LimitAction" #define SHUTDOWN_ACTION "ShutdownAction" -#define SIGNAL_OVERHEAT_TIME "TimeUpdate" -#define OVERHEAT_CALLBACK_TIME 1 //seconds -#define OVERHEAT_POWEROFF_TIME 30 - -#define SAMPLE_CNT 4 +/* Dbus Interfaces (THERMAL_PATH, THERMAL_INTERFACE, and THERMAL_METHOD_TEMP_CHANGED) + and Action Type Strings (RELEASE_ACTION, WARNING_ACTION, etc.) + can be modified according to the thermal daemons (e.g., PASS and SIOP) -#define TEMPERATURE_NORMAL 70 -#define TEMPERATURE_WARNING 75 -#define TEMPERATURE_LIMIT 80 -#define TEMPERATURE_SHUTDOWN 85 - -enum thermal_enum_type { - NORMAL, - WARNING, - LIMIT, - SHUTDOWN -}; + #define THERMAL_PATH "/Org/Tizen/Trm/Siop" + #define THERMAL_INTERFACE "org.tizen.trm.siop" + #define THERMAL_METHOD_TEMP_CHANGED "ChangedCooldownMode" */ -struct thermal_config_info { - int normal; - int warning; - int limit; - int shutdown; +enum cool_down_status_type { + COOL_DOWN_NONE_INIT, + COOL_DOWN_RELEASE, + COOL_DOWN_WARNING_ACTION, + COOL_DOWN_LIMIT_ACTION, + COOL_DOWN_SHUT_DOWN, }; -- 2.7.4 From 1c198bf8de89952cd544086672a86797ca131b73 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Thu, 14 Mar 2019 17:08:43 +0900 Subject: [PATCH 09/16] Refactoring: remove unnecessary local variable Change-Id: I1d2f9dc7a6ed147e24261c20f2a0b6478820a276 --- src/usb/usb-state.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/usb/usb-state.c b/src/usb/usb-state.c index c7bcbeb..dde7407 100644 --- a/src/usb/usb-state.c +++ b/src/usb/usb-state.c @@ -80,7 +80,6 @@ extcon_usb_state_e usb_state_get_connection(void) void usb_state_retrieve_selected_mode(void) { int ret, mode; - char buf[PATH_MAX]; ret = vconf_get_int(VCONFKEY_USB_SEL_MODE, &mode); if (ret != 0) { @@ -98,12 +97,7 @@ void usb_state_retrieve_selected_mode(void) usb_selected_mode = (unsigned int)mode; - if (snprintf(buf, PATH_MAX, "%s", MTP_RESPONDER_PATH) < 0) { - _E("Fail to copy MTP_RESPONDER_PATH."); - return; - } - - if (access(buf, R_OK) != 0) { + if (access(MTP_RESPONDER_PATH, R_OK) != 0) { mode &= ~USB_FUNCTION_MTP; usb_state_set_selected_mode(mode); } -- 2.7.4 From d4ef8ce0bb06def2ffc8f1d784af632adb56fb34 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 19 Mar 2019 15:42:54 +0900 Subject: [PATCH 10/16] Remove dbus method, ChangedCooldownMode for cooldown Deviced don't have to receive cooldown related signals or dbus methods. It only supports dbus methods for siop. Change-Id: Ief92af6776c325fb41b111c117ee45df7b0e4f0e Signed-off-by: lokilee73 --- src/thermal/thermal.c | 220 -------------------------------------------------- src/thermal/thermal.h | 4 - 2 files changed, 224 deletions(-) diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c index ca8e1d9..6b8b50c 100644 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -22,21 +22,15 @@ #include #include -#include #include "apps/apps.h" #include "core/devices.h" #include "core/log.h" #include "core/device-notifier.h" #include "core/devices.h" -#include "display/display-ops.h" -#include "battery/power-supply.h" -#include "power/power-handler.h" #include "thermal.h" static struct thermal_device *thermal_dev; -static int cool_down_level = COOL_DOWN_NONE_INIT; -static guint shut_down_timer; static int booting_done(void *data) { @@ -53,216 +47,6 @@ static int booting_done(void *data) return done; } -static int get_action_id(char *string) -{ - int temp = COOL_DOWN_NONE_INIT; - - if (!string) { - _E("Invalid temp level"); - return temp; - } - - if (!strncmp(string, RELEASE_ACTION, strlen(RELEASE_ACTION))) - temp = COOL_DOWN_RELEASE; - else if (!strncmp(string, WARNING_ACTION, strlen(WARNING_ACTION))) - temp = COOL_DOWN_WARNING_ACTION; - else if (!strncmp(string, LIMIT_ACTION, strlen(LIMIT_ACTION))) - temp = COOL_DOWN_LIMIT_ACTION; - else if (!strncmp(string, SHUTDOWN_ACTION, strlen(SHUTDOWN_ACTION))) - temp = COOL_DOWN_SHUT_DOWN; - else - temp = -EINVAL; - - return temp; -} - -void cool_down_wakeup(int level) -{ - if (level >= COOL_DOWN_LIMIT_ACTION || battery.health == HEALTH_BAD) { - _D("Dim."); - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_COOL_DOWN, LCD_DIM); - } else { - _D("Normal."); - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_COOL_DOWN, LCD_NORMAL); - } -} - -void cool_down_release(void) -{ - device_notify(DEVICE_NOTIFIER_COOL_DOWN, (void *)&cool_down_level); -} - -void cool_down_warning(void) -{ - device_notify(DEVICE_NOTIFIER_COOL_DOWN, (void *)&cool_down_level); -} - -void cool_down_limit(void) -{ - if (disp_plgn.pm_lock_internal) { - disp_plgn.pm_lock_internal(INTERNAL_LOCK_COOL_DOWN, LCD_DIM, STAY_CUR_STATE, 65000); - disp_plgn.pm_lock_internal(INTERNAL_LOCK_COOL_DOWN, LCD_OFF, STAY_CUR_STATE, 65000); - } - - device_notify(DEVICE_NOTIFIER_COOL_DOWN, (void *)&cool_down_level); -} - -void cool_down_poweroff(void) -{ - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_COOL_DOWN, LCD_DIM); - if (disp_plgn.pm_lock_internal) { - disp_plgn.pm_lock_internal(INTERNAL_LOCK_COOL_DOWN, LCD_DIM, STAY_CUR_STATE, 30000); - disp_plgn.pm_lock_internal(INTERNAL_LOCK_COOL_DOWN, LCD_OFF, STAY_CUR_STATE, 30000); - } - - device_notify(DEVICE_NOTIFIER_COOL_DOWN, (void *)&cool_down_level); -} - -static int power_execute(void *data) -{ - static const struct device_ops *ops; - - FIND_DEVICE_INT(ops, POWER_OPS_NAME); - - return ops->execute(data); -} - -static gboolean shut_down_timer_cb(void *data) -{ - int ret; - - shut_down_timer = 0; - ret = power_execute(POWER_POWEROFF); - if (ret != 0) - _E("Failed to request poweroff."); - - return G_SOURCE_REMOVE; -} - -void shut_down_timer_stop(void) -{ - if (!shut_down_timer) - return; - - g_source_remove(shut_down_timer); - shut_down_timer = 0; - _I("Stop cool down power off."); -} - -void shut_down_timer_start(void) -{ - if (shut_down_timer) - shut_down_timer_stop(); - - shut_down_timer = g_timeout_add_seconds( - SHUTDOWN_FORCE_WAIT, - shut_down_timer_cb, NULL); -} - -static int cool_down_execute(int state) -{ - int ret; - static int old_state = COOL_DOWN_NONE_INIT; - - cool_down_level = state; - if (vconf_set_int(VCONFKEY_SYSMAN_COOL_DOWN_MODE, cool_down_level) != 0) - _E("Failed to set VCONFKEY_SYSMAN_COOL_DOWN_MODE : %d", cool_down_level); - - if (old_state == cool_down_level) { - if (cool_down_level == COOL_DOWN_SHUT_DOWN) { - _I("Force cool down power off by multiple shutdown request."); - ret = power_execute(POWER_POWEROFF); - if (ret != 0) - _E("Failed to request poweroff."); - } - return 0; - } - - if (!booting_done(NULL)) { - _E("Booting is not done."); - return 0; - } - - switch (state) { - case COOL_DOWN_RELEASE: - shut_down_timer_stop(); - cool_down_release(); - break; - - case COOL_DOWN_WARNING_ACTION: - cool_down_warning(); - _I("State is WARNING."); - break; - - case COOL_DOWN_LIMIT_ACTION: - cool_down_limit(); - cool_down_wakeup(COOL_DOWN_LIMIT_ACTION); - break; - - case COOL_DOWN_SHUT_DOWN: - cool_down_wakeup(COOL_DOWN_SHUT_DOWN); - cool_down_poweroff(); - shut_down_timer_start(); - break; - - default: - _E("Invalid state : %d", state); - } - - _D("Last old_state = %d, new_state = %d", old_state, state); - old_state = state; - - return 0; -} - -static int check_sender_process(GDBusConnection *conn, const char *sender) -{ - pid_t pid; - - if (sender == NULL || g_dbus_is_name(sender) == FALSE) { - _E("Invalid sender."); - return -EINVAL; - } - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("Process(%d) does not exist, dbus ignored.", pid); - return -ESRCH; - } - - return pid; -} - -static GVariant *dbus_cooldown_handler(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int val; - char *string; - - g_variant_get(param, "(s)", &string); - _D("Cooldown string : %s", string); - ret = check_sender_process(conn, sender); - if (ret < 0) - goto out; - - val = get_action_id(string); - if (val < 0) { - _E("Invalid value : %d", val); - ret = val; - goto out; - } else - ret = cool_down_execute(val); - -out: - free(string); - return g_variant_new("(i)", ret); -} - static GVariant *dbus_get_temperature(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) @@ -287,7 +71,6 @@ exit: static const dbus_method_s dbus_methods[] = { { "GetTemperature", "i", "i", dbus_get_temperature}, - { "ChangedCooldownMode", "s", "i", dbus_cooldown_handler}, /* Add methods here */ }; @@ -309,9 +92,6 @@ static void thermal_init(void *data) ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_TEMPERATURE, &dbus_interface); if (ret < 0) _E("Failed to init dbus method: %d", ret); - - if (vconf_set_int(VCONFKEY_SYSMAN_COOL_DOWN_MODE, COOL_DOWN_NONE_INIT) != 0) - _E("Failed to set VCONFKEY_SYSMAN_COOL_DOWN_MODE : %d", COOL_DOWN_NONE_INIT); } static void thermal_exit(void *data) diff --git a/src/thermal/thermal.h b/src/thermal/thermal.h index bb65ed9..e28be8c 100644 --- a/src/thermal/thermal.h +++ b/src/thermal/thermal.h @@ -16,10 +16,6 @@ * limitations under the License. */ -/* Vconf */ -#define VCONFKEY_SYSMAN_COOL_DOWN_MODE "db/private/sysman/cool_down_mode" -#define SHUTDOWN_FORCE_WAIT 30 - /* Dbus Interfaces */ #define THERMAL_PATH "/Org/Tizen/System/Pass/Monitor/Thermal" #define THERMAL_INTERFACE "org.tizen.system.pass.monitor.thermal" -- 2.7.4 From c8ec84e76f0e8e58368d63d4b0fcf566d0cdb73d Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 22 Mar 2019 15:14:14 +0900 Subject: [PATCH 11/16] Remove unused #define value(MAX_RETRY) Change-Id: Ib392ec4b59c8096e63cd31212211529202545080 Signed-off-by: Hyotaek Shim --- src/power/power-handler.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 1dbbbb8..4b1cccd 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -57,14 +57,10 @@ #include "boot.h" #define POWEROFF_DURATION 2 -#define MAX_RETRY 2 #define POWEROFF_WAIT_RESOURCED (0.5*1000) /* 0.5 seconds */ #define POWEROFF_WAIT_MAX 10 /* 10 seconds */ - #define POWEROFF_WAIT_SYSTEMD_MS (30 * 1000/*ms*/) /* 30 seconds */ - #define SIGNAL_POWEROFF_STATE "ChangeState" - #define POWER_CONF_FILE "/etc/deviced/power.conf" static struct timeval tv_start_poweroff; @@ -668,11 +664,11 @@ out: } static const dbus_method_s dbus_methods[] = { - { "PowerOff", "s", "i", dbus_power_handler }, + { "PowerOff" , "s" , "i", dbus_power_handler }, { "PowerOffWithOption", "ss", "i", dbus_power_option_handler }, /* Public API device_power_reboot() calls this dbus method. */ - { "AddPowerOffWait", NULL, "i", add_poweroff_time }, - { "RemovePowerOffWait", NULL, "i", remove_poweroff_time }, + { "AddPowerOffWait" , NULL, "i", add_poweroff_time }, + { "RemovePowerOffWait", NULL, "i", remove_poweroff_time }, /* Add methods here */ }; -- 2.7.4 From b33cb9a1976e89659f24a30469b5e134bc0d3f99 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 22 Mar 2019 20:23:33 +0900 Subject: [PATCH 12/16] Rename systemd_start_unit_sync() to systemd_start_unit_wait_started() Change-Id: I904b86beb3a4cf34bcb66fae1aec01cf74bef8ac Signed-off-by: Hyotaek Shim --- src/usb-host-test/usb-host-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usb-host-test/usb-host-test.c b/src/usb-host-test/usb-host-test.c index c961639..1690e89 100644 --- a/src/usb-host-test/usb-host-test.c +++ b/src/usb-host-test/usb-host-test.c @@ -409,7 +409,7 @@ int start() _E("fail to init dbus signal(%d)", ret); sigid_start = ret; - ret = systemd_start_unit_sync(SYSTEMD_UNIT_NAME, NULL, -1); + ret = systemd_start_unit_wait_started(SYSTEMD_UNIT_NAME, NULL, -1); if (ret < 0) { _E("Error starting daemon"); /*unregister_dbus_signal_handler(SYSTEMD_DBUS_PATH, -- 2.7.4 From 190511a10c88a3802df4cc0bb76a33b93065b9c8 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 25 Mar 2019 19:14:52 +0900 Subject: [PATCH 13/16] Rename systemd_stop_unit_sync() to systemd_stop_unit_wait_stopped() Change-Id: I603c83be2e504010da735a9ec428db401fae0d1d Signed-off-by: Hyotaek Shim --- src/usb-host-test/usb-host-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/usb-host-test/usb-host-test.c b/src/usb-host-test/usb-host-test.c index 1690e89..bfb9354 100644 --- a/src/usb-host-test/usb-host-test.c +++ b/src/usb-host-test/usb-host-test.c @@ -455,13 +455,13 @@ static int stop() sigid_stop = ret; - ret = systemd_stop_unit_sync(SYSTEMD_UNIT_NAME, NULL, -1); + ret = systemd_stop_unit_wait_stopped(SYSTEMD_UNIT_NAME, NULL, -1); if (ret < 0) { _E("could not stop socket unit"); goto out; } - ret = systemd_stop_unit_sync(SYSTEMD_SERVICE_NAME, NULL, -1); + ret = systemd_stop_unit_wait_stopped(SYSTEMD_SERVICE_NAME, NULL, -1); if (ret < 0) { _E("could not stop service unit"); goto out; -- 2.7.4 From 1c55f127c7055d6bca1bc889583c46e7437a7e0b Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 29 Mar 2019 10:32:36 +0900 Subject: [PATCH 14/16] Rename booting_finished() to check_booting_finished() Change-Id: If101de088b807c042db8442bf707512192af17ba Signed-off-by: Hyotaek Shim --- src/core/main.c | 2 +- src/power/boot.c | 4 ++-- src/power/boot.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/main.c b/src/core/main.c index 31d835d..6151b42 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -69,7 +69,7 @@ void watchdog_notify(void) static void deviced_dbus_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { int ret; - ret = booting_finished(); + ret = check_booting_finished(); if (ret == 1) { /* Restarted: deviced was terminated */ _I("Notify relaunch."); diff --git a/src/power/boot.c b/src/power/boot.c index 080c23a..530fe8e 100644 --- a/src/power/boot.c +++ b/src/power/boot.c @@ -36,7 +36,7 @@ #define SYSTEMD_STATE_RUNNING "running" #define SYSTEMD_STATE_DEGRADED "degraded" -int booting_finished(void) +int check_booting_finished(void) { char *state = NULL; int ret = 0; @@ -93,7 +93,7 @@ static void booting_done_received(GDBusConnection *conn, if (system_done) return; - system_done = booting_finished(); + system_done = check_booting_finished(); if (system_done == 0) { _E("System session is not ready yet."); return; diff --git a/src/power/boot.h b/src/power/boot.h index ff20fac..8066011 100644 --- a/src/power/boot.h +++ b/src/power/boot.h @@ -19,7 +19,7 @@ #ifndef __DEVICED_BOOT_H__ #define __DEVICED_BOOT_H__ -int booting_finished(void); +int check_booting_finished(void); void add_booting_done_handler(void *data); void remove_booting_done_handler(void *data); -- 2.7.4 From c71113f5885c758143472d3138bf0a6f96cb373b Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Mon, 1 Apr 2019 19:49:17 +0900 Subject: [PATCH 15/16] Add a new function to control touchscreen while swimming Change-Id: I3e4426cbec7e0b9b5ee6c57a204a22be6499148a Signed-off-by: lokilee73 --- plugins/wearable/display/key-filter.c | 20 ++++++ plugins/wearable/display/swim.c | 116 ++++++++++++++++++++++++++++++++++ src/core/device-notifier.h | 1 + src/display/poll.h | 1 + 4 files changed, 138 insertions(+) create mode 100644 plugins/wearable/display/swim.c diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index 02d8a48..7130f52 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -60,6 +60,8 @@ #define KEY_PRESSED 1 #define KEY_BEING_PRESSED 2 +#define LONGKEY_PRESSED_TIME 4 /* 4 second */ + #define SIGNAL_CHANGE_HARDKEY "ChangeHardkey" #define SIGNAL_LCDON_BY_POWERKEY "LCDOnByPowerkey" #define SIGNAL_LCDOFF_BY_POWERKEY "LCDOffByPowerkey" @@ -84,6 +86,7 @@ void __WEAK__ switch_glove_key(int val); static struct timeval pressed_time; static guint longkey_timeout_id = 0; +static guint longkey_restore_id = 0; static int cancel_lcdoff; static int key_combination = KEY_COMBINATION_STOP; static double combination_pressed_time; @@ -165,6 +168,14 @@ static void longkey_pressed() power_execute(opt); } +static gboolean longkey_restore_cb(void *data) +{ + device_notify(DEVICE_NOTIFIER_LONGKEY_RESTORE, (void *)NULL); + longkey_restore_id = 0; + + return G_SOURCE_REMOVE; +} + static gboolean longkey_pressed_cb(void *data) { longkey_pressed(); @@ -437,6 +448,11 @@ static int process_power_key(struct input_event *pinput) longkey_timeout_id = 0; } + if (longkey_restore_id > 0) { + g_source_remove(longkey_restore_id); + longkey_restore_id = 0; + } + break; case KEY_PRESSED: if (display_has_caps(caps, DISPLAY_CAPA_LCDON)) { @@ -454,6 +470,10 @@ static int process_power_key(struct input_event *pinput) longkey_timeout_id = g_timeout_add_seconds( display_conf.longpress_interval, longkey_pressed_cb, NULL); + /* add long key restore timer */ + longkey_restore_id = g_timeout_add_seconds( + LONGKEY_PRESSED_TIME, + longkey_restore_cb, NULL); } if (skip_lcd_off) ignore = false; diff --git a/plugins/wearable/display/swim.c b/plugins/wearable/display/swim.c new file mode 100644 index 0000000..5c92433 --- /dev/null +++ b/plugins/wearable/display/swim.c @@ -0,0 +1,116 @@ +/* + * 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 "core/device-notifier.h" +#include "core/devices.h" +#include "display/core.h" +#include "display/util.h" +#include "display/display-ops.h" +#include + +static const struct device_ops *touchscreen_ops; + +static int swim_execute(void *data) +{ + int state, ret; + static int old_state = -1; + + if (check_default(touchscreen_ops)) + return 0; + + state = (int) data; + if (old_state == state) + return 0; + + if (state) { + _D("Stop touchscreen"); + ret = touchscreen_ops->stop(NORMAL_MODE); + } else { + _D("Start touchscreen"); + ret = touchscreen_ops->start(NORMAL_MODE); + } + + old_state = state; + return ret; +} + +static void swimmode_signal_handler(GDBusConnection *conn, + const gchar *sender, + const gchar *path, + const gchar *iface, + const gchar *name, + GVariant *param, + gpointer data) +{ + int val; + pid_t pid; + bool lcd_on = false; + + g_variant_get(param, "(i)", &val); + pid = dbus_connection_get_sender_pid(conn, sender); + _I("Request swim mode state %d by %d", val, pid); + + if (backlight_ops.get_lcd_power != DPMS_ON) { + if (disp_plgn.pm_change_internal) + disp_plgn.pm_change_internal(INTERNAL_LOCK_SWIM, S_NORMAL); + lcd_on = true; + } + + swim_execute((void *)val); + + if (lcd_on) { + if (disp_plgn.pm_change_internal) + disp_plgn.pm_change_internal(INTERNAL_LOCK_SWIM, S_LCDOFF); + } +} + +static int swim_restore_cb(void *data) +{ + _I("Restore swim mode"); + swim_execute((void *)0); + + return 0; +} + +static void swim_init(void *data) +{ + int ret; + + touchscreen_ops = find_device("touchscreen"); + + ret = subscribe_dbus_signal(NULL, + COREAPPS_PATH_SWIMMODE, + COREAPPS_INTERFACE_SWIMMODE, + COREAPPS_SIGNAL_STATUS, + swimmode_signal_handler, + NULL, NULL); + if (ret <= 0) + _E("Failed to register signal handler: %d", ret); + + register_notifier(DEVICE_NOTIFIER_LONGKEY_RESTORE, swim_restore_cb); +} + +static const struct device_ops swim_device_ops = { + .name = "swim", + .init = swim_init, + .execute = swim_execute, +}; + +DEVICE_OPS_REGISTER(&swim_device_ops) diff --git a/src/core/device-notifier.h b/src/core/device-notifier.h index 771941c..6acc7d8 100644 --- a/src/core/device-notifier.h +++ b/src/core/device-notifier.h @@ -70,6 +70,7 @@ enum device_notifier_type { DEVICE_NOTIFIER_UPSM, DEVICE_NOTIFIER_UDEV, DEVICE_NOTIFIER_BEZEL_WAKEUP, + DEVICE_NOTIFIER_LONGKEY_RESTORE, DEVICE_NOTIFIER_MAX, }; diff --git a/src/display/poll.h b/src/display/poll.h index 819ef97..f6ab3c6 100644 --- a/src/display/poll.h +++ b/src/display/poll.h @@ -62,6 +62,7 @@ enum { INTERNAL_LOCK_PM, INTERNAL_LOCK_HALLIC, INTERNAL_LOCK_AMBIENT, + INTERNAL_LOCK_SWIM, }; #define SIGNAL_NAME_LCD_CONTROL "lcdcontol" -- 2.7.4 From 219f0cb15eafd5e3b76383a6c0c1edc13061061b Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 2 Apr 2019 14:24:47 +0900 Subject: [PATCH 16/16] Add dbus path and interface for Coreapps Change-Id: I9ca144e84bb2024a30c7fb41a5daa541edfb971a Signed-off-by: lokilee73 --- plugins/wearable/display/swim.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/wearable/display/swim.c b/plugins/wearable/display/swim.c index 5c92433..378906e 100644 --- a/plugins/wearable/display/swim.c +++ b/plugins/wearable/display/swim.c @@ -25,6 +25,14 @@ #include "display/display-ops.h" #include +/* CoreApps */ +#define COREAPPS_PATH_HOME "/Org/Tizen/Coreapps/home" +#define COREAPPS_INTERFACE_HOME "org.tizen.coreapps.home" + +#define COREAPPS_PATH_SWIMMODE COREAPPS_PATH_HOME"/swimmode" +#define COREAPPS_INTERFACE_SWIMMODE COREAPPS_INTERFACE_HOME".swimmode" +#define COREAPPS_SIGNAL_STATUS "status" + static const struct device_ops *touchscreen_ops; static int swim_execute(void *data) -- 2.7.4