From 836858e862deeb53959532714c5714cefc930b2f Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 10 Mar 2020 10:36:25 +0900 Subject: [PATCH 01/16] Change bezel state when vconf changes in LCDOFF Change-Id: I3209c2b1c797d47420acffe4e2dbc93426662dc3 Signed-off-by: Youngjae Cho --- plugins/wearable/display/bezel.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plugins/wearable/display/bezel.c b/plugins/wearable/display/bezel.c index 82f0132..9d9eb3c 100644 --- a/plugins/wearable/display/bezel.c +++ b/plugins/wearable/display/bezel.c @@ -21,6 +21,7 @@ #include "core/device-notifier.h" #include "display/util.h" #include "display/poll.h" +#include "display/core.h" #include "display-ops.h" #include #include @@ -36,6 +37,8 @@ enum bezel_type { BEZEL_SOFT, }; +static enum bezel_state bezel_wakeup_control(void); + static struct bezel_device *bezel_dev; static int bezel_wakeup = 0; static int theater_mode = 0; @@ -57,18 +60,32 @@ static void bezel_changed_cb(keynode_t *key_nodes, void *data) static void theater_changed_cb(keynode_t *key_nodes, void *data) { + enum bezel_state state; + assert(key_nodes); theater_mode = vconf_keynode_get_bool(key_nodes); _I("Theater mode: %d.", theater_mode); + + if (pm_cur_state == LCD_OFF) { + state = bezel_wakeup_control(); + bezel_dev->set_state(state); + } } static void goodnight_changed_cb(keynode_t *key_nodes, void *data) { + enum bezel_state state; + assert(key_nodes); goodnight_mode = vconf_keynode_get_bool(key_nodes); _I("Goodnight mode: %d.", goodnight_mode); + + if (pm_cur_state == LCD_OFF) { + state = bezel_wakeup_control(); + bezel_dev->set_state(state); + } } static void bezel_rotary_event_cb(keynode_t *key_nodes, void *data) -- 2.7.4 From b0c229c1801eae38d11d2e40de278cb6ef21322c Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Tue, 10 Mar 2020 11:22:01 +0900 Subject: [PATCH 02/16] Move checking current usb mode to usb_change_mode Change-Id: I96cab5ebc7647cadda4e93c5f7b6ce025b4caafb --- src/usb/usb-debug.c | 5 ----- src/usb/usb-tethering.c | 5 ----- src/usb/usb.c | 12 +++++------- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/usb/usb-debug.c b/src/usb/usb-debug.c index 3e8139a..878e090 100644 --- a/src/usb/usb-debug.c +++ b/src/usb/usb-debug.c @@ -108,11 +108,6 @@ static int usb_debug_mode_changed(void *on) new_mode = USB_FUNCTION_MTP | USB_FUNCTION_ACM; } - if (curr_mode == new_mode) { - _I("already USB mode(0x%x) was used", new_mode); - return 0; - } - ret = usb_change_mode(new_mode); if (ret < 0) _E("Failed to change USB mode to (%d).", new_mode); diff --git a/src/usb/usb-tethering.c b/src/usb/usb-tethering.c index 884bc25..a885585 100644 --- a/src/usb/usb-tethering.c +++ b/src/usb/usb-tethering.c @@ -92,11 +92,6 @@ static int usb_tethering_mode_changed(void *on) saved_prev_mode = USB_FUNCTION_NONE; } - if (curr_mode == new_mode) { - _I("already USB mode(0x%x) was used", new_mode); - return 0; - } - ret = usb_change_mode(new_mode); if (ret < 0) _E("Failed to change USB mode to (0x%x).", new_mode); diff --git a/src/usb/usb.c b/src/usb/usb.c index fcaece7..8335c1b 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -328,14 +328,12 @@ int usb_change_mode(unsigned int new_mode) const unsigned int curr_mode = usb_state_get_current_mode(); const unsigned int prev_mode = usb_state_get_selected_mode(); - _I("USB change mode (0x%x) -> (0x%x), current running mode (0x%x)", prev_mode, new_mode, curr_mode); + if (prev_mode == new_mode) { + _I("already using USB mode(0x%x), current running mode (0x%x)", prev_mode, curr_mode); + return 0; + } - /* - * Information: Because the user explicitly calls this through dbus or vconf, - * you should not check whether the current and new modes are different. - * - * if (curr_mode == new_mode) return; - */ + _I("USB change mode (0x%x) -> (0x%x), current running mode (0x%x)", prev_mode, new_mode, curr_mode); /* * When you change the gadget(usb_change_gadget) for new usb mode, you must disable the gadget first. -- 2.7.4 From 66598f33af1800b26e7af9ddce9b21254fca91eb Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 10 Mar 2020 14:36:27 +0900 Subject: [PATCH 03/16] Change vconfkey about ambient condition Change-Id: I8411394a2f2317374a503349a0bea095b78051d4 Signed-off-by: Youngjae Cho --- src/display/ambient-mode.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index 1469d5c..a615824 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -236,15 +236,16 @@ static void ambient_init(void *data) { int ret; - ret = vconf_get_bool(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, &ambient_condition); + ret = vconf_get_bool("db/starter/always_on_display", &ambient_condition); if (ret < 0) { - _E("Failed to get vconf value for ambient mode: %d", vconf_get_ext_errno()); - ambient_condition = false; - } - _I("Ambient mode condition is %d.", ambient_condition); + _E("Failed to get initial AOD condition. AOD is not going to work."); + return; + } else { + _I("Ambient mode condition is %d.", ambient_condition); - vconf_notify_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - ambient_set_condition, NULL); + vconf_notify_key_changed("db/starter/always_on_display", + ambient_set_condition, NULL); + } ret = subscribe_dbus_signal(NULL, DEVICED_OBJECT_PATH, -- 2.7.4 From c57a913cdfd2c23100fcdc310f67e9756c50743a Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Tue, 10 Mar 2020 20:58:45 +0900 Subject: [PATCH 04/16] Remove VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL replaced by "db/starter/always_on_display" Change-Id: Ie2b756eb9ed5e963ea6127a3d4000eeb99fde61b Signed-off-by: Hyotaek Shim --- src/display/ambient-mode.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index a615824..c0ed7f8 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -260,8 +260,7 @@ static void ambient_init(void *data) static void ambient_exit(void *data) { ambient_set_state(false); - vconf_ignore_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - ambient_set_condition); + vconf_ignore_key_changed("db/starter/always_on_display", ambient_set_condition); } static const struct display_ops ambient_ops = { -- 2.7.4 From 4e1b763e5054c50a234edafedcc47119aa3e75dd Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 10 Mar 2020 18:02:20 +0900 Subject: [PATCH 05/16] Introduce 3 level AOD brightness Change-Id: Iae0ca878f7702e72cccf9ff54f26da59e3b3e78e Signed-off-by: Youngjae Cho --- plugins/wearable/display/device-interface.c | 41 ++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 6 deletions(-) mode change 100644 => 100755 plugins/wearable/display/device-interface.c diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c old mode 100644 new mode 100755 index eb6414d..b03e5c4 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -43,6 +43,7 @@ #include "device-node.h" #include "display/display-dpms.h" #include "battery-monitor.h" +#include "battery/power-supply.h" #define SET_SUSPEND_TIME 0.5 @@ -89,6 +90,9 @@ static bool vital_sleep; static int dpms_running_state = DPMS_SETTING_DONE; static struct display_device *display_dev; static guint release_timer; +static int aod_max_level = -1; +static int aod_normal_level = -1; +static int aod_min_level = -1; struct display_device *display_dev_get(void) { @@ -808,12 +812,23 @@ static int backlight_transit_state(int state) { int brt, val; int start, end; + static int aod_brightness_level; backlight_ops.get_brightness(&brt); if (state == DPMS_OFF) { start = brt; - end = display_conf.aod_enter_level; + + /* There are three levels of AOD brightness: max, normal, min brightness. + * At first, AOD brightness is set to normal level when charger is connected, + * otherwise set to max. And then, if the current brightness is lower than this + * initialized AOD brightness, set AOD brightness to min level brightness. */ + if (battery.online_type && aod_normal_level > 0) + aod_brightness_level = aod_normal_level; + else if (aod_max_level > 0) + aod_brightness_level = aod_max_level; + else + aod_brightness_level = display_conf.aod_enter_level; /* * The value of backlight_ops.get_brightness is system brightness. @@ -822,18 +837,24 @@ static int backlight_transit_state(int state) */ get_brightness(&val); - if (val > display_conf.aod_enter_level) - backlight_ops.transit_brt(start, end, display_conf.brightness_change_step); + if ((val < aod_brightness_level) && (aod_min_level > 0)) + aod_brightness_level = aod_min_level; + + if (val > aod_brightness_level) { + _D("backlight transit start %d end %d DPMS OFF", start, aod_brightness_level); + backlight_ops.transit_brt(start, aod_brightness_level, display_conf.brightness_change_step); + } } else { /* prevent transit effect when another effect is already executed */ - if (brt != display_conf.aod_enter_level) { + if (brt != aod_brightness_level) { _W("effect is already executed brt(%d) aod_level(%d)", - brt, display_conf.aod_enter_level); + brt, aod_brightness_level); return 0; } - start = display_conf.aod_enter_level; + start = aod_brightness_level; end = default_brightness; + _D("backlight transit start %d end %d DPMS ON", start, end); backlight_ops.transit_brt(start, end, display_conf.brightness_change_step); } @@ -965,7 +986,15 @@ int display_service_load(void) return -EPERM; } + if (display_dev && display_dev->get_aod_brightness) { + r = display_dev->get_aod_brightness(&aod_max_level, &aod_normal_level, &aod_min_level); + if (r == 0) { + _I("Use various AOD brightness : max %d, normal %d, min %d", aod_max_level, aod_normal_level, aod_min_level); + } + } + _D("Display device structure load success."); + return 0; } -- 2.7.4 From c59e9b7f81d5454133f791b467b3468d29115d49 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Wed, 11 Mar 2020 13:42:24 +0900 Subject: [PATCH 06/16] Remove the duplicated usb_client->disable() function. Change-Id: Idf5a5e321facd206f3f7cac3e1b9cf8509f8b9b9 --- src/usb/usb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/usb/usb.c b/src/usb/usb.c index 8335c1b..2be5c81 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -222,7 +222,6 @@ static int usb_change_gadget(unsigned mode) goto out; } - usb_client->disable(usb_client); ret = usb_client->reconfigure_gadget(usb_client, gadget); gadget_translator->cleanup_gadget(gadget); if (ret) { @@ -345,7 +344,7 @@ int usb_change_mode(unsigned int new_mode) /* Special case: Because usb gadget is disabled, temporarily switch usb state from available to connected. */ send_usb_state_changed_event(VCONFKEY_SYSMAN_USB_CONNECTED); - ret = usb_disable(); /* Need to clean up because usb_change_gadget() also calls usb_client->disable() */ + ret = usb_disable(); if (ret < 0) { _E("Failed to disable current USB mode."); return ret; -- 2.7.4 From cc7012f0bb62ba47bc8ef2c1a1788a558aa5ece9 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 11 Mar 2020 14:06:16 +0900 Subject: [PATCH 07/16] Add timer to ignore discharging signal from kernel Change-Id: Ib6e495c4515fe193b2e38332d818621e8d03a26a Signed-off-by: Youngjae Cho --- src/battery/lowbat-handler.c | 33 ++++++++++++++++++++++++++++++++- src/battery/power-supply.c | 8 -------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 670d2b2..121f325 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -96,6 +96,8 @@ static int noti_crit = NOTI_NONE; static dd_list *lpe; static int scenario_count; +static guint low_batt_sig_timer; + static int lowbat_monitor_init(void *data); static int lowbat_initialized(void *data) @@ -934,11 +936,40 @@ static void lowbat_exit(void *data) int status = BATTERY_DISABLED; lowbat_initialized(&status); + if (low_batt_sig_timer) { + g_source_remove(low_batt_sig_timer); + low_batt_sig_timer = 0; + } +} + +static gboolean low_battery_charge_status(void *data) +{ + low_batt_sig_timer = 0; + battery.charging_level = lowbat_monitor(data); + if (battery.charging_level > 0 && old_battery.charging_level != battery.charging_level) { + if (vconf_set_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery.charging_level) < 0) + _E("Fail to set level."); + if (power_supply_broadcast(CHARGE_LEVEL_SIGNAL, battery.charging_level) < 0) + _E("power_supply_broadcast failed"); + } + return G_SOURCE_REMOVE; } static int lowbat_execute(void *data) { - return lowbat_monitor(data); + /* In battery kernel side, it has a requirement that battery charging event must get quickly. + * So deviced receives the discharging and charging event within 1.5 sec, + * added a timer to wait for the second signal, if there is no second signal then execute + * the lowbat_execute. + */ + if (low_batt_sig_timer) { + g_source_remove(low_batt_sig_timer); + low_batt_sig_timer = 0; + } else { + low_batt_sig_timer = g_timeout_add(1500, low_battery_charge_status, data); + } + + return 0; } static const struct device_ops lowbat_device_ops = { diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 1b60cf2..a39ce17 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -846,14 +846,6 @@ static void process_power_supply(void *data) broadcasted = false; } battery.charging_level = lowbat_execute(data); - if (battery.charging_level > 0 && old_battery.charging_level != battery.charging_level) { - ret = vconf_set_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery.charging_level); - if (ret < 0) - _E("Failed to set vconf value for battery capacity: %d", vconf_get_ext_errno()); - - if (power_supply_broadcast(CHARGE_LEVEL_SIGNAL, battery.charging_level) < 0) - broadcasted = false; - } if (update_online()) { ret = vconf_set_int(VCONFKEY_SYSMAN_CHARGER_STATUS, online_status); -- 2.7.4 From 293a785f59166585461891e1a127a4e33269461a Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Wed, 11 Mar 2020 20:15:53 +0900 Subject: [PATCH 08/16] Fix lowbat_execute() timer to keep the last one Change-Id: I434fb580ff90e2b5bcdd78d6fc7bede495954eb3 Signed-off-by: Hyotaek Shim --- src/battery/lowbat-handler.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 121f325..69416db 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -962,12 +962,10 @@ static int lowbat_execute(void *data) * added a timer to wait for the second signal, if there is no second signal then execute * the lowbat_execute. */ - if (low_batt_sig_timer) { + if (low_batt_sig_timer) g_source_remove(low_batt_sig_timer); - low_batt_sig_timer = 0; - } else { - low_batt_sig_timer = g_timeout_add(1500, low_battery_charge_status, data); - } + + low_batt_sig_timer = g_timeout_add(1500, low_battery_charge_status, data); return 0; } -- 2.7.4 From 66ee841678906a88ce0fd6cb869ada93d01b8b86 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Tue, 10 Mar 2020 13:19:18 +0900 Subject: [PATCH 09/16] Fix memory leak Change-Id: Ieff593d532ec1522849af8c27f119e235b6d68f6 --- src/board/board-info.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/board/board-info.c b/src/board/board-info.c index c8d630c..c07e1f1 100644 --- a/src/board/board-info.c +++ b/src/board/board-info.c @@ -43,17 +43,21 @@ static GVariant *dbus_revision_handler(GDBusConnection *conn, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) { int ret; + if (!board_dev || !board_dev->get_device_revision) { _E("GetHWRev not supported."); ret = -ENOTSUP; goto revision_fail; } + ret = board_dev->get_device_revision(&info.revision); if (ret < 0) { _E("Fail to get revision."); goto revision_fail; } + _D("Revision: %d", info.revision); + return g_variant_new("(i)", info.revision); revision_fail: @@ -65,20 +69,31 @@ static GVariant *dbus_serial_handler(GDBusConnection *conn, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) { int ret; + GVariant *result; + if (!board_dev || !board_dev->get_device_serial) { _E("GetSerial not supported."); ret = -ENOTSUP; goto serial_out; } + ret = board_dev->get_device_serial(&info.serial); if (ret < 0) { _E("Failed to get serial."); goto serial_out; } + _D("Serial(%s) len(%zu).", info.serial, strlen(info.serial)); serial_out: - return g_variant_new("(si)", info.serial, ret); + result = g_variant_new("(si)", info.serial, ret); + + if (info.serial) { + free(info.serial); + info.serial = NULL; + } + + return result; } static GVariant *dbus_num_handler(GDBusConnection *conn, @@ -87,11 +102,14 @@ static GVariant *dbus_num_handler(GDBusConnection *conn, { int ret; char *p; + GVariant *result; + if (!board_dev || !board_dev->get_device_serial) { _E("GetNum not supported."); ret = -ENOTSUP; goto num_out; } + ret = board_dev->get_device_serial(&info.num); if (ret < 0) { _E("Failed to get num."); @@ -105,7 +123,14 @@ static GVariant *dbus_num_handler(GDBusConnection *conn, _D("Num(%s) len(%zu).", info.num, strlen(info.num)); num_out: - return g_variant_new("(si)", info.num, ret); + result = g_variant_new("(si)", info.num, ret); + + if (info.num) { + free(info.num); + info.num = NULL; + } + + return result; } static const dbus_method_s dbus_methods[] = { -- 2.7.4 From 13f34fa72d324a594d44b0a6f18932e4903eb85c Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Thu, 12 Mar 2020 08:43:19 +0900 Subject: [PATCH 10/16] Fixed using NULL string in gvariant $ dbus-send --type=method_call --print-reply --reply-timeout=1000 --system --dest=org.tizen.system.deviced /Org/Tizen/System/DeviceD/Board org.tizen.system.deviced.Board.GetSerial method return time=946688500.085742 sender=:1.56 -> destination=:1.107 serial=39 reply_serial=2 string "[Invalid UTF-8]" int32 -95 Change-Id: Iff775727ee31278c445929477217457c67b7a7da --- src/board/board-info.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/board/board-info.c b/src/board/board-info.c index c07e1f1..6b59a44 100644 --- a/src/board/board-info.c +++ b/src/board/board-info.c @@ -86,6 +86,9 @@ static GVariant *dbus_serial_handler(GDBusConnection *conn, _D("Serial(%s) len(%zu).", info.serial, strlen(info.serial)); serial_out: + if (info.serial == NULL) + info.serial = strdup(""); + result = g_variant_new("(si)", info.serial, ret); if (info.serial) { @@ -123,6 +126,9 @@ static GVariant *dbus_num_handler(GDBusConnection *conn, _D("Num(%s) len(%zu).", info.num, strlen(info.num)); num_out: + if (info.num == NULL) + info.num = strdup(""); + result = g_variant_new("(si)", info.num, ret); if (info.num) { -- 2.7.4 From d033e4c2947bcf2bf4c1f3ca66e549ecfe882cc2 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Thu, 12 Mar 2020 12:11:18 +0900 Subject: [PATCH 11/16] Remove unused gloable variable info Change-Id: I01f584f4ea75afa96fc8d628d9d8f0812442faf9 --- src/board/board-info.c | 58 +++++++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/src/board/board-info.c b/src/board/board-info.c index 6b59a44..58fa125 100644 --- a/src/board/board-info.c +++ b/src/board/board-info.c @@ -17,25 +17,12 @@ */ -#include -#include -#include -#include -#include #include +#include #include "core/log.h" -#include "core/common.h" #include "core/devices.h" -#include "core/config-parser.h" - -struct board_info { - char *serial; - char *num; - int revision; -}; -static struct board_info info; static struct hw_board *board_dev; static GVariant *dbus_revision_handler(GDBusConnection *conn, @@ -43,6 +30,7 @@ static GVariant *dbus_revision_handler(GDBusConnection *conn, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) { int ret; + int revision; if (!board_dev || !board_dev->get_device_revision) { _E("GetHWRev not supported."); @@ -50,15 +38,15 @@ static GVariant *dbus_revision_handler(GDBusConnection *conn, goto revision_fail; } - ret = board_dev->get_device_revision(&info.revision); + ret = board_dev->get_device_revision(&revision); if (ret < 0) { _E("Fail to get revision."); goto revision_fail; } - _D("Revision: %d", info.revision); + _D("Revision: %d", revision); - return g_variant_new("(i)", info.revision); + return g_variant_new("(i)", revision); revision_fail: return g_variant_new("(i)", ret); @@ -70,6 +58,7 @@ static GVariant *dbus_serial_handler(GDBusConnection *conn, { int ret; GVariant *result; + char *serial = NULL; if (!board_dev || !board_dev->get_device_serial) { _E("GetSerial not supported."); @@ -77,24 +66,22 @@ static GVariant *dbus_serial_handler(GDBusConnection *conn, goto serial_out; } - ret = board_dev->get_device_serial(&info.serial); + ret = board_dev->get_device_serial(&serial); if (ret < 0) { _E("Failed to get serial."); goto serial_out; } - _D("Serial(%s) len(%zu).", info.serial, strlen(info.serial)); + _D("Serial(%s) len(%zu).", serial, strlen(serial)); serial_out: - if (info.serial == NULL) - info.serial = strdup(""); + if (serial == NULL) + serial = strdup(""); - result = g_variant_new("(si)", info.serial, ret); + result = g_variant_new("(si)", serial, ret); - if (info.serial) { - free(info.serial); - info.serial = NULL; - } + if (serial) + free(serial); return result; } @@ -106,6 +93,7 @@ static GVariant *dbus_num_handler(GDBusConnection *conn, int ret; char *p; GVariant *result; + char *num = NULL; if (!board_dev || !board_dev->get_device_serial) { _E("GetNum not supported."); @@ -113,28 +101,26 @@ static GVariant *dbus_num_handler(GDBusConnection *conn, goto num_out; } - ret = board_dev->get_device_serial(&info.num); + ret = board_dev->get_device_serial(&num); if (ret < 0) { _E("Failed to get num."); goto num_out; } - p = strchr(info.num, ','); + p = strchr(num, ','); if (p) *p = '\0'; - _D("Num(%s) len(%zu).", info.num, strlen(info.num)); + _D("Num(%s) len(%zu).", num, strlen(num)); num_out: - if (info.num == NULL) - info.num = strdup(""); + if (num == NULL) + num = strdup(""); - result = g_variant_new("(si)", info.num, ret); + result = g_variant_new("(si)", num, ret); - if (info.num) { - free(info.num); - info.num = NULL; - } + if (num) + free(num); return result; } -- 2.7.4 From 32a6e47d137a00c2a8b037b23ef4387f2ebecb23 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 6 Mar 2020 14:50:16 +0900 Subject: [PATCH 12/16] Prohibit turning on display when display has been detached Kernel set lcd_power node to 5 when display is detached. If the node's value is 5, deviced should ignore lcd on request. To this end, add return statement at the point that can be the entry of the LCDON procedure. Below are the functions that can be a beginning of LCDON. - __pm_change_internal - default_trans - default_action - lcd_on_direct - lcd_on_procedure - dbus_changestatebyreason - dbus_changestate - dbus_customlcdon - switch_on_lcd Change-Id: Ibee6139dede213dbcde715c928a2df64c3757324 Signed-off-by: Youngjae Cho --- plugins/wearable/display/core.c | 33 ++++++++++++++++++++++++++++- plugins/wearable/display/device-interface.c | 9 ++++++++ plugins/wearable/display/key-filter.c | 6 ++++++ src/display/device-interface.h | 1 + src/display/display-dbus.c | 15 +++++++++++++ src/display/poll.c | 7 ++++++ 6 files changed, 70 insertions(+), 1 deletion(-) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 5821dc9..fba21c1 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -498,15 +498,23 @@ void lcd_on_procedure(int state, enum device_flags flag) /* * Display on procedure + * step 0. check if display is detached (only for factory mode) * step 1. broadcast lcd on signal with cause * step 2. set brightness * step 3. set pmstate of vconf * step 4. display on operate * - a. display on * - b. TSP(touch screen) and touchkey enable - * step 5. broadcast lcd on complete siganl + * step 5. broadcast lcd on complete signal * step 6. key backlight enable */ + + /* only for factory mode */ + if (is_display_detached()) { + _W("Turning on display is ignored while the display is detached."); + return; + } + _I("[lcdstep] %lu", flags); if (flags & AMBIENT_MODE) { @@ -1152,6 +1160,13 @@ void lcd_on_direct(enum device_flags flags) power_ops.power_lock(); } + /* only for factory mode */ + if (is_display_detached()) { + _W("Turning on display is ignored while the display is detached."); + return; + } + + pm_old_state = pm_cur_state; pm_cur_state = S_NORMAL; _D("lcd is on directly"); @@ -1976,6 +1991,14 @@ static int default_trans(int evt) } } + /* only for factory mode */ + if (is_display_detached()) { + if (next_state == S_NORMAL || next_state == S_LCDDIM) { + _W("Turning on display is ignored while the display is detached."); + return -1; + } + } + /* state transition */ pm_old_state = pm_cur_state; pm_cur_state = next_state; @@ -2065,6 +2088,14 @@ static int default_action(int timeout) return -EINVAL; } + /* only for facetory mode */ + if (is_display_detached()) { + if (pm_cur_state == S_NORMAL || pm_cur_state == S_LCDDIM) { + _W("Turning on display is ignored while the display is detached."); + return -ENOTSUP; + } + } + if (pm_cur_state != S_SLEEP) { if (pm_cur_state == S_NORMAL && lcdon_tv.tv_sec != 0) { diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index b03e5c4..72322ef 100755 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -289,6 +289,8 @@ static int get_lcd_power(void) return DPMS_SUSPEND; case DISPLAY_OFF: return DPMS_OFF; + case DISPLAY_DETACH: + return DPMS_DETACH; default: return -EINVAL; } @@ -1020,6 +1022,13 @@ bool vital_mode(void) return vital_sleep; } +bool is_display_detached(void) +{ + int state = backlight_ops.get_lcd_power(); + + return (state == DPMS_DETACH) || (state == -EINVAL); +} + static int vital_state_changed(void *data) { int type; diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index 891dadb..87521ed 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -190,6 +190,12 @@ static inline void broadcast_lcdoff_by_powerkey(void) static inline bool switch_on_lcd(enum device_flags flags) { + /* only for factory mode */ + if (is_display_detached()) { + _W("Turning on display is ignored while the display is detached."); + return false; + } + if (current_state_in_on()) return false; diff --git a/src/display/device-interface.h b/src/display/device-interface.h index e0fc089..1cd3d7d 100644 --- a/src/display/device-interface.h +++ b/src/display/device-interface.h @@ -135,6 +135,7 @@ enum mainlock_state { struct display_device *display_dev_get(void); bool display_dimstay_check(void); void dpms_set_running_state(int val); +bool is_display_detached(void); #endif diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 9d88cb5..34f6387 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -312,6 +312,15 @@ static GVariant *dbus_changestate(GDBusConnection *conn, goto out; } + /* only for factory mode */ + if (is_display_detached()) { + if (state == LCD_NORMAL || state == LCD_DIM) { + _W("Turning on display is ignored while the display is detached."); + ret = -ENOTSUP; + goto out; + } + } + if (check_dimstay(state, GOTO_STATE_NOW) == true) { _E("LCD state can not be changed to OFF state! by %d", pid); ret = -EBUSY; @@ -775,6 +784,12 @@ static GVariant *dbus_customlcdon(GDBusConnection *conn, g_variant_get(param, "(i)", &timeout); + /* only for factory mode */ + if (is_display_detached()) { + _W("Turning on display is ignored while the display is detached."); + return g_variant_new("(i)", -ENOTSUP); + } + ret = custom_lcdon(timeout); return g_variant_new("(i)", ret); diff --git a/src/display/poll.c b/src/display/poll.c index ee0471d..7e008d3 100644 --- a/src/display/poll.c +++ b/src/display/poll.c @@ -144,6 +144,7 @@ static int __pm_unlock_internal(pid_t pid, int s_bits, int flag) static int __pm_change_internal(pid_t pid, int s_bits) { int cond; + const int display_on = LCD_NORMAL | LCD_DIM; if (!pm_callback) return -1; @@ -152,6 +153,12 @@ static int __pm_change_internal(pid_t pid, int s_bits) if (cond < 0) return cond; + /* only for factory mode */ + if (is_display_detached() && (cond & display_on)) { + _W("Turning on display is ignored while the display is detached."); + return -ENOTSUP; + } + if (!state_supported(cond)) return -ENOTSUP; -- 2.7.4 From b5455c4702e3fb5d91b307ae67d922d7677258fd Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Thu, 12 Mar 2020 16:30:35 +0900 Subject: [PATCH 13/16] Fix sound issue when wireless charger is attached Change-Id: I683c51ff038d283afcd626021c4fd14c535b638a Signed-off-by: Yunmi Ha --- src/battery/power-supply.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index a39ce17..025593a 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -1057,7 +1057,8 @@ static void battery_changed(struct battery_info *info, void *data) return; ret = booting_done(NULL); - if (ret && old_battery.online != battery.online) { + if (ret && ((old_battery.online != battery.online) || + (battery.online >= CHARGER_WIRELESS_TYPE_BT && old_battery.charge_status == CHARGE_STATUS_DISCHARGING))) { if (battery.online > POWER_SUPPLY_TYPE_BATTERY && battery.charge_now == CHARGER_CHARGING) power_supply_noti(DEVICE_NOTI_BATT_CHARGE, DEVICE_NOTI_ON); else -- 2.7.4 From e5140e4e43943caf732a4db3394a58e2a6507ce0 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 16 Mar 2020 12:54:43 +0900 Subject: [PATCH 14/16] Fix SIGCHLD handling Don't treat ECHILD as an error case as it means this SIGCHLD had already been handled somewhere else. Change-Id: I115c942b5ec616bf21873e806b6f97add959f054 Signed-off-by: Youngjae Cho --- src/core/sig-handler.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/core/sig-handler.c b/src/core/sig-handler.c index 527e6f5..dfb8dd1 100644 --- a/src/core/sig-handler.c +++ b/src/core/sig-handler.c @@ -30,19 +30,17 @@ static struct sigaction sig_pipe_old_act; static void sig_child_handler(int signo, siginfo_t *info, void *data) { - pid_t pid; + pid_t ret; int status; if (!info || signo != SIGCHLD) return; - pid = waitpid(info->si_pid, &status, 0); - if (pid == -1) { - _E("SIGCHLD received.\n"); - return; - } - - _D("Sig child actend call - %d\n", info->si_pid); + ret = waitpid(info->si_pid, &status, 0); + if (ret >= 0) + _D("SIGCHLD from %d handled successfully.", ret); + else if (ret == -1 && errno != ECHILD) + _E("Failed to handle SIGCHLD(%d).", errno); } static void sig_pipe_handler(int signo, siginfo_t *info, void *data) -- 2.7.4 From abed8d696b18cf004128447d7ca85f65b62b2dee Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 16 Mar 2020 17:00:18 +0900 Subject: [PATCH 15/16] Fix display plugin load error Add dummy is_display_detached() for mobile, iot, tv to resolve undefined symbol error. Change-Id: I4ed5eb1565a5afff119e9d7c40a2b385744ad92c Signed-off-by: Youngjae Cho --- plugins/iot/display/device-interface.c | 6 ++++++ plugins/mobile/display/device-interface.c | 6 ++++++ plugins/tv/display/device-interface.c | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index 4064ee2..e62dc49 100644 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -1001,6 +1001,12 @@ static int vital_state_changed(void *data) return 0; } +/* Dummy. Do not consider detached display state */ +bool is_display_detached(void) +{ + return false; +} + int init_sysfs(unsigned int flags) { _init_ops(); diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 4064ee2..e62dc49 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -1001,6 +1001,12 @@ static int vital_state_changed(void *data) return 0; } +/* Dummy. Do not consider detached display state */ +bool is_display_detached(void) +{ + return false; +} + int init_sysfs(unsigned int flags) { _init_ops(); diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 4064ee2..e62dc49 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -1001,6 +1001,12 @@ static int vital_state_changed(void *data) return 0; } +/* Dummy. Do not consider detached display state */ +bool is_display_detached(void) +{ + return false; +} + int init_sysfs(unsigned int flags) { _init_ops(); -- 2.7.4 From 5053c32254000a25bfc46b4133f9e4a1b921ef37 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Mon, 16 Mar 2020 17:48:27 +0900 Subject: [PATCH 16/16] Modify usb debug message Change-Id: I0a3c558221010674a489d9d196db76b0f3d7a96a --- src/usb/usb-dbus.c | 12 ++++++------ src/usb/usb-debug.c | 2 +- src/usb/usb-state.c | 16 ++++++++-------- src/usb/usb.c | 20 ++++++++++---------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/usb/usb-dbus.c b/src/usb/usb-dbus.c index 977f592..479991b 100644 --- a/src/usb/usb-dbus.c +++ b/src/usb/usb-dbus.c @@ -41,7 +41,7 @@ static int get_usb_state(void) ret = vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS, &val); if (ret != VCONF_OK) { - _E("Failed to get vconf value for usb_status: %d", vconf_get_ext_errno()); + _E("Failed to get vconf value for USB status: %d", vconf_get_ext_errno()); return ret; } @@ -75,7 +75,7 @@ void broadcast_usb_state_changed(void) SIGNAL_STATE_CHANGED, g_variant_new("(u)", state)); if (ret < 0) - _E("Failed to send dbus signal."); + _E("Failed to send USB dbus signal."); } static void change_usb_client_mode(GDBusConnection *conn, @@ -93,7 +93,7 @@ static void change_usb_client_mode(GDBusConnection *conn, g_variant_get(param, "(i)", &req_vconf); if (req_vconf < 0) { - _E("Failed to get req_vconf."); + _E("Failed to get USB req_vconf."); return; } @@ -102,7 +102,7 @@ static void change_usb_client_mode(GDBusConnection *conn, mode = get_mode_bitmap_from_vconf(req_vconf); if (mode == USB_FUNCTION_INVALID) { - _E("Failed to convert vconf to mode. There is no mode matches up with vconf %d.", req_vconf); + _E("Failed to convert vconf to USB mode. There is no mode matches up with vconf %d.", req_vconf); return; } @@ -160,13 +160,13 @@ int usb_dbus_init(void) ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_USB, &dbus_interface); if (ret < 0) - _E("Failed to init dbus method: %d", ret); + _E("Failed to init dbus method for USB: %d", ret); ret = subscribe_dbus_signal(NULL, DEVICED_PATH_USB, DEVICED_INTERFACE_USB, "ChangeUsbMode", change_usb_client_mode, NULL, NULL); if (ret <= 0) { - _E("Failed to subscribe dbus signal: %d", ret); + _E("Failed to subscribe dbus signal for USB: %d", ret); return ret; } diff --git a/src/usb/usb-debug.c b/src/usb/usb-debug.c index 878e090..d45409b 100644 --- a/src/usb/usb-debug.c +++ b/src/usb/usb-debug.c @@ -121,7 +121,7 @@ void add_usb_debug_handler(void) if (vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, usb_debug_changed, NULL) != VCONF_OK) - _E("Failed to add usb debug handler."); + _E("Failed to add USB debug handler."); register_notifier(DEVICE_NOTIFIER_USB_DEBUG_MODE, usb_debug_mode_changed); diff --git a/src/usb/usb-state.c b/src/usb/usb-state.c index 5c78903..02b0072 100644 --- a/src/usb/usb-state.c +++ b/src/usb/usb-state.c @@ -117,7 +117,7 @@ static void usb_state_send_system_event(int status) return; } - _I("system_event(%s)", str); + _I("USB system_event (%s)", str); b = bundle_create(); bundle_add_str(b, EVT_KEY_USB_STATUS, str); @@ -197,7 +197,7 @@ int usb_state_set_selected_mode(unsigned int mode) mode_v = get_mode_vconf_from_bitmap(mode); if (mode_v == SET_USB_INVALID) { - _E("Failed to convert selected_mode to vconf. There is no vconf matches up with mode 0x%x", mode); + _E("Failed to convert USB selected_mode to vconf. There is no vconf matches up with USB mode 0x%x", mode); return -EINVAL; } @@ -225,7 +225,7 @@ int usb_state_set_current_mode(unsigned int mode) mode_v = get_mode_vconf_from_bitmap(mode); if (mode_v == SET_USB_INVALID) { - _E("Failed to convert current_mode to vconf. There is no vconf matches up with mode 0x%x", mode); + _E("Failed to convert USB current_mode to vconf. There is no vconf matches up with mode 0x%x", mode); return -EINVAL; } @@ -255,17 +255,17 @@ static void media_noti_cb(GVariant *var, void *user_data, GError *err) if (!var) { if (err) - _E("Error: %s", err->message); + _E("USB media notification error: %s", err->message); return; } if (!dh_get_param_from_var(var, "(i)", &id)) { - _E("Failed to get variant(%s): no message", g_variant_get_type_string(var)); + _E("Failed to get variant(%s): no USB notification message", g_variant_get_type_string(var)); goto out; } noti_id = id; - _D("Media noti(%d)", noti_id); + _D("USB media notification message(%d)", noti_id); out: g_variant_unref(var); @@ -278,7 +278,7 @@ static void add_notification_handler(void) if (noti_id < 0) { ret = add_async_notification("MediaDeviceNotiOn", media_noti_cb, NULL, NULL); if (ret < 0) - _E("Failed to show notification for usb connection."); + _E("Failed to add USB notification for usb connection: %d", ret); } } @@ -289,7 +289,7 @@ static void remove_notification_handler(void) if (noti_id >= 0) { ret = remove_notification("MediaDeviceNotiOff", noti_id); if (ret < 0) - _E("Failed to remove event_noti: %d", ret); + _E("Failed to remove USB notification for usb connection: %d", ret); else noti_id = -1; } diff --git a/src/usb/usb.c b/src/usb/usb.c index 2be5c81..66faa97 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -48,7 +48,7 @@ static struct usb_gadget_translator *gadget_translator_probe(void) } if (!info->open) { - _E("Failed to open USB gadget translator: open(NULL)"); + _E("USB gadget does not have open() "); return NULL; } @@ -79,12 +79,12 @@ static struct usb_client *usb_client_probe(const char *id) _I("Loading USB client. id=%s", id); if (hw_get_info(id, (const struct hw_info **)&info)) { - _I("No usb_client. id=%s", id); + _I("No USB client. id=%s", id); return NULL; } if (!info->open) { - _E("Failed to open USB client(%s): open(NULL)", id); + _E("USB client does not have open(). id=%s", id); return NULL; } @@ -218,14 +218,14 @@ static int usb_change_gadget(unsigned mode) ret = gadget_translator->id_to_gadget(&gadget_id, &gadget); if (ret) { - _E("Unable to translate id into gadget: %d", ret); + _E("Unable to translate USB mode id into gadget: %d", ret); goto out; } ret = usb_client->reconfigure_gadget(usb_client, gadget); gadget_translator->cleanup_gadget(gadget); if (ret) { - _E("Unable to configure gadget: %d", ret); + _E("Unable to configure USB gadget: %d", ret); goto out; } @@ -272,7 +272,7 @@ static int usb_disable(void) ret = usb_config_disable(); if (ret < 0) { - _E("Failed to disable usb config: %d", ret); + _E("Failed to disable USB config: %d", ret); return ret; } @@ -358,7 +358,7 @@ int usb_change_mode(unsigned int new_mode) */ ret = usb_change_gadget(new_mode); if (ret < 0) { - _E("Failed to change gadget: %d", ret); + _E("Failed to change USB gadget: %d", ret); return ret; } @@ -426,7 +426,7 @@ static void uevent_usb_mode_handler(struct udev_device *dev) if (strncmp(state, "CONFIGURED", strlen(state) + 1)) return; - _I("usb_mode udev event happend : CONFIGURED"); + _I("USB udev event happend : CONFIGURED USB_STATE"); if (usb_state_get_selected_mode() & USB_FUNCTION_ACM) systemd_start_unit_wait_started ("data-router.service", NULL, -1); @@ -461,11 +461,11 @@ static void usb_init(void *data) ret = register_udev_uevent_control(&uh); if (ret < 0) - _E("Failed to register udev event(%d)", ret); + _E("Failed to register udev event(%d) for USB", ret); ret = usb_dbus_init(); if (ret < 0) - _E("Failed to init dbus: %d", ret); + _E("Failed to init dbus(%d) for USB", ret); add_usb_tethering_handler(); add_usb_debug_handler(); -- 2.7.4