From abed8d696b18cf004128447d7ca85f65b62b2dee Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 16 Mar 2020 17:00:18 +0900 Subject: [PATCH 01/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 02/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 From 6c9bbf4ca166ac015390200f47a991db23891043 Mon Sep 17 00:00:00 2001 From: Semun Lee Date: Tue, 17 Mar 2020 17:10:10 +0900 Subject: [PATCH 03/16] remove unused code It creates unncessary noise in static analyzers Change-Id: I269efd772f54794b584c99eb224a4f1ba502f2e2 Signed-off-by: Semun Lee --- src/core/common.c | 64 ------------------------------------------------------- src/core/common.h | 1 - 2 files changed, 65 deletions(-) diff --git a/src/core/common.c b/src/core/common.c index c393c14..5854082 100644 --- a/src/core/common.c +++ b/src/core/common.c @@ -137,70 +137,6 @@ int is_app(pid_t pid) return 1; } -static int remove_dir_internal(int fd) -{ - DIR *dir; - struct dirent *de = NULL; - int subfd, ret = 0; - - dir = fdopendir(fd); - if (!dir) - return -1; - while (1) { - de = readdir(dir); - if (ret != 0 || de == NULL) - break; - if (de->d_type == DT_DIR) { - if (!strncmp(de->d_name, ".", 2) || !strncmp(de->d_name, "..", 3)) - continue; - subfd = openat(fd, de->d_name, O_RDONLY | O_DIRECTORY); - if (subfd < 0) { - _SE("Couldn't openat %s: %d\n", de->d_name, errno); - ret = -1; - continue; - } - if (remove_dir_internal(subfd)) - ret = -1; - - close(subfd); - if (unlinkat(fd, de->d_name, AT_REMOVEDIR) < 0) { - _SE("Couldn't unlinkat %s: %d\n", de->d_name, errno); - ret = -1; - } - } else { - if (unlinkat(fd, de->d_name, 0) < 0) { - _SE("Couldn't unlinkat %s: %d\n", de->d_name, errno); - ret = -1; - } - } - } - closedir(dir); - return ret; -} - -int remove_dir(const char *path, int del_dir) -{ - int fd, ret = 0; - - if (!path) - return -1; - fd = open(path, O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW); - if (fd < 0) { - _SE("Couldn't opendir %s: %d\n", path, errno); - return -errno; - } - ret = remove_dir_internal(fd); - close(fd); - - if (del_dir) { - if (rmdir(path)) { - _SE("Couldn't rmdir %s: %d\n", path, errno); - ret = -1; - } - } - return ret; -} - /* * Helper function * - Read from sysfs entry diff --git a/src/core/common.h b/src/core/common.h index 9971752..3f53d1e 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -173,7 +173,6 @@ int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size); int is_vip(int pid); int is_app(pid_t pid); int run_child(int argc, const char *argv[]); -int remove_dir(const char *path, int del_dir); int sys_check_node(char *path); int sys_get_int(char *fname, int *val); int sys_set_int(char *fname, int val); -- 2.7.4 From e20320db0fbaa136355c33b8d3484f99a6a43f9e Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 18 Mar 2020 12:27:45 +0900 Subject: [PATCH 04/16] Add poweroff stage to clarify poweroff sequence POWEROFF_DEFAULT - Default stage, poweroff has not been triggered POWEROFF_TRIGGERED - Poweroff is triggered. Wait timer can be added up to this stage POWEROFF_WAIT_OTHERS - Wait for other processes to clean up their resources Change-Id: Iaf744a624c230a3d0ffc588aa60138264f184c72 Signed-off-by: Youngjae Cho --- src/power/power-handler.c | 89 +++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 41 deletions(-) diff --git a/src/power/power-handler.c b/src/power/power-handler.c index d67103e..9f05cb5 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -64,8 +64,6 @@ static struct timeval tv_start_poweroff; static dd_list *poweroff_options; static struct power_option poweroff_opt; -static bool poweroff_triggered; -static bool poweroff_wait_timer_activated; static dd_list *poweroff_handles; static const char *poweroff_type_flagpaths[] = { // index denotes type @@ -80,6 +78,14 @@ static const char *poweroff_type_names[] = { // index denotes type [POWEROFF_TYPE_EXIT] = POWER_EXIT, }; +enum poweroff_stage { + POWEROFF_DEFAULT, /* Default stage, poweroff has not been triggered */ + POWEROFF_TRIGGERED, /* Poweroff is triggered. Wait timer can be added up to this stage */ + POWEROFF_WAIT_OTHERS, /* Wait for other processes to clean up their resources */ +}; + +static enum poweroff_stage poweroff_stage; + static const char *poweroff_type_to_name(enum poweroff_type type) { if (type <= 0 || type >= ARRAY_SIZE(poweroff_type_names)) @@ -322,38 +328,36 @@ static void poweroff_remove_handle(pid_t pid) free(handle); } -static gboolean poweroff_timeout_cb(void *data) +static gboolean poweroff_wait_timeout_cb(void *data) { char timeout[50] = {0,}; pid_t pid = (pid_t)((intptr_t)data); poweroff_remove_handle(pid); - if (DD_LIST_LENGTH(poweroff_handles)) { - _D("Timer is left."); - return G_SOURCE_REMOVE; - } - _D("No timer left."); + /* All other processes finished cleanup. Poweroff is now on standby */ + if (poweroff_stage == POWEROFF_WAIT_OTHERS && DD_LIST_LENGTH(poweroff_handles) == 0) { + _D("The last poweroff wait timer for pid %d is expired. Poweroff is now on standby.", pid); - if (!poweroff_type_to_name(poweroff_opt.type)) { - _E("Invalid type(%d).", poweroff_opt.type); - goto out; - } + CRITICAL_LOG("Starting poweroff sequence."); - // Watchdog timeout 90 -> 30 sec to reduce delay from unexpected poweroff failure. - snprintf(timeout, sizeof(timeout), "WATCHDOG_USEC=%llu", (unsigned long long)POWEROFF_WAIT_SYSTEMD_MS*1000); - sd_notify(0, timeout); + // Watchdog timeout 90 -> 30 sec to reduce delay from unexpected poweroff failure. + snprintf(timeout, sizeof(timeout), "WATCHDOG_USEC=%llu", (unsigned long long)POWEROFF_WAIT_SYSTEMD_MS*1000); + sd_notify(0, timeout); - make_power_flag(poweroff_opt.type, poweroff_opt.option); + make_power_flag(poweroff_opt.type, poweroff_opt.option); - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_POWEROFF, LCD_OFF, STAY_CUR_STATE, 0); + if (disp_plgn.pm_lock_internal) + disp_plgn.pm_lock_internal(INTERNAL_LOCK_POWEROFF, LCD_OFF, STAY_CUR_STATE, 0); - poweroff_prepare(); - poweroff(); -out: - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_POWEROFF, poweroff_opt.type); + poweroff_prepare(); + poweroff(); + + if (disp_plgn.update_pm_setting) + disp_plgn.update_pm_setting(SETTING_POWEROFF, poweroff_opt.type); + } else { + _D("Poweroff wait timer for pid %d is expired, but keep waiting for others...", pid); + } return G_SOURCE_REMOVE; } @@ -365,7 +369,7 @@ static gboolean poweroff_start_timers(void *data) bool timer_exist = false; int pid_alive = 0; - poweroff_wait_timer_activated = true; + poweroff_stage = POWEROFF_WAIT_OTHERS; DD_LIST_FOREACH(poweroff_handles, l, handle) { pid_alive = kill(handle->pid, 0); @@ -377,7 +381,7 @@ static gboolean poweroff_start_timers(void *data) _D("Run timer, pid=%d timeout=%d timeout_id=%d.", handle->pid, handle->timeout, handle->timeout_id); handle->timeout_id = g_timeout_add_seconds(handle->timeout, - poweroff_timeout_cb, + poweroff_wait_timeout_cb, (void *)((intptr_t)(handle->pid))); timer_exist = true; @@ -397,7 +401,7 @@ static gboolean poweroff_start_timers(void *data) handle->pid = getpid(); handle->timeout = 0; handle->timeout_id = g_timeout_add_seconds(handle->timeout, - poweroff_timeout_cb, + poweroff_wait_timeout_cb, (void *)((intptr_t)(handle->pid))); if (!handle->timeout_id) { @@ -475,8 +479,8 @@ static int power_execute_pid(const char *typename, const char *option) { int ret; - if (poweroff_triggered) { - _E("During poweroff."); + if (poweroff_stage >= POWEROFF_TRIGGERED) { + _E("Duplicate poweroff request. Poweroff was already triggered."); return -EINVAL; } @@ -485,6 +489,7 @@ static int power_execute_pid(const char *typename, const char *option) _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); @@ -500,7 +505,7 @@ static int power_execute_pid(const char *typename, const char *option) if (ret < 0) _E("Failed to set vconf value for power off status: %d", vconf_get_ext_errno()); - poweroff_triggered = true; + poweroff_stage = POWEROFF_TRIGGERED; /* Poweroff event broadcasting */ system_shutdown_send_system_event(); @@ -550,6 +555,7 @@ static GVariant *dbus_power_handler(GDBusConnection *conn, if (ret < 0) goto out; + CRITICAL_LOG("Poweroff PID(%d) requests %s.", ret, type_str); ret = power_execute_pid(type_str, NULL); @@ -571,6 +577,7 @@ static GVariant *dbus_power_option_handler(GDBusConnection *conn, if (ret < 0) goto out; + CRITICAL_LOG("Poweroff PID(%d) requests type=%s option=%s.", ret, type, option); ret = power_execute_pid(type, option); @@ -580,6 +587,7 @@ out: return g_variant_new("(i)", ret); } +/* timer can be added before the stage POWEROFF_WAIT_OTHERS */ static GVariant *add_poweroff_time(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) @@ -589,8 +597,8 @@ static GVariant *add_poweroff_time(GDBusConnection *conn, pid_t pid; dd_list *l; - if (poweroff_wait_timer_activated) { - _E("It's too late. Poweroff wait timers are already activated."); + if (poweroff_stage >= POWEROFF_WAIT_OTHERS) { + _E("It's too late. Poweroff is already in waiting stage."); ret = -1; goto out; } @@ -601,7 +609,7 @@ static GVariant *add_poweroff_time(GDBusConnection *conn, pid = (pid_t)ret; - CRITICAL_LOG("PID %d request poweroff timer.", pid); + CRITICAL_LOG("PID %d requested to a poweroff timer.", pid); DD_LIST_FOREACH(poweroff_handles, l, handle) { if (handle->pid == pid) @@ -647,7 +655,7 @@ static GVariant *remove_poweroff_time(GDBusConnection *conn, pid = (pid_t)ret; - _D("Remove_poweroff_timer pid=%d", pid); + CRITICAL_LOG("PID %d requested to remove poweroff timer.", pid); DD_LIST_FOREACH(poweroff_handles, l, handle) { if (handle->pid == pid) @@ -655,15 +663,12 @@ static GVariant *remove_poweroff_time(GDBusConnection *conn, } if (handle) { - assert(handle); - - if (handle && handle->timeout_id) { + if (handle->timeout_id) g_source_remove(handle->timeout_id); - handle->timeout = 0; - handle->timeout_id = g_timeout_add_seconds(handle->timeout, - poweroff_timeout_cb, - (void *)((intptr_t)(handle->pid))); - } + handle->timeout = 0; + handle->timeout_id = g_timeout_add_seconds(handle->timeout, + poweroff_wait_timeout_cb, + (void *)((intptr_t)(handle->pid))); } else { _E("Invalid pid(%d).", pid); ret = -1; @@ -772,6 +777,8 @@ static void power_init(void *data) ret = config_parse(POWER_CONF_FILE, load_config, NULL); if (ret < 0) _E("Failed to load power off config: %d", ret); + + poweroff_stage = POWEROFF_DEFAULT; } static const struct device_ops power_device_ops = { -- 2.7.4 From efafd843e908816782119e1adde4ecc93f463abc Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 13 Mar 2020 08:55:50 +0900 Subject: [PATCH 05/16] Move battery status backup after checking is done Sometimes, battery status is changed quickly, previous status does not stored at backup structure. so move them after checking is done. Change-Id: I0ee56f035a74eadea40b5747aff0ac8e3896deea Signed-off-by: Youngjae Cho --- src/battery/power-supply.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 025593a..da65763 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -507,8 +507,9 @@ int changed_battery_cf(int status) static void update_present(enum battery_noti_status status) { - CRITICAL_LOG("Charge(%d) present(%d)", battery.charge_now, battery.present); + CRITICAL_LOG("Charge(%d) present(%d, old: %d)", battery.charge_now, battery.present, old_battery.present); + old_battery.present = battery.present; if (status == DEVICE_NOTI_ON) { battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_DIM); device_notify(DEVICE_NOTIFIER_BATTERY_PRESENT, (void *)&battery.present); @@ -534,7 +535,7 @@ void remove_health_popup(void) static void update_health(enum battery_noti_status status) { - _I("Charge(%d) health(%d)", battery.charge_now, battery.health); + _I("Charge(%d) health(%d, old: %d)", battery.charge_now, battery.health, old_battery.health); CRITICAL_LOG("Popup: Battery health status is not good, %s.", battery.health_s); if (status == DEVICE_NOTI_ON) { @@ -586,9 +587,10 @@ static void update_ovp(enum battery_noti_status status) return; old = status; - _I("Charge(%d) ovp(%d) with lcd(%s)", battery.charge_now, battery.health, - (status == DEVICE_NOTI_ON) ? "dim" : "normal"); + _I("Charge(%d) ovp(%d, old: %d) with lcd(%s)", battery.charge_now, battery.health, + old_battery.health, (status == DEVICE_NOTI_ON) ? "dim" : "normal"); + old_battery.health = battery.health; device_notify(DEVICE_NOTIFIER_BATTERY_OVP, (void *)&battery.health); battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); } @@ -833,9 +835,11 @@ static void process_power_supply(void *data) if (power_supply_broadcast(CHARGE_FULL_SIGNAL, battery.charge_full) < 0) broadcasted = false; - if (strncmp(old_battery.health_s, battery.health_s, strlen(battery.health_s))) + if (strncmp(old_battery.health_s, battery.health_s, strlen(battery.health_s))) { + snprintf(old_battery.health_s, sizeof(old_battery.health_s), "%s", battery.health_s); if (power_supply_broadcast_str(CHARGE_HEALTH_SIGNAL, battery.health_s) < 0) broadcasted = false; + } if (old_battery.capacity != battery.capacity) { ret = vconf_set_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, battery.capacity); @@ -898,13 +902,10 @@ static void process_power_supply(void *data) old_battery.charge_status = battery.charge_status; old_battery.charge_full = battery.charge_full; - check_abnormal_status(); - - old_battery.health = battery.health; old_battery.misc = battery.misc; old_battery.freq_strength = battery.freq_strength; - old_battery.present = battery.present; - snprintf(old_battery.health_s, sizeof(old_battery.health_s), "%s", battery.health_s); + + check_abnormal_status(); device_notify(DEVICE_NOTIFIER_POWER_SUPPLY, NULL); if (old_battery.charge_now != battery.charge_now) { -- 2.7.4 From 51c78c0946b06f62d57f8c5a013012679f070338 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 19 Mar 2020 17:43:26 +0900 Subject: [PATCH 06/16] Move PM_DEFAULT_BRIGHTNESS into display_conf All profiles have used PM_DEFAULT_BRIGHTNESS as a same value of 80, but now the wearable profile is changed to use 70. So move this information into each profile's display_conf and delete the macro. And fixed related code. Change-Id: I4207bb88173aee3f6769c8c64ec616799f1c1b48 Signed-off-by: Youngjae Cho --- plugins/iot/display/core.c | 3 ++- plugins/iot/display/device-interface.c | 2 +- plugins/mobile/display/core.c | 3 ++- plugins/mobile/display/device-interface.c | 2 +- plugins/tv/display/core.c | 3 ++- plugins/tv/display/device-interface.c | 2 +- plugins/wearable/display/core.c | 3 ++- plugins/wearable/display/device-interface.c | 2 +- plugins/wearable/display/hbm.c | 5 ++--- src/display/auto-brightness.c | 2 +- src/display/core.h | 1 + src/display/device-interface.h | 1 - src/display/display-dbus.c | 4 ++-- 13 files changed, 18 insertions(+), 15 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 8f90f84..4e34698 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -212,6 +212,7 @@ struct display_config display_conf = { .longpress_interval = LONG_PRESS_INTERVAL, .lightsensor_interval = SAMPLING_INTERVAL, .lcdoff_timeout = LCDOFF_TIMEOUT, + .pm_default_brightness = 80, .brightness_change_step = BRIGHTNESS_CHANGE_STEP, .lcd_always_on = LCD_ALWAYS_ON, .dimming = 1, @@ -2374,7 +2375,7 @@ static void check_seed_status(void) ret = get_setting_brightness(&tmp); if (ret != 0 || (tmp < PM_MIN_BRIGHTNESS || tmp > PM_MAX_BRIGHTNESS)) { _I("Failed to read vconf value for brightness."); - brt = PM_DEFAULT_BRIGHTNESS; + brt = display_conf.pm_default_brightness; if (tmp < PM_MIN_BRIGHTNESS || tmp > PM_MAX_BRIGHTNESS) { ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); if (ret < 0) diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index e62dc49..b6fd9b4 100644 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -496,7 +496,7 @@ static int backlight_standby(int force) static int set_default_brt(int level) { if (level < PM_MIN_BRIGHTNESS || level > PM_MAX_BRIGHTNESS) - level = PM_DEFAULT_BRIGHTNESS; + level = display_conf.pm_default_brightness; default_brightness = level; diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index f6b756a..f7fd0da 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -214,6 +214,7 @@ struct display_config display_conf = { .longpress_interval = LONG_PRESS_INTERVAL, .lightsensor_interval = SAMPLING_INTERVAL, .lcdoff_timeout = LCDOFF_TIMEOUT, + .pm_default_brightness = 80, .brightness_change_step = BRIGHTNESS_CHANGE_STEP, .lcd_always_on = LCD_ALWAYS_ON, .dimming = 1, @@ -2384,7 +2385,7 @@ static void check_seed_status(void) ret = get_setting_brightness(&tmp); if (ret != 0 || (tmp < PM_MIN_BRIGHTNESS || tmp > PM_MAX_BRIGHTNESS)) { _I("Failed to read vconf value for brightness."); - brt = PM_DEFAULT_BRIGHTNESS; + brt = display_conf.pm_default_brightness; if (tmp < PM_MIN_BRIGHTNESS || tmp > PM_MAX_BRIGHTNESS) { ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); if (ret < 0) diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index e62dc49..b6fd9b4 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -496,7 +496,7 @@ static int backlight_standby(int force) static int set_default_brt(int level) { if (level < PM_MIN_BRIGHTNESS || level > PM_MAX_BRIGHTNESS) - level = PM_DEFAULT_BRIGHTNESS; + level = display_conf.pm_default_brightness; default_brightness = level; diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index dba2cef..788de3b 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -212,6 +212,7 @@ struct display_config display_conf = { .longpress_interval = LONG_PRESS_INTERVAL, .lightsensor_interval = SAMPLING_INTERVAL, .lcdoff_timeout = LCDOFF_TIMEOUT, + .pm_default_brightness = 80, .brightness_change_step = BRIGHTNESS_CHANGE_STEP, .lcd_always_on = LCD_ALWAYS_ON, .dimming = 1, @@ -2371,7 +2372,7 @@ static void check_seed_status(void) ret = get_setting_brightness(&tmp); if (ret != 0 || (tmp < PM_MIN_BRIGHTNESS || tmp > PM_MAX_BRIGHTNESS)) { _I("Failed to read vconf value for brightness."); - brt = PM_DEFAULT_BRIGHTNESS; + brt = display_conf.pm_default_brightness; if (tmp < PM_MIN_BRIGHTNESS || tmp > PM_MAX_BRIGHTNESS) { ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); if (ret < 0) diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index e62dc49..b6fd9b4 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -496,7 +496,7 @@ static int backlight_standby(int force) static int set_default_brt(int level) { if (level < PM_MIN_BRIGHTNESS || level > PM_MAX_BRIGHTNESS) - level = PM_DEFAULT_BRIGHTNESS; + level = display_conf.pm_default_brightness; default_brightness = level; diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index fba21c1..55ab9a9 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -217,6 +217,7 @@ struct display_config display_conf = { .longpress_interval = LONG_PRESS_INTERVAL, .lightsensor_interval = SAMPLING_INTERVAL, .lcdoff_timeout = LCDOFF_TIMEOUT, + .pm_default_brightness = 70, .brightness_change_step = BRIGHTNESS_CHANGE_STEP, .lcd_always_on = LCD_ALWAYS_ON, .dimming = 1, @@ -2442,7 +2443,7 @@ static void check_seed_status(void) ret = get_setting_brightness(&tmp); if (ret != 0 || (tmp < PM_MIN_BRIGHTNESS || tmp > PM_MAX_BRIGHTNESS)) { _I("Failed to read vconf value for brightness."); - brt = PM_DEFAULT_BRIGHTNESS; + brt = display_conf.pm_default_brightness; if (tmp < PM_MIN_BRIGHTNESS || tmp > PM_MAX_BRIGHTNESS) { ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); if (ret < 0) diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 72322ef..20bc64f 100755 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -504,7 +504,7 @@ static int backlight_standby(int force) static int set_default_brt(int level) { if (level < PM_MIN_BRIGHTNESS || level > PM_MAX_BRIGHTNESS) - level = PM_DEFAULT_BRIGHTNESS; + level = display_conf.pm_default_brightness; default_brightness = level; diff --git a/plugins/wearable/display/hbm.c b/plugins/wearable/display/hbm.c index 37b02e4..e5e132e 100644 --- a/plugins/wearable/display/hbm.c +++ b/plugins/wearable/display/hbm.c @@ -37,7 +37,6 @@ #define SIGNAL_HBM_OFF "HBMOff" #define HBM_LEVEL 120 -#define DEFAULT_BRIGHTNESS_LEVEL 80 #define LCD_PATH "sys/class/lcd/" #define HBM_PATH "/hbm" @@ -87,12 +86,12 @@ static gboolean hbm_off_cb(void *data) _E("Failed to off hbm."); ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, - DEFAULT_BRIGHTNESS_LEVEL); + display_conf.pm_default_brightness); if (ret < 0) { _E("Failed to set vconf value lcd brightness, %d.", ret); return G_SOURCE_REMOVE; } - backlight_ops.set_default_brt(DEFAULT_BRIGHTNESS_LEVEL); + backlight_ops.set_default_brt(display_conf.pm_default_brightness); backlight_ops.update(); broadcast_hbm_state(SIGNAL_HBM_OFF); diff --git a/src/display/auto-brightness.c b/src/display/auto-brightness.c index 89ec7af..665b3f8 100644 --- a/src/display/auto-brightness.c +++ b/src/display/auto-brightness.c @@ -432,7 +432,7 @@ static int set_autobrightness_state(int status) ret = get_setting_brightness(&default_brt); if (ret != 0 || (default_brt < PM_MIN_BRIGHTNESS || default_brt > PM_MAX_BRIGHTNESS)) { _I("Failed to read vconf value for brightness."); - brt = PM_DEFAULT_BRIGHTNESS; + brt = display_conf.pm_default_brightness; if (default_brt < PM_MIN_BRIGHTNESS || default_brt > PM_MAX_BRIGHTNESS) { ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); if (ret < 0) diff --git a/src/display/core.h b/src/display/core.h index 24f572c..3f175f8 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -125,6 +125,7 @@ struct display_config { double longpress_interval; double lightsensor_interval; int lcdoff_timeout; + const int pm_default_brightness; int brightness_change_step; int lcd_always_on; int dimming; diff --git a/src/display/device-interface.h b/src/display/device-interface.h index 1cd3d7d..aee3e31 100644 --- a/src/display/device-interface.h +++ b/src/display/device-interface.h @@ -34,7 +34,6 @@ #define PM_MAX_BRIGHTNESS 100 #define PM_MIN_BRIGHTNESS 1 -#define PM_DEFAULT_BRIGHTNESS 80 #define PM_DIM_BRIGHTNESS 0 #define DISP_INDEX_SHIFT 16 diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 34f6387..7b207ac 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -1223,10 +1223,10 @@ static void sim_signal_handler(GDBusConnection *conn, ret = vconf_set_bool(VCONFKEY_LCD_BRIGHTNESS_INIT, state); if (ret < 0) _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, PM_DEFAULT_BRIGHTNESS); + ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, display_conf.pm_default_brightness); if (ret < 0) _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); - backlight_ops.set_brightness(PM_DEFAULT_BRIGHTNESS); + backlight_ops.set_brightness(display_conf.pm_default_brightness); _I("SIM card is inserted at first."); } } -- 2.7.4 From 5a3669255977843fb2ea637a9edfa3257bb633bd Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 19 Mar 2020 18:24:14 +0900 Subject: [PATCH 07/16] Remove unused code: sim_signal_hanlder() Change-Id: I1e33a45f8f0150e8f671152da1a1b05c38218538 Signed-off-by: Youngjae Cho --- src/display/display-dbus.c | 43 ------------------------------------------- 1 file changed, 43 deletions(-) diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 7b207ac..815b07d 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -1199,38 +1199,6 @@ static void homescreen_signal_handler(GDBusConnection *conn, g_free(screen); } -static void sim_signal_handler(GDBusConnection *conn, - const gchar *sender, - const gchar *path, - const gchar *iface, - const gchar *name, - GVariant *param, - gpointer data) -{ - int ret, val; - static int state = false; - - ret = vconf_get_bool(VCONFKEY_LCD_BRIGHTNESS_INIT, &state); - if (ret < 0 || state) { - _E("Failed to get %s", VCONFKEY_LCD_BRIGHTNESS_INIT); - return; - } - - g_variant_get(param, "(i)", &val); - - if (val != SIM_CARD_NOT_PRESENT) { - state = true; - ret = vconf_set_bool(VCONFKEY_LCD_BRIGHTNESS_INIT, state); - if (ret < 0) - _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, display_conf.pm_default_brightness); - if (ret < 0) - _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); - backlight_ops.set_brightness(display_conf.pm_default_brightness); - _I("SIM card is inserted at first."); - } -} - static void changestate_signal_handler(GDBusConnection *conn, const gchar *sender, const gchar *path, @@ -1288,17 +1256,6 @@ int init_pm_dbus(void) if (ret < 0) _E("fail to init dbus method(%d)", ret); -#ifndef MICRO_DD - ret = subscribe_dbus_signal(NULL, - TELEPHONY_PATH, - TELEPHONY_INTERFACE_SIM, - SIGNAL_SIM_STATUS, - sim_signal_handler, - NULL, NULL); - if (ret <= 0) - _E("Failed to register signal handler: %d", ret); -#endif - ret = subscribe_dbus_signal(NULL, DEVICED_OBJECT_PATH, DEVICED_INTERFACE_NAME, -- 2.7.4 From 55c2a69024c4ee4d98f3b61155865841fa7126de Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 20 Mar 2020 12:37:04 +0900 Subject: [PATCH 08/16] Change log priority Change-Id: I769f74865d18961d2806426b940e2760e2bdae5a Signed-off-by: Youngjae Cho --- src/battery/power-supply.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index da65763..6784f67 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -355,7 +355,7 @@ static int send_charge_noti(void) METHOD_CHARGE_NOTI_ON, NULL, NULL, charge_noti_on, -1, NULL); if (ret == 0) { - _D("Created battery charge noti."); + _I("Created battery charge noti."); return ret; } } -- 2.7.4 From 7e8a18d8deba1a531f4e8113d9e74b4a5f474ee0 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 20 Mar 2020 13:04:11 +0900 Subject: [PATCH 09/16] Apply dbus sync call to devicectl (Dumpmode, SaveLog) Change-Id: Id13ffd344c7600068da351fb0d9b0c09303b37f8 Signed-off-by: Hyotaek Shim --- src/devicectl/devicectl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/devicectl/devicectl.c b/src/devicectl/devicectl.c index 2f3da14..ab31b54 100644 --- a/src/devicectl/devicectl.c +++ b/src/devicectl/devicectl.c @@ -114,7 +114,7 @@ static int dump_mode(char **args) printf("%s (%s %s).\n", args[1], args[2], args[3]); - ret = dbus_handle_method_async_var(DEVICED_BUS_NAME, + ret = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, devices[arg_id].path, devices[arg_id].iface, "Dumpmode", @@ -134,11 +134,11 @@ static int save_log(char **args) printf("Save log %s device.\n", args[1]); - ret = dbus_handle_method_async(DEVICED_BUS_NAME, + ret = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, devices[arg_id].path, devices[arg_id].iface, "SaveLog", - NULL, NULL); + NULL); if (ret < 0) printf("Failed to save log: %d", ret); -- 2.7.4 From a8338b3892e68e7ef046b76b7486cd9a329575ba Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 20 Mar 2020 10:26:16 +0900 Subject: [PATCH 10/16] Initialize battery.capacity to 0 Change-Id: If36d9691a98be9e32907602cce26ffaca77baffa Signed-off-by: Youngjae Cho --- src/battery/power-supply.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 6784f67..71663cc 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -1767,7 +1767,6 @@ static void power_supply_init(void *data) memset(&battery, 0, sizeof(struct battery_status)); memset(&old_battery, 0, sizeof(struct battery_status)); - battery.capacity = -1; battery.charger_charging = CHARGER_ENABLED; battery.misc = MISC_NONE; battery.freq_strength = 0; -- 2.7.4 From 6711b44145c4c18a5ad37486b6d065175a1c6a18 Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Fri, 6 Dec 2019 22:02:19 +0900 Subject: [PATCH 11/16] auto-test: init test for battery-monitor Change-Id: I273cfb7c15da79b82ee60cb81df83aff49c4a66c Signed-off-by: sanghyeok.oh --- src/auto-test/CMakeLists.txt | 1 + src/auto-test/auto-test.conf | 1 + src/auto-test/battery-monitor-test.c | 766 +++++++++++++++++++++++++++++++++++ 3 files changed, 768 insertions(+) create mode 100644 src/auto-test/battery-monitor-test.c diff --git a/src/auto-test/CMakeLists.txt b/src/auto-test/CMakeLists.txt index bfa34ff..de6e43e 100644 --- a/src/auto-test/CMakeLists.txt +++ b/src/auto-test/CMakeLists.txt @@ -22,6 +22,7 @@ SET(SRCS ir.c time.c test_dbus_interface.c + battery-monitor-test.c ) FOREACH(flag ${pkgs_CFLAGS}) diff --git a/src/auto-test/auto-test.conf b/src/auto-test/auto-test.conf index 0471071..706f0fd 100644 --- a/src/auto-test/auto-test.conf +++ b/src/auto-test/auto-test.conf @@ -9,6 +9,7 @@ ir=1 time=1 [wearable] +battery-monitor=1 battery=1 display=1 led=0 diff --git a/src/auto-test/battery-monitor-test.c b/src/auto-test/battery-monitor-test.c new file mode 100644 index 0000000..236501f --- /dev/null +++ b/src/auto-test/battery-monitor-test.c @@ -0,0 +1,766 @@ +/* + * test + * + * 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 "test.h" +#include "test_dbus_interface.h" + +#define METHOD_BATTERY_MONITOR_BASIC "basic" +#define METHOD_BATTERY_MONITOR_ONOFF "onoff" +#define METHOD_BATTERY_MONITOR_BRIGHTNESS "brightness" +#define METHOD_BATTERY_MONITOR_BASIC_LCD_OFF "basic_lcdoff" +#define METHOD_BATTERY_MONITOR_BASIC_LCD_ON "basic_lcdon" +#define METHOD_BATTERY_MONITOR_BASIC_SESSIONS "basic_sessions" + + +static struct timeval t_start, t_end; +static void time_set_start(void) +{ + gettimeofday(&t_start, NULL); +} + +static void time_set_end(void) +{ + gettimeofday(&t_end, NULL); +} + +static int time_get_duration_sec(void) +{ + return t_end.tv_sec - t_start.tv_sec; +} + +#define DBUS_DEVICED "org.tizen.system.deviced" +#define DBUS_DEVICED_BM_PATH "/Org/Tizen/System/DeviceD/BatteryMonitor" +#define DBUS_DEVICED_BM_IFACE "org.tizen.system.deviced.BatteryMonitor" +#define DBUS_DEVICED_BM_MEMBER "GetBMData" + +/* + * common structure for application time map. + */ +typedef struct { + char *app_id; /**< application id */ + uint time; /**< total duration for which application as active */ +} app_time_map_st1; + +/* + * structure for "display" feature data. + */ +typedef struct { + uint high; /**< total time in milliseconds during which brightness intensity was high */ + uint low; /**< total time in milliseconds during which brightness intensity was low */ + uint med; /**< total time in milliseconds during which brightness intensity was medium */ + time_t start; /**< start time of feature data collection session */ + time_t stop; /**< stop time of feature data collection session */ + GSList *atm_list; /**< application time map('app_time_map_st1') list for all active applications between start & stop */ + GSList *display_list; /**< list of nodes of 'bm_display_st' for next consecutive sessions */ +} bm_display_st; + +static void _atm_list_free(gpointer data) +{ + app_time_map_st1 *atm = (app_time_map_st1 *)data; + + if (!atm) { + _E("atm is null"); + return; + } + + if (atm->app_id) + g_free(atm->app_id); + + free(atm); +} + +static void _bds_list_free(gpointer data) +{ + bm_display_st *bds = (bm_display_st *)data; + + if (!bds) { + _E("bds is null"); + return; + } + + if (bds->atm_list) + g_slist_free_full(bds->atm_list, _atm_list_free); + + free(bds); +} + +static void bds_header_free(bm_display_st *bds_header) +{ + if (bds_header) { + g_slist_free_full(bds_header->display_list, _bds_list_free); + free(bds_header); + } +} + +static bm_display_st *_variant_to_bds(GVariant *param) +{ + bm_display_st *bds_header = NULL; + bm_display_st *bds = NULL; + GSList *bds_list = NULL; + app_time_map_st1 *atm = NULL; + GVariantIter *iter = NULL; + GVariantIter *sub_iter = NULL; + GSList *atm_list = NULL; + guint vals[3]; + guint64 t_start, t_end; + gchar *app_id = NULL; + guint app_time = 0; + + if (!param) { + _E("Wrong param:null"); + return NULL; + } + + g_variant_get(param, "(a(uuuxxa(su)))", &iter); + if (g_variant_iter_n_children(iter) == 0) { + _E("failed to get data from gvariant. array size is 0."); + goto err; + } + + /* make bds list */ + while (g_variant_iter_loop(iter, "(uuuxxa(su))", + &vals[0], &vals[1], &vals[2], &t_start, &t_end, + &sub_iter)) { + /* make atm list */ + atm_list = NULL; + while (g_variant_iter_loop(sub_iter, "(su)", &app_id, &app_time)) { + atm = (app_time_map_st1 *)malloc(sizeof(app_time_map_st1)); + if (!atm) { + _E("failed to allocate memory"); + goto err; + } + + atm->app_id = g_strdup(app_id); + atm->time = app_time; + + atm_list = g_slist_prepend(atm_list, atm); + } + + bds = (bm_display_st *)malloc(sizeof(bm_display_st)); + if (!bds) { + _E("failed to allocate memory"); + g_slist_free_full(atm_list, _atm_list_free); + goto err; + } + + bds->high = vals[0]; + bds->low = vals[1]; + bds->med = vals[2]; + bds->start = t_start; + bds->stop = t_end; + bds->atm_list = g_slist_reverse(atm_list); + bds->display_list = NULL; + + bds_list = g_slist_prepend(bds_list, bds); + } + + bds_header = (bm_display_st *)calloc(1, sizeof(bm_display_st)); + if (!bds_header) { + _E("failed to allocate memory"); + goto err; + } + + bds_header->display_list = g_slist_reverse(bds_list); + + g_variant_iter_free(iter); + + return bds_header; + +err: + if (iter) + g_variant_iter_free(iter); + if (bds_list) + g_slist_free_full(bds_list, _bds_list_free); + + return NULL; +} + +static bm_display_st *_get_display_info(void) +{ + GVariant *reply = NULL; + bm_display_st *bds = NULL; + + reply = test_deviced_BatteryMonitor_GetBMData(); + if (!reply) { + _E("failed to get battery monitor data"); + return NULL; + } + + /* convert gvariant into bds list */ + bds = _variant_to_bds(reply); + + g_variant_unref(reply); + + return bds; +} + +/* lcd off & reset monitor measurement data */ +static bool _reset_battery_monitor_and_lcdoff(void) +{ + int ret; + GVariant *reply; + + ret = test_deviced_display_CustomLCDOff("proximity"); + if (ret < 0) { + _E("failed to get battery monitor data"); + return false; + } + + /* reset monitor */ + reply = test_deviced_BatteryMonitor_GetBMData(); + if (!reply) { + _E("failed to get battery monitor data"); + return false; + } + g_variant_unref(reply); + + return true; +} + +static int _bds_get_total_brightness_time(bm_display_st *bds) +{ + if (!bds) + return 0; + + return bds->high + bds->med + bds->low; +} + +static int _bds_get_total_app_time(bm_display_st *bds) +{ + GSList *node; + int sum = 0; + + if (!bds || !bds->atm_list) + return 0; + + for (node = bds->atm_list; node != NULL; node = g_slist_next(node)) + sum += ((app_time_map_st1*)(node->data))->time; + + return sum; +} + +static bool _bds_check_brightness_and_app_time(bm_display_st *bds_header) +{ + GSList *bds_list; + bm_display_st *bds; + int brightness; + int app_time; + + if (!bds_header) + return false; + + for (bds_list = bds_header->display_list; bds_list != NULL; bds_list = g_slist_next(bds_list)) { + bds = (bm_display_st*)bds_list->data; + brightness = _bds_get_total_brightness_time(bds); + app_time = _bds_get_total_app_time(bds); + + if (brightness != app_time) { + _E("bds total brightness time(%d) != total app time(%d)", + brightness, app_time); + return false; + } + } + + return true; +} + +static int _bds_list_get_total_brightness_time_ms(bm_display_st *bds_header) +{ + GSList *bds_list; + bm_display_st *bds; + int brightness; + int app_time; + int sum = 0; + + if (!bds_header) + return 0; + + for (bds_list = bds_header->display_list; bds_list != NULL; bds_list = g_slist_next(bds_list)) { + bds = (bm_display_st*)bds_list->data; + sum += _bds_get_total_brightness_time(bds); + } + + _E("sum = %d", sum); + + return sum; +} + +static void print_atm_list(GSList *atm_list) +{ + GSList *list; + app_time_map_st1 *atm; + + for (list = atm_list; list != NULL; list = g_slist_next(list)) { + atm = (app_time_map_st1 *)list->data; + _I("%s %u", atm->app_id, atm->time); + } +} + +static void print_bds_info(bm_display_st *bds) +{ + _I("start:%ld, end:%ld, high:%d, med:%d, low:%d, atm_list len:%d", + bds->start, bds->stop, bds->high, bds->med, bds->low, g_slist_length(bds->atm_list)); + print_atm_list(bds->atm_list); +} + +static void print_bds_list(bm_display_st *bds_header) +{ + GSList *bds_list; + int sum = 0; + + if (!bds_header) + return ; + + for (bds_list = bds_header->display_list; bds_list != NULL; bds_list = g_slist_next(bds_list)) + print_bds_info(bds_list->data); +} + +/* TC */ + +/* + basic dbus interface check + result : reply data +*/ +static bool test_battery_monitor_is_ready(void) +{ + GVariant *ret = test_deviced_BatteryMonitor_GetBMData(); + if (!ret) { + _E("failed to get battery monitor data"); + return false; + } + g_variant_unref(ret); + + return true; +} + +/* + basic lcd on/off test + result : reply single session data +*/ +static bool test_battery_monitor_lcd_on_off(void) +{ + bool pass = true; + int ret; + int duration; + bm_display_st *bds_header = NULL; + bm_display_st *bds = NULL; + int sum; + + if (!_reset_battery_monitor_and_lcdoff()) { + _E("failed to get battery monitor data"); + return false; + } + + ret = test_deviced_display_CustomLCDOn(1); + if (ret < 0) { + _E("failed to get battery monitor data"); + return false; + } + + /* start test */ + time_set_start(); + sleep(1); + time_set_end(); + + ret = test_deviced_display_CustomLCDOff("proximity"); + if (ret < 0) { + _E("failed to get battery monitor data"); + return false; + } + /* end test */ + + /* check result */ + duration = time_get_duration_sec(); + + bds_header = _get_display_info(); + if (!bds_header) { + _E("failed to get battery monitor data"); + pass = false; + goto err; + } + + if (!_bds_check_brightness_and_app_time(bds_header)) { + _E("failed to _bds_check_brightness_and_app_time"); + pass = false; + goto err; + } + + bds = (bm_display_st *)bds_header; + sum = _bds_list_get_total_brightness_time_ms(bds_header); + _I("duration=%d, bm=%d, start-end(%d)", duration, sum, (int)(bds->stop - bds->start)); + + /* approximation : compare sec */ + if (duration != sum / 1000) { + _E("duration mismatched"); + pass = false; + } + +err: + bds_header_free(bds_header); + + return pass; +} + +/* + basic test of brightness(high/med/low) + result : reply single session data and high/med/low value. +*/ +static bool test_battery_monitor_brightness(void) +{ + bool pass = true; + int ret; + int duration; + bm_display_st *bds_header = NULL; + bm_display_st *bds = NULL; + int sum; + + if (!_reset_battery_monitor_and_lcdoff()) { + _E("failed to get battery monitor data"); + return false; + } + + /* init test env */ + ret = test_deviced_display_SetBrightness(0, 100); + if (ret < 0) { + _E("failed to get battery monitor data"); + return false; + } + + /* start test */ + + /* high 1sec */ + ret = test_deviced_display_CustomLCDOn(1); + if (ret < 0) { + _E("failed to get battery monitor data"); + return false; + } + + time_set_start(); + sleep(1); + + /* med 1sec */ + ret = test_deviced_display_SetBrightness(0, 40); + if (ret < 0) { + _E("failed to get battery monitor data"); + return false; + } + sleep(1); + + /* low 1sec */ + ret = test_deviced_display_SetBrightness(0, 10); + if (ret < 0) { + _E("failed to get battery monitor data"); + return false; + } + sleep(1); + time_set_end(); + + ret = test_deviced_display_CustomLCDOff("proximity"); + if (ret < 0) { + _E("failed to get battery monitor data"); + return false; + } + /* end test */ + + /* check result */ + duration = time_get_duration_sec(); + + bds_header = _get_display_info(); + if (!bds_header) { + _E("failed to get battery monitor data"); + return false; + } + + /* expect single session data */ + if (g_slist_length(bds_header->display_list) != 1) { + _E("size(display_list) should be 1, but(%d)", g_slist_length(bds_header->display_list)); + pass = false; + goto err; + } + + if (!_bds_check_brightness_and_app_time(bds_header)) { + pass = false; + goto err; + } + + bds = (bm_display_st *)bds_header->display_list->data; + sum = _bds_list_get_total_brightness_time_ms(bds_header); + _I("duration=%d, bm=%d", duration, sum); + + if (duration != sum / 1000) { + _E("sleep duration(%d) != h+l+m(%d)", duration, sum / 1000); + pass = false; + } + if (bds->high / 1000 != 1) { + _E("bds->high(%d) != 1", bds->high / 1000); + pass = false; + } + if (bds->med / 1000 != 1) { + _E("bds->high(%d) != 1", bds->med / 1000); + pass = false; + } + if (bds->low / 1000 != 1) { + _E("bds->high(%d) != 1", bds->low / 1000); + pass = false; + } + +err: + bds_header_free(bds_header); + + return pass; +} + +/* + basic test of multiple GetBMData call in lcd off state + result : reply single session data(filled with 0) +*/ +static bool test_battery_monitor_request_within_lcd_off(void) +{ + bm_display_st *bds_header = NULL; + bm_display_st *bds = NULL; + int i; + + if (!_reset_battery_monitor_and_lcdoff()) { + _E("failed to get battery monitor data"); + return false; + } + + for (i = 0; i < 10; ++i) { + bds_header = _get_display_info(); + if (!bds_header) { + _E("failed to get battery monitor data"); + return false; + } + /* expect single session */ + if (g_slist_length(bds_header->display_list) != 1) { + _E("failed. size(display list) should be 1"); + goto err; + } + + /* expect zero datas */ + bds = (bm_display_st *)bds_header->display_list->data; + if (bds->start || bds->stop || bds->high || bds->med || bds->low || g_slist_length(bds->atm_list)) { + _E("bds data should be filled with 0"); + print_bds_info(bds); + goto err; + } + + g_slist_free_full(bds_header->display_list, _bds_list_free); + free(bds_header); + } + + return true; +err: + bds_header_free(bds_header); + return false; +} + +/* + basic test of multiple GetBMData call in lcd on state + result : reply single session data(filled with measurement data) +*/ +static bool test_battery_monitor_request_within_lcd_on(void) +{ + bm_display_st *bds_header = NULL; + bm_display_st *bds = NULL; + int i; + int ret; + + if (!_reset_battery_monitor_and_lcdoff()) { + _E("failed to get battery monitor data"); + return false; + } + + /* lcd on */ + ret = test_deviced_display_CustomLCDOn(1); + if (ret < 0) { + _E("failed to get battery monitor data"); + return false; + } + + /* test */ + for (i = 0; i < 10; ++i) { + bds_header = _get_display_info(); + if (!bds_header) { + _E("failed to get battery monitor data"); + return false; + } + /* expect single session */ + if (g_slist_length(bds_header->display_list) != 1) { + _E("failed. size(display list) should be 1"); + goto err; + } + + /* expect some measurement datas */ + bds = (bm_display_st *)bds_header->display_list->data; + if (!bds->start || !bds->stop || !(bds->high + bds->med + bds->low) || !g_slist_length(bds->atm_list)) { + _E("bds data should be filled with datas"); + print_bds_info(bds); + goto err; + } + + g_slist_free_full(bds_header->display_list, _bds_list_free); + free(bds_header); + } + + return true; +err: + bds_header_free(bds_header); + + return false; +} + +/* + battery monitor limitation test ? + result : reply 100 session datas(filled with measurement data) +*/ +static bool test_battery_monitor_generate_many_sessions(void) +{ + bm_display_st *bds_header = NULL; + bm_display_st *bds = NULL; + GSList *list; + const int session_size = 100; + int i; + int ret; + bool pass = true; + + if (!_reset_battery_monitor_and_lcdoff()) { + _E("failed to get battery monitor data"); + return false; + } + + for (i = 0; i < session_size; ++i) { + /* lcd on */ + ret = test_deviced_display_CustomLCDOn(1); + if (ret < 0) { + _E("failed to get battery monitor data"); + return false; + } + usleep(1000); + ret = test_deviced_display_CustomLCDOff("proximity"); + if (ret < 0) { + _E("failed to get battery monitor data"); + return false; + } + } + + /* test */ + bds_header = _get_display_info(); + if (!bds_header) { + _E("failed to get battery monitor data"); + return false; + } + + if (g_slist_length(bds_header->display_list) != session_size) { + _E("failed. size(display list) should be %d. but %d", session_size, g_slist_length(bds_header->display_list)); + pass = false; + goto err; + } + + /* expect measurement datas */ + for (list = bds_header->display_list; list != NULL; list = g_slist_next(list)) { + bds = (bm_display_st *)list->data; + if (!bds->start || !bds->stop || !(bds->high + bds->med + bds->low) || !g_slist_length(bds->atm_list)) { + _E("bds data should be filled with datas"); + print_bds_info(bds); + pass = false; + goto err; + } + } + +err: + bds_header_free(bds_header); + + return true; +} + +void battery_monitor_test_all(int *success, int *fail) +{ + int s = 0; + int f = 0; + + (test_battery_monitor_is_ready()) ? s++ : f++; + (test_battery_monitor_lcd_on_off()) ? s++ : f++; + (test_battery_monitor_brightness()) ? s++ : f++; + //(test_battery_monitor_time_apps()) ? s++ : f++; + (test_battery_monitor_request_within_lcd_off()) ? s++ : f++; + (test_battery_monitor_request_within_lcd_on()) ? s++ : f++; + (test_battery_monitor_generate_many_sessions()) ? s++ : f++; + + if (success) + *success = s; + if (fail) + *fail = f; +} + +static void battery_monitor_init(void *data) +{ + int success = 0; + int fail = 0; + + _I("Start test."); + + battery_monitor_test_all(&success, &fail); + + _I("Total=%d Success=%d Fail=%d", success+fail, success, fail); +} + +static void battery_monitor_exit(void *data) +{ + _I("End test."); +} + +/* systemctl stop batterymonitor.service */ +static int battery_monitor_unit(int argc, char **argv) +{ + if (argc < 4) { + int success = 0; + int fail = 0; + _I("Start test."); + battery_monitor_test_all(&success, &fail); + _I("Total=%d Success=%d Fail=%d", success+fail, success, fail); + } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_MONITOR_BASIC)) { + test_battery_monitor_is_ready(); + } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_MONITOR_ONOFF)) { + test_battery_monitor_lcd_on_off(); + } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_MONITOR_BRIGHTNESS)) { + test_battery_monitor_brightness(); + } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_MONITOR_BASIC_LCD_OFF)) { + test_battery_monitor_request_within_lcd_off(); + } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_MONITOR_BASIC_LCD_ON)) { + test_battery_monitor_request_within_lcd_on(); + } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_MONITOR_BASIC_SESSIONS)) { + test_battery_monitor_generate_many_sessions(); + } else { + _E("Unknown test case."); + } + + return 0; +} + +static const struct test_ops battery_monitor_test_ops = { + .priority = TEST_PRIORITY_NORMAL, + .name = "battery-monitor", + .init = battery_monitor_init, + .exit = battery_monitor_exit, + .unit = battery_monitor_unit, +}; + +TEST_OPS_REGISTER(&battery_monitor_test_ops) -- 2.7.4 From 7ae8cc953ead7f91b9c8b6ea070404a9f673ff33 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Mon, 23 Mar 2020 13:12:13 +0900 Subject: [PATCH 12/16] Fix build warning Change-Id: Ib52902400185d7ea9ed6c7b2094e9c8eee441f13 --- src/devicectl/devicectl.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/devicectl/devicectl.c b/src/devicectl/devicectl.c index ab31b54..19cf443 100644 --- a/src/devicectl/devicectl.c +++ b/src/devicectl/devicectl.c @@ -107,42 +107,50 @@ static int stop_device(char **args) static int dump_mode(char **args) { - int ret; + GVariant *msg; if (!args[1] || !args[2] || !args[3]) return -EINVAL; printf("%s (%s %s).\n", args[1], args[2], args[3]); - ret = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, devices[arg_id].path, devices[arg_id].iface, "Dumpmode", g_variant_new("(s)", args[3])); - if (ret < 0) - printf("Failed to set dump mode: %d", ret); + if (!msg) { + printf("Failed to set dump mode"); + return -EBADMSG; + } + + g_variant_unref(msg); - return ret; + return 0; } static int save_log(char **args) { - int ret; + GVariant *msg; if (!args[1]) return -EINVAL; printf("Save log %s device.\n", args[1]); - ret = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, devices[arg_id].path, devices[arg_id].iface, "SaveLog", NULL); - if (ret < 0) - printf("Failed to save log: %d", ret); + if (!msg) { + printf("Failed to save log"); + return -EBADMSG; + } + + g_variant_unref(msg); - return ret; + return 0; } static void get_pname(pid_t pid, char *pname) -- 2.7.4 From d8be216dd3f8b0446cf49349155630bcd63e0649 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 24 Mar 2020 15:10:52 +0900 Subject: [PATCH 13/16] Add signal broadcast on display detach Path : /Org/Tizen/System/DeviceD/Display Interface : org.tizen.system.deviced.display Signal name : display_detach Change-Id: I31b38b6c389565ccd0df27d26578c28971c5d5eb Signed-off-by: Youngjae Cho --- plugins/wearable/display/core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 55ab9a9..fa9a261 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -2853,6 +2853,7 @@ static void sec_dsim_uevent_changed(struct udev_device *dev) { const char *devpath; const char *action; + int ret; devpath = udev_device_get_devpath(dev); if (!devpath) @@ -2860,8 +2861,16 @@ static void sec_dsim_uevent_changed(struct udev_device *dev) if (!fnmatch(SEC_DSIM_PATH, devpath, 0)) { action = udev_device_get_action(dev); - if (!strcmp(action, UDEV_CHANGE)) + if (!strcmp(action, UDEV_CHANGE)) { + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + DISPLAY_DETACH_STR, + NULL); + if (ret < 0) + _E("Failed to send dbus signal %s.", DISPLAY_DETACH_STR); display_off_by_reason(DISPLAY_DETACH_STR); + } } } -- 2.7.4 From 5bcf96de1d189da7d228ed49651945942017534a Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Tue, 24 Mar 2020 14:42:16 +0900 Subject: [PATCH 14/16] Fix build warning Change-Id: I0bd73a9473bd4fd6763a8f16b24d0995707a0d7b --- src/auto-test/battery-monitor-test.c | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/auto-test/battery-monitor-test.c b/src/auto-test/battery-monitor-test.c index 236501f..6493648 100644 --- a/src/auto-test/battery-monitor-test.c +++ b/src/auto-test/battery-monitor-test.c @@ -285,8 +285,6 @@ static int _bds_list_get_total_brightness_time_ms(bm_display_st *bds_header) { GSList *bds_list; bm_display_st *bds; - int brightness; - int app_time; int sum = 0; if (!bds_header) @@ -320,18 +318,6 @@ static void print_bds_info(bm_display_st *bds) print_atm_list(bds->atm_list); } -static void print_bds_list(bm_display_st *bds_header) -{ - GSList *bds_list; - int sum = 0; - - if (!bds_header) - return ; - - for (bds_list = bds_header->display_list; bds_list != NULL; bds_list = g_slist_next(bds_list)) - print_bds_info(bds_list->data); -} - /* TC */ /* @@ -639,7 +625,6 @@ static bool test_battery_monitor_generate_many_sessions(void) const int session_size = 100; int i; int ret; - bool pass = true; if (!_reset_battery_monitor_and_lcdoff()) { _E("failed to get battery monitor data"); @@ -670,7 +655,6 @@ static bool test_battery_monitor_generate_many_sessions(void) if (g_slist_length(bds_header->display_list) != session_size) { _E("failed. size(display list) should be %d. but %d", session_size, g_slist_length(bds_header->display_list)); - pass = false; goto err; } @@ -680,7 +664,6 @@ static bool test_battery_monitor_generate_many_sessions(void) if (!bds->start || !bds->stop || !(bds->high + bds->med + bds->low) || !g_slist_length(bds->atm_list)) { _E("bds data should be filled with datas"); print_bds_info(bds); - pass = false; goto err; } } -- 2.7.4 From 2fa70c7779dea3c8e9c1f7de9f077b6def30e55d Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 25 Mar 2020 14:23:47 +0900 Subject: [PATCH 15/16] Fix AutoBrightnessChanged considering interaction with AOD Change-Id: I5fb69c70dc75b28b83e438fb37f5d781089c6d2a Signed-off-by: Youngjae Cho --- plugins/wearable/display/display-handler.c | 50 +++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) mode change 100644 => 100755 plugins/wearable/display/display-handler.c diff --git a/plugins/wearable/display/display-handler.c b/plugins/wearable/display/display-handler.c old mode 100644 new mode 100755 index 354a460..36a2b0c --- a/plugins/wearable/display/display-handler.c +++ b/plugins/wearable/display/display-handler.c @@ -34,6 +34,9 @@ #include "display-info.h" #define CHARGER_LCD_NODE "/sys/class/power_supply/battery/lcd" +#define SIGNAL_HOMESCREEN "HomeScreen" +#define CLOCK_CHANGED "clockchanged" +#define CLOCK_END "clockend" enum charging_lcd_state { CHARGING_LCD_OFF = 0, @@ -41,6 +44,8 @@ enum charging_lcd_state { }; static guint autobrt_timer; +static bool lcdon_from_aod; +static int autobrtlevel; static gboolean display_autobrt_changed(gpointer data) { @@ -70,7 +75,12 @@ static GVariant *dbus_autobrightnesschanged(GDBusConnection *conn, * effect seems sluggish because of heavy load of jobs for turning on * display. So delay this brightness change a bit to avoid this * heavy loaded time and therefore make it change smoothly. */ - autobrt_timer = g_timeout_add(200, display_autobrt_changed, (gpointer)level); + if (lcdon_from_aod) { + autobrtlevel = level; + autobrt_timer = g_timeout_add(200, display_autobrt_changed, (gpointer)level); + } else { + display_autobrt_changed((gpointer)level); + } } else { ret = -ENOTSUP; } @@ -78,6 +88,34 @@ static GVariant *dbus_autobrightnesschanged(GDBusConnection *conn, return g_variant_new("(i)", ret); } +static void aod_change_signal(GDBusConnection *conn, + const gchar *sender, + const gchar *path, + const gchar *iface, + const gchar *name, + GVariant *param, + gpointer data) + +{ + char *screen; + + g_variant_get(param, "(s)", &screen); + + /* clock-viewer send "clockchanged" as signal parameter when AOD->LCDON. + * On catching this signal, do change brightness immediately. */ + if (!strncmp(screen, CLOCK_CHANGED, strlen(CLOCK_CHANGED))) { + lcdon_from_aod = false; + if (autobrt_timer) { + g_source_remove(autobrt_timer); + display_autobrt_changed((gpointer)autobrtlevel); + } + } else if (!strncmp(screen, CLOCK_END, strlen(CLOCK_END))) { + lcdon_from_aod = true; + } + + g_free(screen); +} + static const dbus_method_s dbus_methods[] = { { "AutoBrightnessChanged", "i", "i", dbus_autobrightnesschanged }, }; @@ -114,6 +152,16 @@ static void display_handler_init(void *data) prepare_level_handler(); register_notifier(DEVICE_NOTIFIER_LCD, display_state_changed); + lcdon_from_aod = false; + ret = subscribe_dbus_signal(NULL, + DEVICED_OBJECT_PATH, + DEVICED_INTERFACE_NAME, + SIGNAL_HOMESCREEN, + aod_change_signal, + NULL, NULL); + if (ret <= 0) + _E("Failed to register signal handler: %d", ret); + ret = sys_set_int(CHARGER_LCD_NODE, CHARGING_LCD_ON); if (ret < 0) _E("Can't write %s node.", CHARGER_LCD_NODE); -- 2.7.4 From 6063b33acd1d0a5331c29bc53677f4867ab4c6dd Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Wed, 25 Mar 2020 15:15:12 +0900 Subject: [PATCH 16/16] Do not apply GrayScale during UltraPowerSaving Change-Id: Icc2c412cfeed9c5afd7688ff10cbd790c21c4305 Signed-off-by: Hyotaek Shim --- plugins/wearable/display/enhance.c | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/plugins/wearable/display/enhance.c b/plugins/wearable/display/enhance.c index d799711..1675d7b 100644 --- a/plugins/wearable/display/enhance.c +++ b/plugins/wearable/display/enhance.c @@ -104,21 +104,6 @@ static int enhance_lcd_state_changed(void *data) return 0; } -static int enhance_ultrapowersaving_changed(void *data) -{ - bool mode; - - mode = DATA_VALUE_BOOL(data); - - if (!greysacle_setting) - greyscale_status = mode; - - enhance_update_state(); - _I("Set ultra power saving mode."); - - return 0; -} - static void enhance_init(void *data) { int val, ret; @@ -126,8 +111,6 @@ static void enhance_init(void *data) /* register notifier */ register_notifier(DEVICE_NOTIFIER_LCD, enhance_lcd_state_changed); - register_notifier(DEVICE_NOTIFIER_ULTRAPOWERSAVING, - enhance_ultrapowersaving_changed); ret = vconf_notify_key_changed(VCONF_HIGH_CONTRAST, enhance_high_contrast_cb, NULL); @@ -170,8 +153,6 @@ static void enhance_exit(void *data) { /* unregister notifier */ unregister_notifier(DEVICE_NOTIFIER_LCD, enhance_lcd_state_changed); - unregister_notifier(DEVICE_NOTIFIER_ULTRAPOWERSAVING, - enhance_ultrapowersaving_changed); vconf_ignore_key_changed(VCONF_HIGH_CONTRAST, enhance_high_contrast_cb); vconf_ignore_key_changed(VCONF_GREYSCALE, enhance_greyscale_cb); -- 2.7.4