From 8d1a57bed7421c2fdbe6231c5a60a707630d0330 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Tue, 27 Nov 2018 14:16:33 +0100 Subject: [PATCH 01/16] power: disable_coredump_handler: Fix error condition correctly fd could be zero as well and it's not an error condition. Fix the check to only test write() return value. Change-Id: I92932f7fa2368d88fc2210f35f35521ba51161c2 --- src/power/power-handler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/power/power-handler.c b/src/power/power-handler.c index d45267b..d277641 100755 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -167,7 +167,7 @@ static bool disable_coredump_handler(void) close(fd); } - bool is_ok = fd > 0 && ret > 0; + bool is_ok = ret > 0; _I("Disabling core dumps %s", is_ok ? "succeeded" : "failed"); return is_ok; -- 2.7.4 From 657bdceb78e1ec1ec21899553b52fbde121a74e4 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 7 Dec 2018 14:27:11 +0900 Subject: [PATCH 02/16] Fix build errors Change-Id: Idb1ad4f63f9571531201469b95ecab01c4f923e6 Signed-off-by: lokilee73 --- plugins/iot/display/input.c | 2 +- plugins/mobile/display/input.c | 2 +- plugins/tv/display/input.c | 2 +- plugins/wearable/display/input.c | 2 +- src/battery/lowbat-handler.c | 2 +- src/core/common.c | 2 +- src/core/device-notifier.c | 6 +++--- src/core/launch.c | 2 +- src/tzip/tzip-utility.c | 4 ++-- src/usb-host-test/usb-host-test.c | 4 ++-- src/usb/usb-debug.c | 2 +- src/usb/usb-tethering.c | 2 +- src/usb/usb.c | 2 +- 13 files changed, 17 insertions(+), 17 deletions(-) mode change 100644 => 100755 plugins/iot/display/input.c mode change 100644 => 100755 plugins/mobile/display/input.c mode change 100644 => 100755 plugins/tv/display/input.c mode change 100644 => 100755 plugins/wearable/display/input.c mode change 100644 => 100755 src/core/device-notifier.c mode change 100644 => 100755 src/core/launch.c mode change 100644 => 100755 src/tzip/tzip-utility.c mode change 100644 => 100755 src/usb/usb-debug.c mode change 100644 => 100755 src/usb/usb-tethering.c diff --git a/plugins/iot/display/input.c b/plugins/iot/display/input.c old mode 100644 new mode 100755 index 95714ac..a986504 --- a/plugins/iot/display/input.c +++ b/plugins/iot/display/input.c @@ -75,7 +75,7 @@ static inline void process_event(struct libinput_event *ev) input.value = libinput_event_keyboard_get_key_state(k); fd = libinput_get_fd(li); - _D("time %d.%d type %d code %d value %d fd %d", + _D("time %ld.%06ld type %d code %d value %d fd %d", input.time.tv_sec, input.time.tv_usec, input.type, input.code, input.value, fd); diff --git a/plugins/mobile/display/input.c b/plugins/mobile/display/input.c old mode 100644 new mode 100755 index 95714ac..a986504 --- a/plugins/mobile/display/input.c +++ b/plugins/mobile/display/input.c @@ -75,7 +75,7 @@ static inline void process_event(struct libinput_event *ev) input.value = libinput_event_keyboard_get_key_state(k); fd = libinput_get_fd(li); - _D("time %d.%d type %d code %d value %d fd %d", + _D("time %ld.%06ld type %d code %d value %d fd %d", input.time.tv_sec, input.time.tv_usec, input.type, input.code, input.value, fd); diff --git a/plugins/tv/display/input.c b/plugins/tv/display/input.c old mode 100644 new mode 100755 index 95714ac..a986504 --- a/plugins/tv/display/input.c +++ b/plugins/tv/display/input.c @@ -75,7 +75,7 @@ static inline void process_event(struct libinput_event *ev) input.value = libinput_event_keyboard_get_key_state(k); fd = libinput_get_fd(li); - _D("time %d.%d type %d code %d value %d fd %d", + _D("time %ld.%06ld type %d code %d value %d fd %d", input.time.tv_sec, input.time.tv_usec, input.type, input.code, input.value, fd); diff --git a/plugins/wearable/display/input.c b/plugins/wearable/display/input.c old mode 100644 new mode 100755 index 95714ac..a986504 --- a/plugins/wearable/display/input.c +++ b/plugins/wearable/display/input.c @@ -75,7 +75,7 @@ static inline void process_event(struct libinput_event *ev) input.value = libinput_event_keyboard_get_key_state(k); fd = libinput_get_fd(li); - _D("time %d.%d type %d code %d value %d fd %d", + _D("time %ld.%06ld type %d code %d value %d fd %d", input.time.tv_sec, input.time.tv_usec, input.type, input.code, input.value, fd); diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index cdedc60..4452836 100755 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -148,7 +148,7 @@ static int lowbat_add_scenario(int old, int now, int (*func)(void *data)) { struct lowbat_process_entry *scenario; - _D("%d %d, %x", old, now, func); + _D("%d %d, %p", old, now, func); if (!func) { _E("invalid func address!"); diff --git a/src/core/common.c b/src/core/common.c index 1d66785..1ffd895 100755 --- a/src/core/common.c +++ b/src/core/common.c @@ -495,7 +495,7 @@ void print_time(const char *prefix) gettimeofday(&tv, NULL); ret = localtime_r(&(tv.tv_sec), &tm); if (ret) - _D("%s --> %d:%02d:%02d %d", + _D("%s --> %d:%02d:%02d %06ld", prefix, tm.tm_hour, tm.tm_min, tm.tm_sec, tv.tv_usec); } diff --git a/src/core/device-notifier.c b/src/core/device-notifier.c old mode 100644 new mode 100755 index 7b8e9f3..0a50f87 --- a/src/core/device-notifier.c +++ b/src/core/device-notifier.c @@ -40,7 +40,7 @@ int register_notifier(enum device_notifier_type status, int (*func)(void *data)) dd_list *n; struct device_notifier *notifier; - _I("%d, %x", status, func); + _I("%d, %p", status, func); if (!func) { _E("invalid func address!"); @@ -48,7 +48,7 @@ int register_notifier(enum device_notifier_type status, int (*func)(void *data)) } FIND_NOTIFIER(device_notifier_list, n, notifier, status, func) { - _E("function is already registered! [%d, %x]", + _E("function is already registered! [%d, %p]", status, func); return -EINVAL; } @@ -78,7 +78,7 @@ int unregister_notifier(enum device_notifier_type status, int (*func)(void *data } FIND_NOTIFIER(device_notifier_list, n, notifier, status, func) { - _I("[%d, %x]", status, func); + _I("[%d, %p]", status, func); notifier->deleted = true; } diff --git a/src/core/launch.c b/src/core/launch.c old mode 100644 new mode 100755 index c5a90fc..57f4f88 --- a/src/core/launch.c +++ b/src/core/launch.c @@ -169,7 +169,7 @@ int launch_app_with_nice(const char *file, char *const argv[], pid_t *pid, int _ ret = execvp(file, argv); /* If failed... */ - _E("exec. error: %s", errno); + _E("exec. error: %d", errno); return -2; } diff --git a/src/tzip/tzip-utility.c b/src/tzip/tzip-utility.c old mode 100644 new mode 100755 index bfbd3b9..6cd5335 --- a/src/tzip/tzip-utility.c +++ b/src/tzip/tzip-utility.c @@ -649,7 +649,7 @@ int read_zipfile(struct tzip_handle *handle, char *buf, if (offset > handle->file_info->uncompressed_size || offset < 0) { - _E("Invalid Offset (%jd) for file size (%d)", offset, handle->file_info->uncompressed_size); + _E("Invalid Offset (%jd) for file size (%lu)", offset, handle->file_info->uncompressed_size); return -EINVAL; } @@ -790,7 +790,7 @@ int read_zipfile(struct tzip_handle *handle, char *buf, /* store current zip position for subsequent read */ handle->offset = offset + bytes_read; - _D("bytes_read : %d [offset : %jd, total size : %d]", bytes_read, handle->offset, handle->file_info->uncompressed_size); + _D("bytes_read : %d [offset : %jd, total size : %lu]", bytes_read, handle->offset, handle->file_info->uncompressed_size); return bytes_read; } diff --git a/src/usb-host-test/usb-host-test.c b/src/usb-host-test/usb-host-test.c index 1c7345c..e83811b 100755 --- a/src/usb-host-test/usb-host-test.c +++ b/src/usb-host-test/usb-host-test.c @@ -243,7 +243,7 @@ static void service_started_handler(GDBusConnection *conn, int ret; if (!dh_get_param_from_var(param, "(uoss)", &id, NULL, &unit, NULL)) { - _E("failed to get params grom gvariant. expected:%s, type:%s", "uoss", g_variant_get_type(param)); + _E("failed to get params grom gvariant. expected:%s, type:%s", "uoss", g_variant_get_type_string(param)); return ; } @@ -280,7 +280,7 @@ static void service_stopped_handler(GDBusConnection *conn, usbg_gadget *g; if (!dh_get_param_from_var(param, "(uoss)", &id, NULL, &unit, NULL)) { - _E("failed to get params grom gvariant. expected:%s, type:%s", "uoss", g_variant_get_type(param)); + _E("failed to get params grom gvariant. expected:%s, type:%s", "uoss", g_variant_get_type_string(param)); return ; } diff --git a/src/usb/usb-debug.c b/src/usb/usb-debug.c old mode 100644 new mode 100755 index a647cae..6310ef5 --- a/src/usb/usb-debug.c +++ b/src/usb/usb-debug.c @@ -85,7 +85,7 @@ static int usb_debug_mode_changed(void *data) ret = usb_change_mode(mode); if (ret < 0) - _E("Failed to change usb mode to (%s)", mode); + _E("Failed to change usb mode to (%d)", mode); return ret; } diff --git a/src/usb/usb-tethering.c b/src/usb/usb-tethering.c old mode 100644 new mode 100755 index b7834ec..911a3b7 --- a/src/usb/usb-tethering.c +++ b/src/usb/usb-tethering.c @@ -76,7 +76,7 @@ static int usb_tethering_mode_changed(void *data) ret = usb_change_mode(mode); if (ret < 0) - _E("Failed to change usb mode to (%s)", mode); + _E("Failed to change usb mode to (%d)", mode); return ret; } diff --git a/src/usb/usb.c b/src/usb/usb.c index 65c2b7b..a171007 100755 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -336,7 +336,7 @@ int usb_change_mode(unsigned mode) if (usb_state_get_connection() == USB_CONNECTED) { ret = usb_enable(mode); if (ret < 0) { - _E("Failed to enable usb mode (%d)"); + _E("Failed to enable usb mode (%d)", ret); return ret; } } -- 2.7.4 From 97c64bd08202a8cf515ad78b8c8faf672749288c Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 14 Dec 2018 10:35:36 +0900 Subject: [PATCH 03/16] Fix left build errors for aarch64 Change-Id: Iba78b2d02d12b291b09c192f333b09e1c84abcff Signed-off-by: lokilee73 --- src/power/power-handler.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/power/power-handler.c b/src/power/power-handler.c index d277641..ce3ec06 100755 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -298,7 +298,7 @@ int check_power_flag(void) close(fd); if (len < 0) { len = errno; - _E("read() failed (%d)", len); + _E("read() failed (%ld)", len); return 0; } while (len > 0 && buf[len - 1] == '\n') @@ -341,7 +341,7 @@ static void make_power_flag(enum poweroff_type type, char *option) if (option) { len = write(fd, option, strlen(option)); if (len <= 0) - _E("Failed to store option (%d)", len < 0 ? errno : len); + _E("Failed to store option (%ld)", len < 0 ? errno : len); } close(fd); -- 2.7.4 From 4b16705894aba0d6a40fcf46bd4dea9aca254a23 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 20 Dec 2018 13:40:58 +0900 Subject: [PATCH 04/16] Fix incorrect changes for build errors Change-Id: I22b86b4e8efe2449c05bdc1a03edb771845161ac Signed-off-by: lokilee73 --- src/power/power-handler.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/power/power-handler.c b/src/power/power-handler.c index ce3ec06..b8fc0a3 100755 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -298,7 +298,7 @@ int check_power_flag(void) close(fd); if (len < 0) { len = errno; - _E("read() failed (%ld)", len); + _E("read() failed (%zd)", len); return 0; } while (len > 0 && buf[len - 1] == '\n') @@ -341,7 +341,7 @@ static void make_power_flag(enum poweroff_type type, char *option) if (option) { len = write(fd, option, strlen(option)); if (len <= 0) - _E("Failed to store option (%ld)", len < 0 ? errno : len); + _E("Failed to store option (%zd)", len < 0 ? errno : len); } close(fd); -- 2.7.4 From cb316a043c72fc98568eef7d500c20d9c376da22 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 12 Dec 2018 19:29:30 +0900 Subject: [PATCH 05/16] Change thermal algorithm to get temp value from device HAL Needed action is triggered by below table ex) Action Table -------------------------------------------------- Current Previous Action -------------------------------------------------- NORMAL NORMAL X WARNING ReleaseAction CRITICAL ReleaseAction DANGER X -------------------------------------------------- WARNING NORMAL WarningAction WARNING X CRITICAL WarningAction DANGER X -------------------------------------------------- CRITICAL NORMAL LimitAction WARNING LimitAction CRITICAL X DANGER X -------------------------------------- DANGER NORMAL ShutdownAction WARNING ShutdownAction CRITICAL ShutdownAction DANGER X -------------------------------------------------- Change-Id: Id8bd9737f9c648d1ed131dc22c3d8de3ba1b58a0 Signed-off-by: lokilee73 --- src/thermal/thermal.c | 232 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 147 insertions(+), 85 deletions(-) diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c index cc16557..bda2810 100755 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -28,31 +28,21 @@ #include "core/device-notifier.h" #include "core/devices.h" +static struct thermal_device *thermal_dev; static int noti; -/* 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" #define WARNING_ACTION "WarningAction" #define LIMIT_ACTION "LimitAction" #define SHUTDOWN_ACTION "ShutdownAction" -/* 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 THERMAL_PATH "/Org/Tizen/Trm/Siop" - #define THERMAL_INTERFACE "org.tizen.trm.siop" - #define THERMAL_METHOD_TEMP_CHANGED "ChangedCooldownMode" */ - #define SIGNAL_OVERHEAT_TIME "TimeUpdate" #define OVERHEAT_CALLBACK_TIME 1 //seconds #define OVERHEAT_POWEROFF_TIME 30 +#define SAMPLE_CNT 4 + enum thermal_enum_type { NORMAL, WARNING, @@ -60,6 +50,14 @@ enum thermal_enum_type { DANGER }; +static int ap_temp_table[DANGER + 1] = { +/* [Lv] = {Celsius degree} */ + 44, + 46, + 48, + 53, +}; + static int power_off(void) { const struct device_ops *power; @@ -196,50 +194,15 @@ static void thermal_add_recovery_popup(void) _E("Fail to launch recovery popup"); } -static int change_templevel_to_enum(char *string) -{ - int temp = -1; - - if (!string) { - _E("Invalid temp level"); - return temp; - } - - if (!strncmp(string, RELEASE_ACTION, strlen(RELEASE_ACTION))) - temp = NORMAL; - else if (!strncmp(string, WARNING_ACTION, strlen(WARNING_ACTION))) - temp = WARNING; - else if (!strncmp(string, LIMIT_ACTION, strlen(LIMIT_ACTION))) - temp = CRITICAL; - else if (!strncmp(string, SHUTDOWN_ACTION, strlen(SHUTDOWN_ACTION))) - temp = DANGER; - - return temp; -} - -static void thermal_action(char *state) +static void thermal_action(int state) { - static int old_state = NORMAL; - int new_state; char *action = NULL; - new_state = change_templevel_to_enum(state); - if (new_state < 0) { - _E("Invalid thermal state : %d", new_state); - goto out; - } - - _D("old_state = %d, new_state = %d", old_state, new_state); - if (old_state == DANGER) - goto out; - - switch (new_state) { + switch (state) { case NORMAL: - if (old_state == WARNING || old_state == CRITICAL) { - thermal_remove_noti(); - thermal_add_recovery_popup(); - } - action = strdup(RELEASE_ACTION); + thermal_remove_noti(); + thermal_add_recovery_popup(); + action = strdup(RELEASE_ACTION); break; case WARNING: @@ -260,43 +223,120 @@ static void thermal_action(char *state) thermal_overheat_popup(); action = strdup(SHUTDOWN_ACTION); break; - - default: - _E("invalid state : %d", new_state); - goto out; } - old_state = new_state; broadcast_thermal_state_legacy(action); free(action); +} -out: - _D("Last old_state = %d, new_state = %d", old_state, new_state); +static bool is_thermal_updated(int old_state, int new_state) +{ + bool ret = false; + + if (new_state == NORMAL) { + if (old_state == WARNING || old_state == CRITICAL) + ret = true; + } else if (new_state == WARNING) { + if (old_state == NORMAL || old_state == CRITICAL) + ret = true; + } else if (new_state == CRITICAL) { + if (old_state == NORMAL || old_state == WARNING) + ret = true; + } else if (new_state == DANGER) { + if (old_state != DANGER) + ret = true; + } + + return ret; +} + +static int thermal_get_temp_enum(int temp) +{ + int i; + + if (temp > ap_temp_table[DANGER]) + return DANGER; + + for (i = 0; i < DANGER + 1; i++) { + if (temp <= ap_temp_table[i]) + break; + } + + return i; +} + +static int thermal_get_average(int temp) +{ + 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]; + + 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 updated = false; + + avg_temp = thermal_get_average(info->temp); + new_state = thermal_get_temp_enum(avg_temp); + if (new_state < NORMAL || new_state > DANGER) { + _E("Invalid thermal state : %d", new_state); + return; + } + + update = is_thermal_updated(old_state, new_state); + _I("Last update(%d) old_state(%d) new_state(%d)", update, old_state, new_state); + if (updated) + thermal_action(new_state); + + old_state = new_state; } -static void temp_signal_handler(GDBusConnection *conn, - const gchar *sender, - const gchar *path, - const gchar *iface, - const gchar *name, - GVariant *param, - gpointer data) +static int thermal_service_start(void) { - char *temp_str = NULL; + int ret; - g_variant_get(param, "(s)", &temp_str); + if (!thermal_dev) { + _E("Thermal service is not supported"); + return -ENOTSUP; + } + + ret = thermal_dev->register_changed_event(thermal_handler, NULL); + if (ret < 0) + _E("Failed to register thermal event (%d)", ret); - _D("temp_str = %s", temp_str); - thermal_action(temp_str); - g_free(temp_str); + return ret; } -static guint sigid; +static int thermal_service_stop(void) +{ + int ret; + + if (!thermal_dev) { + _E("Thermal service is not supported"); + return -ENOTSUP; + } + + ret = thermal_dev->unregister_changed_event(thermal_handler); + if (ret < 0) + _E("Failed to unregister thermal event (%d)", ret); + + return ret; +} static int booting_done(void *data) { static int done; - int ret; if (data == NULL) return done; @@ -305,13 +345,7 @@ static int booting_done(void *data) return done; _I("booting done"); - ret = subscribe_dbus_signal(NULL, THERMAL_PATH, - THERMAL_INTERFACE, - THERMAL_METHOD_TEMP_CHANGED, - temp_signal_handler, NULL, NULL); - if (ret <= 0) - _E("fail to init dbus signal(%d)", ret); - sigid = ret; + thermal_service_start(); return done; } @@ -333,14 +367,42 @@ static void thermal_exit(void *data) if (ret < 0) _E("Fail to unregister booting done Notifier"); - if (sigid) - unsubscribe_dbus_signal(NULL, sigid); + thermal_service_stop(); } static int thermal_probe(void *data) { - /* device-manager-plugin-xxx is not used for the information of temperature. - instead, pass is used */ + struct hw_info *info; + int ret; + + if (thermal_dev) + return 0; + + ret = hw_get_info(THERMAL_HARDWARE_DEVICE_ID, + (const struct hw_info **)&info); + if (ret < 0) { + _E("There is no HAL for Thermal"); + return ret; + } + + if (!info->open) { + _E("Failed to open thermal device; open(NULL)"); + return -ENODEV; + } + + ret = info->open(info, NULL, (struct hw_common**)&thermal_dev); + if (ret < 0) { + _E("Failed to get thermal device structure (%d)", ret); + return ret; + } + + if (!thermal_dev || + !thermal_dev->get_info || + !thermal_dev->register_changed_event || + !thermal_dev->unregister_changed_event) { + _E("Thermal HAL does not support event handler"); + return -ENODEV; + } _I("Thermal device structure load success"); return 0; -- 2.7.4 From 791718ab2a0d08b6cc8fb79e26729360f683ffa4 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 26 Dec 2018 20:21:24 +0900 Subject: [PATCH 06/16] Fix build error Change-Id: I8de7b15bdc3b921e2bb8e09e60e7a128deb3d198 Signed-off-by: lokilee73 --- src/thermal/thermal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c index bda2810..6dd8b22 100755 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -294,8 +294,8 @@ static void thermal_handler(struct thermal_info *info, void *data) return; } - update = is_thermal_updated(old_state, new_state); - _I("Last update(%d) old_state(%d) new_state(%d)", update, old_state, new_state); + updated = is_thermal_updated(old_state, new_state); + _I("Last updated(%d) old_state(%d) new_state(%d)", updated, old_state, new_state); if (updated) thermal_action(new_state); -- 2.7.4 From 08716711448426cd2858da03e4af217aa1bda344 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 27 Dec 2018 10:42:47 +0900 Subject: [PATCH 07/16] Remove executable flag from non-executable files Change-Id: I6b848799d6a5f568350becac14c3d85c10b6b3e9 Signed-off-by: lokilee73 --- CMakeLists.txt | 0 packaging/deviced.spec | 0 plugins/iot/display/ambient-mode.c | 0 plugins/iot/display/core.c | 0 plugins/iot/display/device-interface.c | 0 plugins/iot/display/display-dbus.c | 0 plugins/iot/display/input.c | 0 plugins/iot/display/setting.c | 0 plugins/mobile/display/ambient-mode.c | 0 plugins/mobile/display/core.c | 0 plugins/mobile/display/device-interface.c | 0 plugins/mobile/display/display-dbus.c | 0 plugins/mobile/display/input.c | 0 plugins/mobile/display/setting.c | 0 plugins/tv/display/ambient-mode.c | 0 plugins/tv/display/core.c | 0 plugins/tv/display/device-interface.c | 0 plugins/tv/display/display-dbus.c | 0 plugins/tv/display/input.c | 0 plugins/tv/display/setting.c | 0 plugins/wearable/display/ambient-mode.c | 0 plugins/wearable/display/core.c | 0 plugins/wearable/display/device-interface.c | 0 plugins/wearable/display/display-dbus.c | 0 plugins/wearable/display/input.c | 0 plugins/wearable/display/setting.c | 0 src/apps/apps.c | 0 src/apps/apps.h | 0 src/auto-test/battery.c | 0 src/auto-test/display.c | 0 src/auto-test/proc.c | 0 src/battery/lowbat-handler.c | 0 src/battery/power-supply.c | 0 src/battery/power-supply.h | 0 src/core/common.c | 0 src/core/device-notifier.c | 0 src/core/launch.c | 0 src/core/main.c | 0 src/core/udev.h | 0 src/deviced/dd-deviced.h | 0 src/display/device-interface.h | 0 src/extcon/earjack.c | 0 src/extcon/extcon.h | 0 src/extcon/extcon_count.c | 0 src/extcon/extcon_count.h | 0 src/extcon/hdmi.c | 0 src/led/rgb.c | 0 src/libdeviced/CMakeLists.txt | 0 src/libdeviced/deviced-noti.c | 0 src/libdeviced/display.c | 0 src/power/power-handler.c | 0 src/power/power-handler.h | 0 src/shared/deviced-priv.h | 0 src/shared/plugin.h | 0 src/thermal/thermal.c | 0 src/time/time-handler.c | 0 src/tzip/tzip-utility.c | 0 src/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c | 0 src/usb-host-test/usb-host-test.c | 0 src/usb/usb-dbus.c | 0 src/usb/usb-debug.c | 0 src/usb/usb-state.c | 0 src/usb/usb-tethering.c | 0 src/usb/usb.c | 0 src/usb/usb.h | 0 src/usbhost/usb-host.c | 0 66 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 CMakeLists.txt mode change 100755 => 100644 packaging/deviced.spec mode change 100755 => 100644 plugins/iot/display/ambient-mode.c mode change 100755 => 100644 plugins/iot/display/core.c mode change 100755 => 100644 plugins/iot/display/device-interface.c mode change 100755 => 100644 plugins/iot/display/display-dbus.c mode change 100755 => 100644 plugins/iot/display/input.c mode change 100755 => 100644 plugins/iot/display/setting.c mode change 100755 => 100644 plugins/mobile/display/ambient-mode.c mode change 100755 => 100644 plugins/mobile/display/core.c mode change 100755 => 100644 plugins/mobile/display/device-interface.c mode change 100755 => 100644 plugins/mobile/display/display-dbus.c mode change 100755 => 100644 plugins/mobile/display/input.c mode change 100755 => 100644 plugins/mobile/display/setting.c mode change 100755 => 100644 plugins/tv/display/ambient-mode.c mode change 100755 => 100644 plugins/tv/display/core.c mode change 100755 => 100644 plugins/tv/display/device-interface.c mode change 100755 => 100644 plugins/tv/display/display-dbus.c mode change 100755 => 100644 plugins/tv/display/input.c mode change 100755 => 100644 plugins/tv/display/setting.c mode change 100755 => 100644 plugins/wearable/display/ambient-mode.c mode change 100755 => 100644 plugins/wearable/display/core.c mode change 100755 => 100644 plugins/wearable/display/device-interface.c mode change 100755 => 100644 plugins/wearable/display/display-dbus.c mode change 100755 => 100644 plugins/wearable/display/input.c mode change 100755 => 100644 plugins/wearable/display/setting.c mode change 100755 => 100644 src/apps/apps.c mode change 100755 => 100644 src/apps/apps.h mode change 100755 => 100644 src/auto-test/battery.c mode change 100755 => 100644 src/auto-test/display.c mode change 100755 => 100644 src/auto-test/proc.c mode change 100755 => 100644 src/battery/lowbat-handler.c mode change 100755 => 100644 src/battery/power-supply.c mode change 100755 => 100644 src/battery/power-supply.h mode change 100755 => 100644 src/core/common.c mode change 100755 => 100644 src/core/device-notifier.c mode change 100755 => 100644 src/core/launch.c mode change 100755 => 100644 src/core/main.c mode change 100755 => 100644 src/core/udev.h mode change 100755 => 100644 src/deviced/dd-deviced.h mode change 100755 => 100644 src/display/device-interface.h mode change 100755 => 100644 src/extcon/earjack.c mode change 100755 => 100644 src/extcon/extcon.h mode change 100755 => 100644 src/extcon/extcon_count.c mode change 100755 => 100644 src/extcon/extcon_count.h mode change 100755 => 100644 src/extcon/hdmi.c mode change 100755 => 100644 src/led/rgb.c mode change 100755 => 100644 src/libdeviced/CMakeLists.txt mode change 100755 => 100644 src/libdeviced/deviced-noti.c mode change 100755 => 100644 src/libdeviced/display.c mode change 100755 => 100644 src/power/power-handler.c mode change 100755 => 100644 src/power/power-handler.h mode change 100755 => 100644 src/shared/deviced-priv.h mode change 100755 => 100644 src/shared/plugin.h mode change 100755 => 100644 src/thermal/thermal.c mode change 100755 => 100644 src/time/time-handler.c mode change 100755 => 100644 src/tzip/tzip-utility.c mode change 100755 => 100644 src/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c mode change 100755 => 100644 src/usb-host-test/usb-host-test.c mode change 100755 => 100644 src/usb/usb-dbus.c mode change 100755 => 100644 src/usb/usb-debug.c mode change 100755 => 100644 src/usb/usb-state.c mode change 100755 => 100644 src/usb/usb-tethering.c mode change 100755 => 100644 src/usb/usb.c mode change 100755 => 100644 src/usb/usb.h mode change 100755 => 100644 src/usbhost/usb-host.c diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100755 new mode 100644 diff --git a/packaging/deviced.spec b/packaging/deviced.spec old mode 100755 new mode 100644 diff --git a/plugins/iot/display/ambient-mode.c b/plugins/iot/display/ambient-mode.c old mode 100755 new mode 100644 diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c old mode 100755 new mode 100644 diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c old mode 100755 new mode 100644 diff --git a/plugins/iot/display/display-dbus.c b/plugins/iot/display/display-dbus.c old mode 100755 new mode 100644 diff --git a/plugins/iot/display/input.c b/plugins/iot/display/input.c old mode 100755 new mode 100644 diff --git a/plugins/iot/display/setting.c b/plugins/iot/display/setting.c old mode 100755 new mode 100644 diff --git a/plugins/mobile/display/ambient-mode.c b/plugins/mobile/display/ambient-mode.c old mode 100755 new mode 100644 diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c old mode 100755 new mode 100644 diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c old mode 100755 new mode 100644 diff --git a/plugins/mobile/display/display-dbus.c b/plugins/mobile/display/display-dbus.c old mode 100755 new mode 100644 diff --git a/plugins/mobile/display/input.c b/plugins/mobile/display/input.c old mode 100755 new mode 100644 diff --git a/plugins/mobile/display/setting.c b/plugins/mobile/display/setting.c old mode 100755 new mode 100644 diff --git a/plugins/tv/display/ambient-mode.c b/plugins/tv/display/ambient-mode.c old mode 100755 new mode 100644 diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c old mode 100755 new mode 100644 diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c old mode 100755 new mode 100644 diff --git a/plugins/tv/display/display-dbus.c b/plugins/tv/display/display-dbus.c old mode 100755 new mode 100644 diff --git a/plugins/tv/display/input.c b/plugins/tv/display/input.c old mode 100755 new mode 100644 diff --git a/plugins/tv/display/setting.c b/plugins/tv/display/setting.c old mode 100755 new mode 100644 diff --git a/plugins/wearable/display/ambient-mode.c b/plugins/wearable/display/ambient-mode.c old mode 100755 new mode 100644 diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c old mode 100755 new mode 100644 diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c old mode 100755 new mode 100644 diff --git a/plugins/wearable/display/display-dbus.c b/plugins/wearable/display/display-dbus.c old mode 100755 new mode 100644 diff --git a/plugins/wearable/display/input.c b/plugins/wearable/display/input.c old mode 100755 new mode 100644 diff --git a/plugins/wearable/display/setting.c b/plugins/wearable/display/setting.c old mode 100755 new mode 100644 diff --git a/src/apps/apps.c b/src/apps/apps.c old mode 100755 new mode 100644 diff --git a/src/apps/apps.h b/src/apps/apps.h old mode 100755 new mode 100644 diff --git a/src/auto-test/battery.c b/src/auto-test/battery.c old mode 100755 new mode 100644 diff --git a/src/auto-test/display.c b/src/auto-test/display.c old mode 100755 new mode 100644 diff --git a/src/auto-test/proc.c b/src/auto-test/proc.c old mode 100755 new mode 100644 diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c old mode 100755 new mode 100644 diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c old mode 100755 new mode 100644 diff --git a/src/battery/power-supply.h b/src/battery/power-supply.h old mode 100755 new mode 100644 diff --git a/src/core/common.c b/src/core/common.c old mode 100755 new mode 100644 diff --git a/src/core/device-notifier.c b/src/core/device-notifier.c old mode 100755 new mode 100644 diff --git a/src/core/launch.c b/src/core/launch.c old mode 100755 new mode 100644 diff --git a/src/core/main.c b/src/core/main.c old mode 100755 new mode 100644 diff --git a/src/core/udev.h b/src/core/udev.h old mode 100755 new mode 100644 diff --git a/src/deviced/dd-deviced.h b/src/deviced/dd-deviced.h old mode 100755 new mode 100644 diff --git a/src/display/device-interface.h b/src/display/device-interface.h old mode 100755 new mode 100644 diff --git a/src/extcon/earjack.c b/src/extcon/earjack.c old mode 100755 new mode 100644 diff --git a/src/extcon/extcon.h b/src/extcon/extcon.h old mode 100755 new mode 100644 diff --git a/src/extcon/extcon_count.c b/src/extcon/extcon_count.c old mode 100755 new mode 100644 diff --git a/src/extcon/extcon_count.h b/src/extcon/extcon_count.h old mode 100755 new mode 100644 diff --git a/src/extcon/hdmi.c b/src/extcon/hdmi.c old mode 100755 new mode 100644 diff --git a/src/led/rgb.c b/src/led/rgb.c old mode 100755 new mode 100644 diff --git a/src/libdeviced/CMakeLists.txt b/src/libdeviced/CMakeLists.txt old mode 100755 new mode 100644 diff --git a/src/libdeviced/deviced-noti.c b/src/libdeviced/deviced-noti.c old mode 100755 new mode 100644 diff --git a/src/libdeviced/display.c b/src/libdeviced/display.c old mode 100755 new mode 100644 diff --git a/src/power/power-handler.c b/src/power/power-handler.c old mode 100755 new mode 100644 diff --git a/src/power/power-handler.h b/src/power/power-handler.h old mode 100755 new mode 100644 diff --git a/src/shared/deviced-priv.h b/src/shared/deviced-priv.h old mode 100755 new mode 100644 diff --git a/src/shared/plugin.h b/src/shared/plugin.h old mode 100755 new mode 100644 diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c old mode 100755 new mode 100644 diff --git a/src/time/time-handler.c b/src/time/time-handler.c old mode 100755 new mode 100644 diff --git a/src/tzip/tzip-utility.c b/src/tzip/tzip-utility.c old mode 100755 new mode 100644 diff --git a/src/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c b/src/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c old mode 100755 new mode 100644 diff --git a/src/usb-host-test/usb-host-test.c b/src/usb-host-test/usb-host-test.c old mode 100755 new mode 100644 diff --git a/src/usb/usb-dbus.c b/src/usb/usb-dbus.c old mode 100755 new mode 100644 diff --git a/src/usb/usb-debug.c b/src/usb/usb-debug.c old mode 100755 new mode 100644 diff --git a/src/usb/usb-state.c b/src/usb/usb-state.c old mode 100755 new mode 100644 diff --git a/src/usb/usb-tethering.c b/src/usb/usb-tethering.c old mode 100755 new mode 100644 diff --git a/src/usb/usb.c b/src/usb/usb.c old mode 100755 new mode 100644 diff --git a/src/usb/usb.h b/src/usb/usb.h old mode 100755 new mode 100644 diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c old mode 100755 new mode 100644 -- 2.7.4 From a00b3923d873a8a1a94f1b519aa211d8161c8fbe Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Thu, 3 Jan 2019 19:23:51 +0900 Subject: [PATCH 08/16] sensitivity: merge sensitivity Change-Id: I3a6e0336d699f9a006cbe47fa920603e33d2d956 Signed-off-by: sanghyeok.oh --- CMakeLists.txt | 4 + packaging/deviced.spec | 1 + src/touchscreen/sensitivity.c | 220 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 225 insertions(+) create mode 100644 src/touchscreen/sensitivity.c diff --git a/CMakeLists.txt b/CMakeLists.txt index d55168c..bd1b986 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,6 +108,10 @@ IF(TOUCHSCREEN_MODULE STREQUAL on) SET(SRCS ${SRCS} ${TOUCHSCREEN_SRCS}) ENDIF() +IF(TOUCH_SENSITIVITY_MODULE STREQUAL on) + SET(SRCS ${SRCS} src/touchscreen/sensitivity.c) +ENDIF() + IF(TZIP_MODULE STREQUAL on) ADD_SOURCE(src/tzip TZIP_SRCS) SET(SRCS ${SRCS} ${TZIP_SRCS}) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index b92bd02..d2d988b 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -155,6 +155,7 @@ Plugin libraries for IoT devices -DTIZEN_FEATURE_CPU_MODULE=on \ -DTIZEN_FEATURE_USBHOST_TEST=on \ -DTIZEN_FEATURE_BATTERY_OVER_TEMPERATURE=on \ + -DTOUCH_SENSITIVITY_MODULE=on \ #eol %build diff --git a/src/touchscreen/sensitivity.c b/src/touchscreen/sensitivity.c new file mode 100644 index 0000000..8f1bd25 --- /dev/null +++ b/src/touchscreen/sensitivity.c @@ -0,0 +1,220 @@ +/* + * deviced + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 +#include + +#include "core/devices.h" +#include "core/common.h" +#include "core/log.h" +#include "core/device-notifier.h" + + +#ifndef VCONFKEY_SETAPPL_TOUCH_SENSITIVITY +#define VCONFKEY_SETAPPL_TOUCH_SENSITIVITY "db/setting/enhance_touch_sensitivity" +#endif + +#define DISABLE_SENSITIVITY_SIGNAL "DisableSensitivity" + +#define TOUCH_SENSITIVITY_DISABLE_INTERVAL 1 + +#ifndef TOUCHSENSITIVITY_GLOVE_MODE_OFF +#define TOUCHSENSITIVITY_GLOVE_MODE_OFF 0 +#endif +#ifndef TOUCHSENSITIVITY_GLOVE_MODE_ON +#define TOUCHSENSITIVITY_GLOVE_MODE_ON 1 +#endif + +static guint disable_timer; + +static struct touchsensitivity_device *touchsensitivity_dev; + +static int check_dev(void) +{ + if (!touchsensitivity_dev || + !touchsensitivity_dev->glove_mode_set_state || + !touchsensitivity_dev->glove_mode_get_state) + return -ENODEV; + return 0; +} + +static gboolean disable_sensitivity(void *data) +{ + int ret; + int status; + + if (check_dev() < 0) { + _E("touch sensitivity HAL does not exist"); + return G_SOURCE_REMOVE; + } + + if (vconf_get_bool(VCONFKEY_SETAPPL_TOUCH_SENSITIVITY, &status) != 0 || + status == TOUCHSENSITIVITY_GLOVE_MODE_ON) + return G_SOURCE_REMOVE; + + ret = touchsensitivity_dev->glove_mode_set_state(TOUCHSENSITIVITY_GLOVE_MODE_OFF); + _I("%s change auto touch sensitivity disable", ret ? "fail" : "set"); + return G_SOURCE_REMOVE; +} + +static void disable_touch_sensitivity_handler(GDBusConnection *conn, + const gchar *sender, + const gchar *path, + const gchar *iface, + const gchar *name, + GVariant *param, + gpointer data) +{ + disable_timer = g_timeout_add_seconds(TOUCH_SENSITIVITY_DISABLE_INTERVAL, disable_sensitivity, NULL); + if (disable_timer == 0) + _E("fail to add battery init timer during booting"); +} + +static GVariant *get_touch_sensitivity(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + int val = -1, ret; + + if (check_dev() < 0) { + _E("touch sensitivity HAL does not exist"); + goto out; + } + ret = touchsensitivity_dev->glove_mode_get_state(&val); + _I("%s touch sensitivity %d", ret ? "fail" : "get", val); +out: + return g_variant_new("(i)", val); +} + +static GVariant *set_touch_sensitivity(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + int val = -1, ret = -ESRCH; + + g_variant_get(param, "(i)", &val); + + if (disable_timer) { + g_source_remove(disable_timer); + disable_timer = 0; + } + if (check_dev() < 0) { + _E("touch sensitivity HAL does not exist"); + ret = -EINVAL; + goto error; + } + ret = touchsensitivity_dev->glove_mode_set_state(val); + +error: + _I("%s touch sensitivity %d", ret ? "fail" : "set", val); + + return g_variant_new("(i)", ret); +} + +static const dbus_method_s dbus_methods[] = { + { "GetSensitivity", NULL, "i", get_touch_sensitivity }, + { "SetSensitivity", "i", "i", set_touch_sensitivity }, + /* Add methods here */ +}; + +static const dbus_interface_u dbus_interface = { + .oh = NULL, + .name = DEVICED_INTERFACE_TOUCH, + .methods = dbus_methods, + .nr_methods = ARRAY_SIZE(dbus_methods), +}; + +static int booting_done(void *data) +{ + static int done; + int ret; + int status = TOUCHSENSITIVITY_GLOVE_MODE_OFF; + + if (data == NULL) + goto out; + + done = *(int *)data; + + if (vconf_get_bool(VCONFKEY_SETAPPL_TOUCH_SENSITIVITY, &status) != 0 || + status == TOUCHSENSITIVITY_GLOVE_MODE_OFF) + goto out; + + if (check_dev() < 0) { + _E("touch sensitivity HAL does not exist"); + goto out; + } + ret = touchsensitivity_dev->glove_mode_set_state(TOUCHSENSITIVITY_GLOVE_MODE_ON); + _I("%s change auto touch sensitivity enable", ret ? "fail" : "set"); + unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); +out: + return done; +} + +static void sensitivity_init(void *data) +{ + int ret; + struct hw_info *info; + + if (touchsensitivity_dev) + return; + + ret = hw_get_info(TOUCHSENSITIVITY_HARDWARE_DEVICE_ID, + (const struct hw_info **)&info); + if (ret < 0) { + _E("Fail to load touch sensitivity shared library (%d)", ret); + return; + } + + if (!info->open) { + _E("fail to open touch sensitivity device : open(NULL)"); + return; + } + + ret = info->open(info, NULL, (struct hw_common **)&touchsensitivity_dev); + if (ret < 0) { + _E("fail to get touch sensitivity device structure : (%d)", ret); + return; + } + + _I("touch sensitivity device structure load success"); + + /* init dbus interface */ + ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_TOUCH, &dbus_interface); + if (ret < 0) + _E("fail to init dbus method(%d)", ret); + + subscribe_dbus_signal(NULL, + DEVICED_PATH_TOUCH, + DEVICED_INTERFACE_TOUCH, + DISABLE_SENSITIVITY_SIGNAL, + disable_touch_sensitivity_handler, + NULL, NULL); + + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); +} + +static const struct device_ops sensitivity_device_ops = { + .name = "sensitivity", + .init = sensitivity_init, +}; + +DEVICE_OPS_REGISTER(&sensitivity_device_ops) + -- 2.7.4 From 38227a89678df5c8b7ed376c69d6f7739b38b6b8 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 9 Jan 2019 11:22:49 +0900 Subject: [PATCH 09/16] dbus: modify to use send with reply change dbus function to fix errors in media and battery Change-Id: I4d91ad3419dab43c74d72fd58d767c5fdbe91d21 Signed-off-by: lokilee73 --- src/apps/apps.c | 10 ++++++---- src/battery/power-supply.c | 20 ++++++++++++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/apps/apps.c b/src/apps/apps.c index 53bb751..cd4a654 100644 --- a/src/apps/apps.c +++ b/src/apps/apps.c @@ -107,11 +107,12 @@ int launch_message_post(char *type) if (!type) return -EINVAL; - ret = dbus_handle_method_async_var(POPUP_BUS_NAME, + ret = dbus_handle_method_async_with_reply_var(POPUP_BUS_NAME, POPUP_PATH_NOTI, POPUP_INTERFACE_NOTI, "MessagePostOn", - g_variant_new("(s)", type)); + g_variant_new("(s)", type), + __cb, -1, NULL); if (disp_plgn.pm_change_internal) disp_plgn.pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); @@ -160,8 +161,9 @@ int remove_notification(char *type, int id) if (!type || id < 0) return -EINVAL; - return dbus_handle_method_async_var(POPUP_BUS_NAME, + return dbus_handle_method_async_with_reply_var(POPUP_BUS_NAME, POPUP_PATH_NOTI, POPUP_INTERFACE_NOTI, - type, g_variant_new("(i)", id)); + type, g_variant_new("(i)", id), + __cb, -1, NULL); } diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index f3d0c5b..9b4bb7a 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -193,6 +193,21 @@ out: g_variant_unref(var); } +static void noti_off_cb(GVariant *var, void *user_data, GError *err) +{ + int ret= 0; + + if (!dh_get_param_from_var(var, "(i)", &ret)) { + _E("no message [%s]", g_variant_get_type_string(var)); + goto out; + } + + _D("Noti Off : %d", ret); + +out: + g_variant_unref(var); +} + static int check_power_supply_noti(void) { #ifdef MICRO_DD @@ -239,11 +254,12 @@ static int send_full_noti(enum charge_full_type state) if (noti_id <= 0) return -EPERM; for (retry = RETRY_MAX; retry > 0; retry--) { - ret = dbus_handle_method_async_var(POPUP_BUS_NAME, + ret = dbus_handle_method_async_with_reply_var(POPUP_BUS_NAME, POPUP_PATH_NOTI, POPUP_INTERFACE_NOTI, METHOD_FULL_NOTI_OFF, - g_variant_new("(i)", noti_id)); + g_variant_new("(i)", noti_id), + noti_off_cb, -1, NULL); if (ret == 0) { _D("Deleted battery full noti"); noti_id = 0; -- 2.7.4 From edbfbd744fb6ec32804ad550935b9196c806cee6 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 10 Jan 2019 21:08:51 +0900 Subject: [PATCH 10/16] Apply conf file and change thermal structure Firstly, thermal value depends on hardware. So, we have to apply different temp table for each targets. Secondly, change the name on temp table as products. ex) Critical -> Limt Danger -> Shutdown Lastly, change condition in thermal_get_temp_enum Change-Id: If25be071e000dfaa1d5e68d205538cd2332d1d9b Signed-off-by: lokilee73 --- CMakeLists.txt | 5 ++ conf/temperature.conf | 6 ++ conf/wearable-temperature.conf | 6 ++ packaging/deviced.spec | 5 ++ src/thermal/thermal.c | 143 +++++++++++++++++++++++++++-------------- src/thermal/thermal.h | 49 ++++++++++++++ 6 files changed, 165 insertions(+), 49 deletions(-) create mode 100644 conf/temperature.conf create mode 100644 conf/wearable-temperature.conf create mode 100644 src/thermal/thermal.h diff --git a/CMakeLists.txt b/CMakeLists.txt index bd1b986..013b1f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -246,6 +246,11 @@ 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 new file mode 100644 index 0000000..db8a158 --- /dev/null +++ b/conf/temperature.conf @@ -0,0 +1,6 @@ +[THERMAL] +#Level is Celsius +Normal=70 +Warning=75 +Limit=80 +Shutdown=85 diff --git a/conf/wearable-temperature.conf b/conf/wearable-temperature.conf new file mode 100644 index 0000000..ceb68b2 --- /dev/null +++ b/conf/wearable-temperature.conf @@ -0,0 +1,6 @@ +[THERMAL] +#Level is Celsius +Normal=44 +Warning=46 +Limit=48 +Shutdown=53 diff --git a/packaging/deviced.spec b/packaging/deviced.spec index d2d988b..2606afa 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -207,6 +207,7 @@ cat %{_sysconfdir}/deviced/wearable-display.conf >> %{_sysconfdir}/deviced/displ rm -rf %{_sysconfdir}/deviced/wearable-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 @@ -272,6 +273,7 @@ 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 @@ -279,16 +281,19 @@ 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 %manifest deviced.manifest %license LICENSE.Apache-2.0 %defattr(-,root,root,-) +%config %{_sysconfdir}/deviced/temperature.conf %{_libdir}/tv-display.so %files plugin-profile-iot %manifest deviced.manifest %license LICENSE.Apache-2.0 %defattr(-,root,root,-) +%config %{_sysconfdir}/deviced/temperature.conf %{_libdir}/iot-display.so diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c index 6dd8b22..794b186 100644 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -27,35 +27,19 @@ #include "core/log.h" #include "core/device-notifier.h" #include "core/devices.h" +#include "thermal.h" +#include "core/config-parser.h" static struct thermal_device *thermal_dev; static int noti; -/* Action types */ -#define RELEASE_ACTION "ReleaseAction" -#define WARNING_ACTION "WarningAction" -#define LIMIT_ACTION "LimitAction" -#define SHUTDOWN_ACTION "ShutdownAction" +#define THERMAL_CONF_FILE "/etc/deviced/temperature.conf" -#define SIGNAL_OVERHEAT_TIME "TimeUpdate" -#define OVERHEAT_CALLBACK_TIME 1 //seconds -#define OVERHEAT_POWEROFF_TIME 30 - -#define SAMPLE_CNT 4 - -enum thermal_enum_type { - NORMAL, - WARNING, - CRITICAL, - DANGER -}; - -static int ap_temp_table[DANGER + 1] = { -/* [Lv] = {Celsius degree} */ - 44, - 46, - 48, - 53, +static struct thermal_config_info thermal_table = { + .normal = TEMPERATURE_NORMAL, + .warning = TEMPERATURE_WARNING, + .limit = TEMPERATURE_LIMIT, + .shutdown = TEMPERATURE_SHUTDOWN }; static int power_off(void) @@ -206,18 +190,17 @@ static void thermal_action(int state) break; case WARNING: - thermal_remove_popup(); - thermal_add_noti(); + _I("State is WARNING"); action = strdup(WARNING_ACTION); break; - case CRITICAL: + case LIMIT: thermal_remove_popup(); thermal_add_noti(); action = strdup(LIMIT_ACTION); break; - case DANGER: + case SHUTDOWN: thermal_remove_popup(); thermal_remove_noti(); thermal_overheat_popup(); @@ -229,21 +212,46 @@ static void thermal_action(int state) free(action); } -static bool is_thermal_updated(int old_state, int new_state) +/* 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 == CRITICAL) + if (old_state == WARNING || old_state == LIMIT) ret = true; } else if (new_state == WARNING) { - if (old_state == NORMAL || old_state == CRITICAL) + if (old_state == NORMAL) ret = true; - } else if (new_state == CRITICAL) { + } else if (new_state == LIMIT) { if (old_state == NORMAL || old_state == WARNING) ret = true; - } else if (new_state == DANGER) { - if (old_state != DANGER) + } else if (new_state == SHUTDOWN) { + if (old_state != SHUTDOWN) ret = true; } @@ -252,17 +260,18 @@ static bool is_thermal_updated(int old_state, int new_state) static int thermal_get_temp_enum(int temp) { - int i; + int ret = -1; - if (temp > ap_temp_table[DANGER]) - return DANGER; + 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; - for (i = 0; i < DANGER + 1; i++) { - if (temp <= ap_temp_table[i]) - break; - } - - return i; + return ret; } static int thermal_get_average(int temp) @@ -285,18 +294,18 @@ static void thermal_handler(struct thermal_info *info, void *data) { static int old_state = NORMAL; int avg_temp, new_state; - bool updated = false; + bool action_needed = false; avg_temp = thermal_get_average(info->temp); new_state = thermal_get_temp_enum(avg_temp); - if (new_state < NORMAL || new_state > DANGER) { - _E("Invalid thermal state : %d", new_state); + if (new_state == -1) { + _I("Keep current state : %d", old_state); return; } - updated = is_thermal_updated(old_state, new_state); - _I("Last updated(%d) old_state(%d) new_state(%d)", updated, old_state, new_state); - if (updated) + 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; @@ -350,10 +359,46 @@ static int booting_done(void *data) 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("%s,%s,%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 %d %d %d %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("Fail to register booting done Notifier"); diff --git a/src/thermal/thermal.h b/src/thermal/thermal.h new file mode 100644 index 0000000..19b8d3b --- /dev/null +++ b/src/thermal/thermal.h @@ -0,0 +1,49 @@ +/* + * 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. + */ + + +/* Action types */ +#define RELEASE_ACTION "ReleaseAction" +#define WARNING_ACTION "WarningAction" +#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 + +#define TEMPERATURE_NORMAL 70 +#define TEMPERATURE_WARNING 75 +#define TEMPERATURE_LIMIT 80 +#define TEMPERATURE_SHUTDOWN 85 + +enum thermal_enum_type { + NORMAL, + WARNING, + LIMIT, + SHUTDOWN +}; + +struct thermal_config_info { + int normal; + int warning; + int limit; + int shutdown; +}; -- 2.7.4 From a5d9163c90d3bab0bbc2c54952dbaccec8fc5574 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 17 Jan 2019 18:02:44 +0900 Subject: [PATCH 11/16] Fix integer overflow in extcon_count.c Change-Id: I83ac1617238aa664f1c5c6d1cff0c6945f5b1940 Signed-off-by: lokilee73 --- src/extcon/extcon_count.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/extcon/extcon_count.c b/src/extcon/extcon_count.c index 6e5df02..bb9914b 100644 --- a/src/extcon/extcon_count.c +++ b/src/extcon/extcon_count.c @@ -47,6 +47,7 @@ int extcon_update_count(int index, unsigned long count) int r; int ret = 0; char buf[BUF_MAX]; + unsigned long value; fd = open(extcon_devices[index].str, O_RDWR | O_CREAT, 0644); if (fd < 0) { @@ -62,9 +63,15 @@ int extcon_update_count(int index, unsigned long count) } buf[r] = '\0'; - extcon_devices[index].count = strtoul(buf, NULL, 10); - extcon_devices[index].count += count; - + value = strtoul(buf, NULL, 10); + if (value == ULONG_MAX && errno == ERANGE) + _E("converted value is over ULONG MAX(%lu)!", ULONG_MAX); + else if (value > ULONG_MAX - count) + value = ULONG_MAX; + else + value += count; + + extcon_devices[index].count = value; lseek(fd, 0, SEEK_SET); _I("ext(%d) count %lu", index, extcon_devices[index].count); snprintf(buf, sizeof(buf), "%lu", extcon_devices[index].count); -- 2.7.4 From 9f4dd859afeeda3f8f59b041f8a13bad4a471d18 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 18 Jan 2019 11:47:46 +0900 Subject: [PATCH 12/16] Change the way to make display.conf To make display.conf by using 'cat' can add duplicated contents in it. So, change the way by file replacement Change-Id: I69215787e89012ac8183899cea16b4215c73d65b Signed-off-by: lokilee73 --- conf/mobile-display.conf | 36 ++++++++++++++++++++++++++++++++++++ conf/wearable-display.conf | 36 ++++++++++++++++++++++++++++++++++++ packaging/deviced.spec | 9 ++++----- 3 files changed, 76 insertions(+), 5 deletions(-) diff --git a/conf/mobile-display.conf b/conf/mobile-display.conf index 05e20d8..59af551 100644 --- a/conf/mobile-display.conf +++ b/conf/mobile-display.conf @@ -1,2 +1,38 @@ +[Display] +# deviced is pending lcd on until lock screen shows. +# This is the maximum pending time. +# LockScreenWaitingTime=0.3 (second) + +# Power-off popup is launched when power key is long pressed. +# This is duration of pressing power key. +# LongPressInterval=2 (second) + +# This is polling time of auto brightness. +# LightSensorSamplingInterval=1 (second) + +# display state is changed to SLEEP state after this time. +# If this value is large, it causes power consumption problem. +# LCDOffTimeout=500 (milli second) + +# This is n step of auto brightness. +# If brightness is change from a to b, brightness's changed n times from a to b. +# BrightnessChangeStep=10 + +# Just below application only allow to change display frame rate. +# refer to enum refresh_app +# ChangedFrameRateAllowed=setting (setting or all) +# ControlDisplay=(yes or no) + +# LCD is not turned off when this value is yes and key double pressed +# PowerKeyDoublePressSupport=(yes or no) + +# If this value is yes, LCD is always on except pressing power key. +# Default value is no, LCD is turned off by lcd timeout. +# LCDAlwaysOn=(yes or no) + +# If this value is yes, LCD is turned off by lcd timeout. +# If this value is no, LCD is turned off just by external requests. +# TimeoutEnable=(yes or no) + LCDAlwaysOn=no TimeoutEnable=yes diff --git a/conf/wearable-display.conf b/conf/wearable-display.conf index 8075ab9..3c190ae 100644 --- a/conf/wearable-display.conf +++ b/conf/wearable-display.conf @@ -1,3 +1,39 @@ +[Display] +# deviced is pending lcd on until lock screen shows. +# This is the maximum pending time. +# LockScreenWaitingTime=0.3 (second) + +# Power-off popup is launched when power key is long pressed. +# This is duration of pressing power key. +# LongPressInterval=2 (second) + +# This is polling time of auto brightness. +# LightSensorSamplingInterval=1 (second) + +# display state is changed to SLEEP state after this time. +# If this value is large, it causes power consumption problem. +# LCDOffTimeout=500 (milli second) + +# This is n step of auto brightness. +# If brightness is change from a to b, brightness's changed n times from a to b. +# BrightnessChangeStep=10 + +# Just below application only allow to change display frame rate. +# refer to enum refresh_app +# ChangedFrameRateAllowed=setting (setting or all) +# ControlDisplay=(yes or no) + +# LCD is not turned off when this value is yes and key double pressed +# PowerKeyDoublePressSupport=(yes or no) + +# If this value is yes, LCD is always on except pressing power key. +# Default value is no, LCD is turned off by lcd timeout. +# LCDAlwaysOn=(yes or no) + +# If this value is yes, LCD is turned off by lcd timeout. +# If this value is no, LCD is turned off just by external requests. +# TimeoutEnable=(yes or no) + LCDAlwaysOn=no TimeoutEnable=yes ControlDisplay=no diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 2606afa..b3713e1 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -197,14 +197,12 @@ fi %postun -n libdeviced -p /sbin/ldconfig %post plugin-profile-mobile -cat %{_sysconfdir}/deviced/mobile-display.conf >> %{_sysconfdir}/deviced/display.conf -rm -rf %{_sysconfdir}/deviced/mobile-display.conf +mv %{_sysconfdir}/deviced/mobile-display.conf %{_sysconfdir}/deviced/display.conf mkdir -p %{_libdir}/deviced mv %{_libdir}/mobile-display.so %{_libdir}/deviced/display.so %post plugin-profile-wearable -cat %{_sysconfdir}/deviced/wearable-display.conf >> %{_sysconfdir}/deviced/display.conf -rm -rf %{_sysconfdir}/deviced/wearable-display.conf +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 @@ -232,7 +230,6 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %config %{_sysconfdir}/deviced/cpu.conf %config %{_sysconfdir}/deviced/power.conf %config %{_sysconfdir}/deviced/battery.conf -%config %{_sysconfdir}/deviced/display.conf # usbhost_test %{_sysconfdir}/deviced/usb-host-test/test_gadget.gs %{_bindir}/usb-host-ffs-test-daemon @@ -288,6 +285,7 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %manifest deviced.manifest %license LICENSE.Apache-2.0 %defattr(-,root,root,-) +%config %{_sysconfdir}/deviced/display.conf %config %{_sysconfdir}/deviced/temperature.conf %{_libdir}/tv-display.so @@ -295,5 +293,6 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %manifest deviced.manifest %license LICENSE.Apache-2.0 %defattr(-,root,root,-) +%config %{_sysconfdir}/deviced/display.conf %config %{_sysconfdir}/deviced/temperature.conf %{_libdir}/iot-display.so -- 2.7.4 From c14fb65f6a5c970f83915b6bafd2e0c095b3689e Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 30 Jan 2019 11:16:26 +0900 Subject: [PATCH 13/16] Remove extcon_count.c and extcon_count.h Because they have dependency with products Change-Id: I1fe49f9b0089f85ad09d4d7c21e5c609195be7eb Signed-off-by: lokilee73 --- src/battery/power-supply.c | 21 +------- src/extcon/earjack.c | 4 -- src/extcon/extcon_count.c | 131 --------------------------------------------- src/extcon/extcon_count.h | 32 ----------- 4 files changed, 1 insertion(+), 187 deletions(-) delete mode 100644 src/extcon/extcon_count.c delete mode 100644 src/extcon/extcon_count.h diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 9b4bb7a..f303cbe 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -36,7 +36,6 @@ #include "apps/apps.h" #include "power-supply.h" #include "battery.h" -#include "extcon/extcon_count.h" #define BATTERY_NAME "battery" #define CHARGEFULL_NAME "Full" @@ -195,7 +194,7 @@ out: static void noti_off_cb(GVariant *var, void *user_data, GError *err) { - int ret= 0; + int ret = 0; if (!dh_get_param_from_var(var, "(i)", &ret)) { _E("no message [%s]", g_variant_get_type_string(var)); @@ -559,7 +558,6 @@ static void check_online(void) old_online = VCONFKEY_SYSMAN_CHARGER_CONNECTED; vconf_set_int(VCONFKEY_SYSMAN_CHARGER_STATUS, old_online); power_supply_broadcast(CHARGER_STATUS_SIGNAL, old_online); - extcon_update_count(EXTCON_TA, 1); check_power_supply(old_online); charger_state_send_system_event(CHARGE_STATUS_CONNECTED); if (charge_status != old_charge_status) @@ -676,22 +674,6 @@ static void check_capacity_status(const char *env_value) battery.capacity = atoi(env_value); } -static void update_capacity_full(void) -{ - static int old; - int delta; - - if (battery.online <= POWER_SUPPLY_TYPE_BATTERY || - old == 0 || - old >= battery.capacity) { - old = battery.capacity; - return; - } - delta = battery.capacity - old; - old = battery.capacity; - extcon_update_count(EXTCON_BATTERY_FULL, delta); -} - static void process_power_supply(void *data) { if (old_battery.charge_now != battery.charge_now || battery.charge_now == CHARGER_ABNORMAL) { @@ -713,7 +695,6 @@ static void process_power_supply(void *data) check_battery_status(); device_notify(DEVICE_NOTIFIER_POWER_SUPPLY, NULL); device_notify(DEVICE_NOTIFIER_BATTERY_CHARGING, &battery.charge_now); - update_capacity_full(); } static void battery_state(struct battery_info *info) diff --git a/src/extcon/earjack.c b/src/extcon/earjack.c index 05e247a..fcb9d52 100644 --- a/src/extcon/earjack.c +++ b/src/extcon/earjack.c @@ -26,7 +26,6 @@ #include "display/poll.h" #include "display/display-ops.h" #include "extcon/extcon.h" -#include "extcon/extcon_count.h" #define SIGNAL_EARJACK_STATE "ChangedEarjack" #define GET_EARJACK_STATE "Earjack" @@ -74,9 +73,6 @@ static int earjack_update(int status) disp_plgn.pm_change_internal(INTERNAL_LOCK_EARJACK, LCD_NORMAL); } - if (CONNECTED(status)) - extcon_update_count(EXTCON_EARJACK, 1); - return 0; } diff --git a/src/extcon/extcon_count.c b/src/extcon/extcon_count.c deleted file mode 100644 index bb9914b..0000000 --- a/src/extcon/extcon_count.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2015 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 - -#include "core/log.h" -#include "core/list.h" -#include "core/common.h" -#include "core/devices.h" -#include "extcon_count.h" - -#define BUF_MAX 256 - -// TODO : storage location should be configurable by configuration file -static struct extcon_device { - const enum extcon_type type; - const char *str; - unsigned long count; -} extcon_devices[] = { - { EXTCON_TA, "/opt/share/batt_cable_count", 0}, - { EXTCON_EARJACK, "/opt/share/earjack_count", 0}, - { EXTCON_BATTERY_FULL, "/opt/share/battery_full_count", 0}, -}; - -int extcon_update_count(int index, unsigned long count) -{ - int fd; - int r; - int ret = 0; - char buf[BUF_MAX]; - unsigned long value; - - fd = open(extcon_devices[index].str, O_RDWR | O_CREAT, 0644); - if (fd < 0) { - _E("cannot open file(%s)", extcon_devices[index].str); - return -ENOENT; - } - - r = read(fd, buf, BUF_MAX); - if (r < 0 || r >= BUF_MAX) { - close(fd); - ret = -EIO; - return ret; - } - - buf[r] = '\0'; - value = strtoul(buf, NULL, 10); - if (value == ULONG_MAX && errno == ERANGE) - _E("converted value is over ULONG MAX(%lu)!", ULONG_MAX); - else if (value > ULONG_MAX - count) - value = ULONG_MAX; - else - value += count; - - extcon_devices[index].count = value; - lseek(fd, 0, SEEK_SET); - _I("ext(%d) count %lu", index, extcon_devices[index].count); - snprintf(buf, sizeof(buf), "%lu", extcon_devices[index].count); - - r = write(fd, buf, strlen(buf)); - if (r < 0) - ret = -EIO; - - close(fd); - return ret; -} - -static int extcon_create_count(int index) -{ - int fd; - int r; - int ret = 0; - char buf[BUF_MAX]; - fd = open(extcon_devices[index].str, O_RDWR | O_CREAT, 0644); - if (fd < 0) { - _E("cannot open file(%s)", extcon_devices[index].str); - return -ENOENT; - } - snprintf(buf, sizeof(buf), "%lu", extcon_devices[index].count); - r = write(fd, buf, strlen(buf)); - if (r < 0) - ret = -EIO; - - if (ret != 0) { - close(fd); - _E("cannot write file(%s)", extcon_devices[index].str); - return ret; - } - - _I("create extcon(%d:%x) %s", - index, fd, extcon_devices[index].str); - close(fd); - return ret; -} - -static void extcon_count_init(void *data) -{ - int i, ret; - - for (i = 0; i < ARRAY_SIZE(extcon_devices); i++) { - ret = extcon_create_count(i); - if (ret < 0) - break; - } -} - -static const struct device_ops extcon_count_ops = { - .name = "extcon_count", - .init = extcon_count_init, -}; - -DEVICE_OPS_REGISTER(&extcon_count_ops) diff --git a/src/extcon/extcon_count.h b/src/extcon/extcon_count.h deleted file mode 100644 index 8c489af..0000000 --- a/src/extcon/extcon_count.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2015 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 __EXTCON_COUNT_H__ -#define __EXTCON_COUNT_H__ - -#include "core/common.h" - -enum extcon_type { - EXTCON_TA = 0, - EXTCON_EARJACK, - EXTCON_BATTERY_FULL, -}; - -int extcon_update_count(int index, unsigned long count); -#endif /* __EXTCON_COUNT_H__ */ -- 2.7.4 From 51849e1cad17ba09bc95d72c82c590a406530c35 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 10 Jan 2019 00:11:44 +0000 Subject: [PATCH 14/16] power: Rework handling of repeated poweroff/reboot request MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This commit generalizes "repeated poweroff/reboot" code path to use same state variables as dbus requests (poweroff_opt var). Additionally, multiple constructs are simplified. Change-Id: I989c7fdbf021da0d69d9062507a05fd8692846a5 Signed-off-by: Paweł Szewczyk Signed-off-by: Hyotaek Shim --- src/core/main.c | 8 +- src/power/power-handler.c | 218 +++++++++++++++------------------------------- src/power/power-handler.h | 11 ++- 3 files changed, 86 insertions(+), 151 deletions(-) diff --git a/src/core/main.c b/src/core/main.c index bf798f4..64d44c8 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -93,8 +93,14 @@ static int deviced_main(int argc, char **argv) mainloop = g_main_loop_new(NULL, FALSE); ret = check_power_flag(); - if (ret) + if (ret) { + /* assume reboot was requested and deviced was + * killed/terminated in middle of it - resume + * procedure + */ + poweroff_procedure(); return 0; + } handle = dbus_handle_get_connection(G_BUS_TYPE_SYSTEM, FALSE); if (!handle) diff --git a/src/power/power-handler.c b/src/power/power-handler.c index b8fc0a3..d63a29e 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -72,20 +72,44 @@ #define POWER_CONF_FILE "/etc/deviced/power.conf" -struct power_flag { - enum poweroff_type type; - const char *path; -} power_flags[] = { - { POWER_OFF_DIRECT, POWER_FLAG_POWEROFF }, - { POWER_OFF_RESTART, POWER_FLAG_REBOOT }, -}; - static struct timeval tv_start_poweroff; static dd_list *poweroff_options; static struct power_option poweroff_opt; static bool during_poweroff; static dd_list *poweroff_handles; +static char *poweroff_type_flagpaths[] = { // index denotes type + [POWER_OFF_DIRECT] = POWER_FLAG_POWEROFF, + [POWER_OFF_REBOOT] = POWER_FLAG_REBOOT, +}; +static char *poweroff_type_names[] = { // index denotes type + [POWER_OFF_POWEROFF] = POWER_POWEROFF, + [POWER_OFF_POPUP] = PWROFF_POPUP, + [POWER_OFF_REBOOT] = POWER_REBOOT, + [POWER_OFF_DIRECT] = "", +}; + +static char *poweroff_type_to_name(enum poweroff_type type) +{ + if (type >= ARRAY_SIZE(poweroff_type_names)) + return NULL; + + return poweroff_type_names[type]; +} + +static enum poweroff_type poweroff_name_to_type(char *name) +{ + if (!name) + goto out; + + for (int i = 0; i < ARRAY_SIZE(poweroff_type_names); i++) { + if (poweroff_type_names[i] && strcmp(poweroff_type_names[i], name) == 0) + return i; + } +out: + return POWER_OFF_INVALID; +} + static void poweroff_start_animation(void) { int ret; @@ -146,9 +170,6 @@ static int disable_systemd_journald(void) _E("failed to stop 'systemd-journald.service'"); return ret; } - _I("done %s with %s option", - poweroff_opt.name ? poweroff_opt.name : "NULL", - poweroff_opt.option ? poweroff_opt.option : "NULL"); return 0; } @@ -246,12 +267,8 @@ static void restart(char *option) } } -static int poweroff_procedure(void) +int poweroff_procedure(void) { - _I("%s option(%s)", - poweroff_opt.name ? poweroff_opt.name : "NULL", - poweroff_opt.option ? poweroff_opt.option : "NULL"); - powerdown(); if (poweroff_opt.type == POWER_OFF_DIRECT) { @@ -271,48 +288,15 @@ static int poweroff_procedure(void) int check_power_flag(void) { - char buf[32] = { 0, }; - char *option = NULL; - int i, index; - int fd; - ssize_t len; - - index = -1; - for (i = 0 ; i < ARRAY_SIZE(power_flags) ; i++) { - if (access(power_flags[i].path, F_OK) == 0) { - index = i; - break; - } - } - if (index < 0) - return 0; - - if (power_flags[index].type == POWER_OFF_DIRECT) { - poweroff(); - return 1; - } - - fd = open(power_flags[index].path, O_RDONLY); - if (fd >= 0) { - len = read(fd, buf, sizeof(buf) - 1); - close(fd); - if (len < 0) { - len = errno; - _E("read() failed (%zd)", len); - return 0; + for (int i = 0; i < ARRAY_SIZE(poweroff_type_flagpaths); i++) { + if (access(poweroff_type_flagpaths[i], F_OK) == 0) { + poweroff_opt.type = i; + poweroff_opt.option = NULL; + return 1; } - while (len > 0 && buf[len - 1] == '\n') - len--; - buf[len] = '\0'; - _I("reboot option (%s)", buf); } - if (strlen(buf) > 0) - option = buf; - - restart(option); - - return 1; + return 0; } static void make_power_flag(enum poweroff_type type, char *option) @@ -320,15 +304,11 @@ static void make_power_flag(enum poweroff_type type, char *option) const char *path; int fd; ssize_t len; - int i; - path = NULL; - for (i = 0 ; i < ARRAY_SIZE(power_flags) ; i++) { - if (power_flags[i].type == type) { - path = power_flags[i].path; - break; - } - } + if (type <= 0 || type >= ARRAY_SIZE(poweroff_type_flagpaths)) + return; + + path = poweroff_type_flagpaths[type]; if (!path) return; @@ -385,19 +365,14 @@ static gboolean poweroff_timeout_cb(void *data) } _D("No timer left"); - if (!poweroff_opt.name) { - _E("There is no option"); + char *name = poweroff_type_to_name(poweroff_opt.type); + if (!name) { + _E("Invalid type (%d)", poweroff_opt.type); goto out; } watchdog_notify(); - if (poweroff_opt.type != POWER_OFF_DIRECT && - poweroff_opt.type != POWER_OFF_RESTART) { - _E("Invalid type (%d)", poweroff_opt.type); - goto out; - } - during_poweroff = true; make_power_flag(poweroff_opt.type, poweroff_opt.option); @@ -412,7 +387,7 @@ static gboolean poweroff_timeout_cb(void *data) ret = poweroff_procedure(); if (ret < 0) - _E("Failed to %s (%d)", poweroff_opt.name, ret); + _E("Failed to %s (%d)", name, ret); out: if (disp_plgn.update_pm_setting) @@ -488,53 +463,15 @@ static int pwroff_popup(void) return launch_system_app(APP_POWERKEY, 2, APP_KEY_TYPE, APP_POWERKEY); } -static int get_poweroff_type_enum(char *type, enum poweroff_type *val) +static int poweroff_option_valid(enum poweroff_type type_e, char *option) { - size_t len; - - if (!type || !val) - return -EINVAL; - - len = strlen(type) + 1; - - if (!strncmp(POWER_POWEROFF, type, len)) { - *val = POWER_OFF_DIRECT; - return 0; - } - - if (!strncmp(PWROFF_POPUP, type, len)) { - *val = POWER_OFF_POPUP; - return 0; - } - - if (!strncmp(POWER_REBOOT, type, len)) { - *val = POWER_OFF_RESTART; - return 0; - } - - _E("Invalid poweroff type (%s)", type); - return -EINVAL; -} - -static int find_poweroff_option(char *type, char *option) -{ - int ret; dd_list *l; struct power_option *elem; - enum poweroff_type type_e; - - if (!type) - return -EINVAL; - - ret = get_poweroff_type_enum(type, &type_e); - if (ret < 0) { - _E("Failed to get type enum value (%d)", ret); - return ret; - } DD_LIST_FOREACH(poweroff_options, l, elem) { if (elem->type != type_e) continue; + if (option) { if (elem->option == NULL) continue; @@ -544,21 +481,10 @@ static int find_poweroff_option(char *type, char *option) if (elem->option != NULL) continue; } - poweroff_opt.type = elem->type; - if (poweroff_opt.name) { - free(poweroff_opt.name); - poweroff_opt.name = NULL; - } - poweroff_opt.name = (elem->name ? strdup(elem->name) : NULL); - if (poweroff_opt.option) { - free(poweroff_opt.option); - poweroff_opt.option = NULL; - } - poweroff_opt.option = (option ? strdup(option) : NULL); - return 0; + return 1; } - return -ENOENT; + return 0; } static void poweroff_send_broadcast(int status) @@ -579,6 +505,7 @@ static void poweroff_send_broadcast(int status) g_variant_new("(i)", status)); } + static int power_execute_pid(char *type, char *option, pid_t pid) { int ret; @@ -588,25 +515,29 @@ static int power_execute_pid(char *type, char *option, pid_t pid) return -EINVAL; } - if (!type) + enum poweroff_type type_e = poweroff_name_to_type(type); + if (type_e == POWER_OFF_INVALID) { + _E("Failed to get type enum value (%d)", type_e); + return -EINVAL; + } + if (poweroff_option_valid(type_e, option)) { + poweroff_opt.type = type_e; + free(poweroff_opt.option); + poweroff_opt.option = NULL; + if (option) + poweroff_opt.option = strdup(option); + } else { + _E("Failed to find supported %s option %s", type, (option ? option : "NULL")); return -EINVAL; - - ret = find_poweroff_option(type, option); - if (ret < 0) { - _E("Failed to find supported %s option %s (%d)", type, (option ? option : "NULL"), ret); - return ret; } - if (strncmp(PWROFF_POPUP, poweroff_opt.name, PWROFF_POPUP_LEN) == 0) { + if (poweroff_opt.type == POWER_OFF_POPUP) { _D("request popup"); - if (poweroff_opt.type == POWER_OFF_POPUP) { - vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, poweroff_opt.type); - pwroff_popup(); - } + vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, poweroff_opt.type); + pwroff_popup(); return 0; } - poweroff_opt.pid = pid; /* Poweroff event broadcasting */ system_shutdown_send_system_event(); poweroff_send_broadcast(poweroff_opt.type); @@ -806,13 +737,8 @@ static int add_poweroff_option(enum poweroff_type type, char *option) struct power_option *opt; char *name; - if (type == POWER_OFF_POPUP) - name = PWROFF_POPUP; - else if (type == POWER_OFF_DIRECT) - name = POWER_POWEROFF; - else if (type == POWER_OFF_RESTART) - name = POWER_REBOOT; - else { + name = poweroff_type_to_name(type); + if (!name) { _E("Invalid type (%d)", type); return -EINVAL; } @@ -824,12 +750,11 @@ static int add_poweroff_option(enum poweroff_type type, char *option) } opt->type = type; - opt->name = strdup(name); opt->option = (option ? strdup(option) : NULL); DD_LIST_APPEND(poweroff_options, opt); - _D("Add %s option (%s)", opt->name, opt->option); + _D("Add %s option (%s)", name, opt->option); return 0; } @@ -883,6 +808,7 @@ static void power_init(void *data) register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + add_poweroff_option(POWER_OFF_POWEROFF, NULL); add_poweroff_option(POWER_OFF_DIRECT, NULL); add_poweroff_option(POWER_OFF_RESTART, NULL); add_poweroff_option(POWER_OFF_POPUP, NULL); diff --git a/src/power/power-handler.h b/src/power/power-handler.h index ae545a0..1406b3f 100644 --- a/src/power/power-handler.h +++ b/src/power/power-handler.h @@ -28,17 +28,19 @@ #define PWROFF_POPUP "pwroff-popup" #define PWROFF_POPUP_LEN 12 + enum poweroff_type { - POWER_OFF_NONE = 0, + POWER_OFF_INVALID = 0, + POWER_OFF_NONE = POWER_OFF_INVALID, // compat only POWER_OFF_POPUP, + POWER_OFF_POWEROFF, /* replaces POWER_OFF_DIRECT */ + POWER_OFF_REBOOT, + POWER_OFF_RESTART = POWER_OFF_REBOOT, // compat only POWER_OFF_DIRECT, - POWER_OFF_RESTART, }; struct power_option { - pid_t pid; enum poweroff_type type; - char *name; char *option; }; @@ -49,5 +51,6 @@ struct poweroff_handle { }; int check_power_flag(void); +int poweroff_procedure(void); #endif /* __POWER_HANDLE_H__ */ -- 2.7.4 From 621089c73c7819e6ba57fce0cc3f72201c9d59b7 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 10 Jan 2019 00:17:22 +0000 Subject: [PATCH 15/16] power: Add deviced-shutdown This commit provides special binary that is going to handle Tizen system shutdown. This utility is called by systemd, not deviced. The final shutdown scheme is going to look like following: 1. deviced receivies request to shutdown/reboot the system, - preparation is performed (send signals, etc) - operation start is marked in /run/ - hardcoded actions are started - depending on shutdown type following is performed: + direct shutdown: system is rebooted immidietly (end of flow) + other: dbus request to systemd is sent 2. systemd receives the "poweroff" request - supported requests are Reboot, PowerOff & Halt - systemd (pid1) replaces it's own process with shutdown binary (execve("/usr/lib/systemd/systemd-shutdown")) - shutdown binary is provided by deviced package by alternatives mechanism # ls -l systemd-shutdown systemd-shutdown -> /etc/alternatives/systemd-shutdown # ls -l /etc/alternatives/systemd-shutdown /etc/alternatives/systemd-shutdown -> /usr/lib/systemd/deviced-shutdown (alternatives allow both systemd and deviced to "provide" same binary, with deviced having higher priority being selected as the one to use) 3. /usr/lib/systemd/systemd-shutdown becomes pid1 - original systemd1 manager is no longer available, meaning no restart, watchdog, socket/path/etc activation is handled. - depending on systemd-provided params it performs reboot or poweroff Change-Id: I46b4d0f375a1a6e7fc3e1d74b0530d7ec73ccb12 Signed-off-by: Hyotaek Shim --- CMakeLists.txt | 7 ++ packaging/deviced.spec | 15 ++++- src/power-shutdown/shutdown.c | 150 ++++++++++++++++++++++++++++++++++++++++++ src/power/power-handler.c | 80 +++++++++------------- src/power/power-handler.h | 2 + 5 files changed, 204 insertions(+), 50 deletions(-) create mode 100644 src/power-shutdown/shutdown.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 013b1f2..66ebf37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -227,6 +227,13 @@ SET(deviced_LDFLAGS ${pkgs_LDFLAGS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-lrt -ldl -lm" shared) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) +IF(POWER_MODULE STREQUAL on) + ADD_EXECUTABLE(deviced-shutdown src/power-shutdown/shutdown.c src/core/common.c src/core/execute.c) + SET(deviced-shutdown_LDFLAGS ${pkgs_LDFLAGS}) + TARGET_LINK_LIBRARIES(deviced-shutdown ${pkgs_LDFLAGS} "-lrt -ldl -lm" shared) + INSTALL(TARGETS deviced-shutdown DESTINATION lib/systemd) +ENDIF() + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/deviced/ DESTINATION include/${PROJECT_NAME} FILES_MATCHING PATTERN "*_doc.h" EXCLUDE diff --git a/packaging/deviced.spec b/packaging/deviced.spec index b3713e1..6a7b35f 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -41,9 +41,11 @@ BuildRequires: pkgconfig(capi-system-device) Requires: %{name}-tools = %{version}-%{release} %{?systemd_requires} Requires(post): /usr/bin/vconftool +Requires(post): %{_sbindir}/update-alternatives +Requires(preun): %{_sbindir}/update-alternatives %description -deviced +Deviced %package -n libdeviced Summary: Deviced library @@ -178,6 +180,9 @@ mkdir -p %{buildroot}%{TZ_SYS_DUMPGEN} install -m 775 scripts/dump_pmstate_log.sh %{buildroot}%{TZ_SYS_DUMPGEN}/dump_pmstate_log.sh %post +# Assume power module is on (-DPOWER_MODULE=on) +update-alternatives --install %{_libdir}/systemd/systemd-shutdown systemd-shutdown %{_libdir}/systemd/deviced-shutdown 500 + #memory type vconf key init users_gid=$(getent group %{TZ_SYS_USER_GROUP} | cut -f3 -d':') @@ -186,6 +191,10 @@ if [ "$1" == "1" ]; then systemctl restart deviced.service fi +%preun +# Assume power module is on (-DPOWER_MODULE=on) +update-alternatives --remove %{_libdir}/systemd/systemd-shutdown systemd-shutdown %{_libdir}/systemd/deviced-shutdown + %postun systemctl daemon-reload if [ "$1" == "0" ]; then @@ -238,6 +247,10 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %{_sysconfdir}/deviced/usb-host-test/descs %{_sysconfdir}/deviced/usb-host-test/strs +# Assume power module is on (-DPOWER_MODULE=on) +%{_libdir}/systemd/deviced-shutdown + + %files -n libdeviced %manifest deviced.manifest %license LICENSE.Apache-2.0 diff --git a/src/power-shutdown/shutdown.c b/src/power-shutdown/shutdown.c new file mode 100644 index 0000000..0ac97c5 --- /dev/null +++ b/src/power-shutdown/shutdown.c @@ -0,0 +1,150 @@ +/* + * deviced-shutdown: deviced's replacement for systemd-shutdown binary + * + * This binary is supposed to be called on Tizen system by systemd + * manager during shutdown, as result of eg. dbus call to Reboot + * method, test via: + * + * # dbus-send --print-reply --system --dest=org.freedesktop.systemd1 --type=method_call /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager.(Reboot|PowerOff) + * + * + * 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 +#include +#include +#include +#include +#include +#include +#include + +#include "dd-deviced.h" +#include "core/log.h" +#include "core/common.h" + +#define UMOUNT_RW_PATH_USER "/opt/usr" +#define UMOUNT_RW_PATH_SYSTEM "/opt" +#define MAX_UMOUNT_KILL_RETRY 4 + +char *progname; + +static int usage(void) +{ + printf("%s: Invalid command specified (supported are: reboot, halt|poweroff, exit)\n", progname); + return 0; +} + +static void umount_partitions(void) +{ + umount_partition_by_kill(UMOUNT_RW_PATH_USER, MAX_UMOUNT_KILL_RETRY); + umount_partition_by_kill(UMOUNT_RW_PATH_SYSTEM, MAX_UMOUNT_KILL_RETRY); +} + +static void sigchld(int signo) +{ + int wstatus; + int r; + + do + r = waitpid(-1, &wstatus, WNOHANG); + while (r > 0); +} + +static void autoboot(void) +{ + static char buf[4096] = {0,}; + int fd = open("/run/reboot", O_RDONLY); // XXX POWER_FLAG_REBOOT + if (fd >= 0) { + (void)read(fd, buf, sizeof(buf)); + close(fd); + } + + printf("%s: reboot param is <%s>\n", progname, buf); + syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, + buf[0] != 0 ? LINUX_REBOOT_CMD_RESTART2 : LINUX_REBOOT_CMD_RESTART, + &buf); +} + +int main(int ac, char *av[]) +{ + enum { + ARG_LOGLEVEL, + ARG_LOGTARGET, + ARG_LOGCOLOR, + ARG_LOGLOCATION, + ARG_EXITCODE + }; + static struct option opts[] = { + {"log-level", required_argument, NULL, ARG_LOGLEVEL}, + {"log-target", required_argument, NULL, ARG_LOGTARGET}, + {"log-color", optional_argument, NULL, ARG_LOGCOLOR}, + {"log-location", optional_argument, NULL, ARG_LOGLOCATION}, + {"exit-code", required_argument, NULL, ARG_EXITCODE}, + {}, + }; + + progname = av[0]; + + int c; + while ((c = getopt_long(ac, av, "", opts, NULL)) >= 0) + ; // not supported for now + + int cmd; + char *cmd_name = av[optind]; + if (optind >= ac || !cmd_name) + return usage(); + + if (strcmp(cmd_name, "reboot") == 0) + cmd = RB_AUTOBOOT; + else if (strcmp(cmd_name, "halt") == 0 || strcmp(cmd_name, "poweroff") == 0) + cmd = RB_POWER_OFF; + else if (strcmp(cmd_name, "exit") == 0) + exit(0); + else + // XXX this is critical failure - we are pid1 already + // and can't perform requested action - exit below + // will cause system to panic() and, hopefully, reboot + // (depends on sysctls) + return usage(); + + printf("%s: executing %s action\n", progname, cmd_name); + + (void)signal(SIGCHLD, sigchld); + (void)signal(SIGHUP, SIG_IGN); + (void)signal(SIGTERM, SIG_IGN); + + if (!is_emulator()) { + printf("%s: unmounting rw partitions\n", progname); + umount_partitions(); + } + + printf("%s: flushing filesystems\n", progname); + + sync(); + + printf("%s: performing %s\n", progname, cmd_name); + + if (cmd == RB_AUTOBOOT) + autoboot(); + else + reboot(cmd); + + return 1; +} diff --git a/src/power/power-handler.c b/src/power/power-handler.c index d63a29e..a084cc7 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -61,14 +61,9 @@ #define POWEROFF_WAIT_RESOURCED (0.5*1000) /* 0.5 seconds */ #define POWEROFF_WAIT_MAX 10 /* 10 seconds */ -#define SIGNAL_POWEROFF_STATE "ChangeState" - -#define UMOUNT_RW_PATH_USER "/opt/usr" -#define UMOUNT_RW_PATH_SYSTEM "/opt" -#define MAX_UMOUNT_KILL_RETRY 4 +#define POWEROFF_WAIT_SYSTEMD_MS (30 * 1000/*ms*/) /* 30 seconds */ -#define POWER_FLAG_POWEROFF "/run/"POWER_POWEROFF -#define POWER_FLAG_REBOOT "/run/"POWER_REBOOT +#define SIGNAL_POWEROFF_STATE "ChangeState" #define POWER_CONF_FILE "/etc/deviced/power.conf" @@ -194,14 +189,6 @@ static bool disable_coredump_handler(void) return is_ok; } -/* umount usr data partition */ -static void unmount_rw_partition(void) -{ - umount_partition_by_kill(UMOUNT_RW_PATH_USER, MAX_UMOUNT_KILL_RETRY); - umount_partition_by_kill(UMOUNT_RW_PATH_SYSTEM, MAX_UMOUNT_KILL_RETRY); - sync(); -} - static void powerdown(void) { static int wait; @@ -236,52 +223,49 @@ static void powerdown(void) } watchdog_notify(); - - if (!is_emulator()) - unmount_rw_partition(); } -static void reboot_with_option(int cmd, char *option) +static void poweroff_request_shutdown() { - if (!cmd) + _I("Requested power off via systemd"); + + char *method; + + if (poweroff_opt.type == POWER_OFF_REBOOT) + method = "Reboot"; + else if (poweroff_opt.type == POWER_OFF_POWEROFF) + method = "PowerOff"; + else { + _E("poweroff invalid type (%d)", poweroff_opt.type); return; - if (syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, - cmd, (void *)option) < 0) - _E("Failed to reboot with option (%d)", errno); -} + } -static void poweroff(void) -{ - _I("Power off !!!"); - reboot_with_option(LINUX_REBOOT_CMD_POWER_OFF, NULL); + dbus_handle_method_sync_timeout(SYSTEMD_DBUS_DEST, + SYSTEMD_DBUS_PATH, + SYSTEMD_DBUS_IFACE_MANAGER, + method, + NULL, + NULL, + POWEROFF_WAIT_SYSTEMD_MS); } -static void restart(char *option) +static void poweroff_direct(void) { - if (option) { - _I("Restart with option %s !!!", option); - reboot_with_option(LINUX_REBOOT_CMD_RESTART2, option); - } else { - _I("Restart !!!"); - reboot_with_option(LINUX_REBOOT_CMD_RESTART, NULL); - } + _I("Requested power off without systemd (direct call)"); + if (syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, + LINUX_REBOOT_CMD_POWER_OFF, NULL) < 0) + _E("Failed to poweroff (%d)", errno); } int poweroff_procedure(void) { - powerdown(); - - if (poweroff_opt.type == POWER_OFF_DIRECT) { - poweroff(); - return 0; - } - if (poweroff_opt.type == POWER_OFF_RESTART) { - restart(poweroff_opt.option); - return 0; - } + powerdown(); - _E("poweroff invalid type (%d)", poweroff_opt.type); + if (poweroff_opt.type == POWER_OFF_DIRECT) + poweroff_direct(); + else + poweroff_request_shutdown(); return 0; } @@ -508,8 +492,6 @@ static void poweroff_send_broadcast(int status) static int power_execute_pid(char *type, char *option, pid_t pid) { - int ret; - if (during_poweroff) { _E("during poweroff"); return -EINVAL; diff --git a/src/power/power-handler.h b/src/power/power-handler.h index 1406b3f..968e17a 100644 --- a/src/power/power-handler.h +++ b/src/power/power-handler.h @@ -28,6 +28,8 @@ #define PWROFF_POPUP "pwroff-popup" #define PWROFF_POPUP_LEN 12 +#define POWER_FLAG_POWEROFF "/run/"POWER_POWEROFF +#define POWER_FLAG_REBOOT "/run/"POWER_REBOOT enum poweroff_type { POWER_OFF_INVALID = 0, -- 2.7.4 From c4546512bb84cf1f6f6cd4120ecf644afc83f32b Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 31 Jan 2019 11:58:47 +0900 Subject: [PATCH 16/16] Version 5.5.0 Change-Id: I5bfa2097c864342fccd20c0660524a0c35ac5580 Signed-off-by: Hyotaek Shim --- packaging/deviced.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 6a7b35f..db995fd 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -5,7 +5,7 @@ Name: deviced Summary: Deviced -Version: 5.0.0 +Version: 5.5.0 Release: 1 Group: System/Management License: Apache-2.0 -- 2.7.4