From e20320db0fbaa136355c33b8d3484f99a6a43f9e Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 18 Mar 2020 12:27:45 +0900 Subject: [PATCH 01/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 02/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 03/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 04/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 05/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 06/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 07/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 08/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 09/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 10/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 11/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 12/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 13/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 From 062007edea62eab61e1cc58a90755e402d2dab16 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Mon, 23 Mar 2020 08:30:36 +0900 Subject: [PATCH 14/16] Remove unused sources It has been moved to libsyscommon. Change-Id: I8f9241b359905ae71caf935803f083f040f21a3c --- src/shared/deviced-systemd.c | 458 ------------------------------------------- src/shared/deviced-systemd.h | 64 ------ 2 files changed, 522 deletions(-) delete mode 100644 src/shared/deviced-systemd.c delete mode 100644 src/shared/deviced-systemd.h diff --git a/src/shared/deviced-systemd.c b/src/shared/deviced-systemd.c deleted file mode 100644 index df10e1c..0000000 --- a/src/shared/deviced-systemd.c +++ /dev/null @@ -1,458 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2014 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. - */ - -#define _GNU_SOURCE - -#include -#include -#include -#include -#include -#include -#include - -#include "common.h" -#include "deviced-systemd.h" - -#include "core/log.h" - -#define SYSTEMD_UNIT_ESCAPE_CHAR ".-" - -typedef unsigned int uint; -typedef long long int64; -typedef unsigned long long uint64; - -#define g_variant_type_int32 G_VARIANT_TYPE_INT32 -#define g_variant_type_int64 G_VARIANT_TYPE_INT64 -#define g_variant_type_uint32 G_VARIANT_TYPE_UINT32 -#define g_variant_type_uint64 G_VARIANT_TYPE_UINT64 -#define g_variant_type_string G_VARIANT_TYPE_STRING - -#define g_variant_get_function_int32(v) g_variant_get_int32(v) -#define g_variant_get_function_int64(v) g_variant_get_int64(v) -#define g_variant_get_function_uint32(v) g_variant_get_uint32(v) -#define g_variant_get_function_uint64(v) g_variant_get_uint64(v) -#define g_variant_get_function_string(v) g_variant_dup_string(v, NULL) - -/* -static int deviced_systemd_proxy_call_sync(const char *name, - const char *path, - const char *iface, - const char *method, - GVariant *variant, - GVariant **reply) -{ - GVariant *gvar; - GError *error; - GDBusProxy *proxy; - int ret = 0; - -#if (GLIB_MAJOR_VERSION <= 2 && GLIB_MINOR_VERSION < 36) - g_type_init(); -#endif - - error = NULL; - proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - NULL, // GDBusInterfaceInfo - name, - path, - iface, - NULL, // GCancellable - &error); - - if (proxy == NULL) { - _E("Error creating proxy: %s", error->message); - ret = error->code; - g_error_free(error); - return ret; - } - - error = NULL; - gvar = g_dbus_proxy_call_sync(proxy, - method, - variant, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, // GCancellable - &error); - - if (error) { - _E("Error proxy call sync: %s", error->message); - ret = error->code; - g_error_free(error); - return -ret; - } - - g_assert(gvar != NULL); - *reply = gvar; - g_clear_error(&error); - g_object_unref(proxy); - - return 0; -} -*/ - -static int deviced_systemd_start_or_stop_unit(char *method, char *name) -{ - GVariant *reply = NULL; - gchar *objpath = NULL; - int ret = 0; - - _I("Starting: method=%s name=%s", method, name); - reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, - SYSTEMD_DBUS_PATH, - SYSTEMD_DBUS_IFACE_MANAGER, - method, - g_variant_new("(ss)", name, "replace")); - - if (!reply || !dh_get_param_from_var(reply, "(o)", &objpath)) { - _E("Failed to get %s: no message", method); - ret = -EBADMSG; - goto finish; - } - - _I("Finished: method=%s name=%s", method, name); -finish: - if (reply) - g_variant_unref(reply); - g_free(objpath); - - return ret; -} - -int deviced_systemd_start_unit(char *name) -{ - if (name == NULL) { - _E("Wrong name(%s)", name); - return -1; - } - - return deviced_systemd_start_or_stop_unit("StartUnit", name); -} - -int deviced_systemd_stop_unit(char *name) -{ - if (name == NULL) { - _E("Wrong name(%s)", name); - return -1; - } - - return deviced_systemd_start_or_stop_unit("StopUnit", name); -} - -static char *deviced_systemd_get_unit_dbus_path(const char *unit) -{ - char *path = NULL; - int i; - size_t p, k, prefix_len, unit_len = strlen(unit); - size_t path_len, len, escape; - - assert(unit); - - for (escape = 0, p = 0; p < unit_len; escape++) { - k = strcspn(unit+p, SYSTEMD_UNIT_ESCAPE_CHAR); - if (p+k >= unit_len) - break; - p += k+1; - } - - prefix_len = strlen(SYSTEMD_DBUS_UNIT_PATH); - /* assume we try to get object path of foo-bar.service then - * the object path will be - * "/org/freedesktop/systemd1/unit/foo_2dbar_2eservice\n". In - * this case we can find two escape characters, one of escape - * char('-') is changed to three of char("_2d"). So the total - * length will be: */ - /* (PREFIX) + (unit - escape + 3*escape) + NULL */ - path_len = prefix_len + (unit_len - escape) - + (escape * 3 * sizeof(char)) + 1; - path = (char *)calloc(path_len, sizeof(char)); - if (!path) - return NULL; - - strncpy(path, SYSTEMD_DBUS_UNIT_PATH, prefix_len + 1); - for (i = 0, p = 0; i <= escape; i++) { - k = strcspn(unit + p, SYSTEMD_UNIT_ESCAPE_CHAR); - strncpy(path + prefix_len, unit + p, k); - if (k < strlen(unit + p)) { - len = path_len - (prefix_len + k); - snprintf(path + prefix_len + k, len, - "_%x", *(unit + p + k) & 0xff); - prefix_len += k+3; - p += k+1; - } - } - - return path; -} - -/* -static GVariant * deviced_systemd_get_property(const char *name, - const char *path, - const char *iface, - const char *method, - const char *interface, - const char *property) -{ - GVariant *reply; - - reply = dbus_handle_method_sync_with_reply_var(name, - path, - iface, - method, - g_variant_new("(ss)", interface, property)); - - return reply; -} -*/ - -GVariant * deviced_systemd_get_manager_property(const char *property) -{ - GVariant *reply = NULL; - GVariant *val = NULL; - - assert(property); - - reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, - SYSTEMD_DBUS_PATH, - DBUS_IFACE_DBUS_PROPERTIES, - "Get", - g_variant_new("(ss)", SYSTEMD_DBUS_IFACE_MANAGER, property)); - if (!reply || !dh_get_param_from_var(reply, "(v)", &val)) - _E("Failed to get variant."); - if (reply) - g_variant_unref(reply); - - return val; -} - -GVariant * deviced_systemd_get_unit_property(const char *unit, - const char *property) -{ - char *escaped; - GVariant * reply = NULL; - GVariant *val = NULL; - - assert(unit); - assert(property); - - escaped = deviced_systemd_get_unit_dbus_path(unit); - - reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, - escaped, - DBUS_IFACE_DBUS_PROPERTIES, - "Get", - g_variant_new("(ss)", SYSTEMD_DBUS_IFACE_UNIT, property)); - - if (!reply || !dh_get_param_from_var(reply, "(v)", &val)) - _E("Failed to get variant."); - if (reply) - g_variant_unref(reply); - free(escaped); - - return val; -} - -GVariant * deviced_systemd_get_service_property(const char *unit, - const char *property) -{ - char *escaped; - GVariant * reply = NULL; - GVariant *val = NULL; - - assert(unit); - assert(property); - - escaped = deviced_systemd_get_unit_dbus_path(unit); - - reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, - escaped, - DBUS_IFACE_DBUS_PROPERTIES, - "Get", - g_variant_new("(ss)", SYSTEMD_DBUS_IFACE_SERVICE, property)); - if (!reply || !dh_get_param_from_var(reply, "(v)", &val)) - _E("Failed to get variant."); - if (reply) - g_variant_unref(reply); - free(escaped); - return val; -} - -int check_systemd_active(void) -{ - GVariant *msg, inner; - int ret = FALSE; - const char *state; - char *pa[2]; - - pa[0] = "org.freedesktop.systemd1.Unit"; - pa[1] = "ActiveState"; - - _I("%s %s", pa[0], pa[1]); - - msg = dbus_handle_method_sync_with_reply_var("org.freedesktop.systemd1", - "/org/freedesktop/systemd1/unit/default_2etarget", - "org.freedesktop.DBus.Properties", - "Get", g_variant_new("(ss)", pa[0], pa[1])); - - if (!msg) - return -EBADMSG; - - if (!dh_get_param_from_var(msg, "(v)", &inner)) { - _E("Failed to get signature(%s): no message", g_variant_get_type_string(msg)); - ret = -EBADMSG; - goto out2; - } - - if (!dh_get_param_from_var(inner, "s", &state)) { - _E("Failed to get signature(%s): no message", g_variant_get_type_string(inner)); - ret = -EBADMSG; - goto out1; - } - - if (strncmp(state, "active", 6) == 0) - ret = TRUE; -out1: - g_variant_unref(inner); - -out2: - g_variant_unref(msg); - return ret; -} - -#if 0 -#define DEFINE_SYSTEMD_GET_PROPERTY(iface, type, value) \ - int deviced_systemd_get_##iface##_property_as_##type( \ - const char *target, \ - const char *property, \ - value*result) \ -{ \ - \ - GVariant *var; \ - GVariant *inner; \ - int r; \ - \ - r = deviced_systemd_get_##iface##_property(target, \ - property, \ - &var); \ - if (r < 0) { \ - _E("Failed to get property:\n" \ - " target: %s\n" \ - " property: %s", \ - target, property); \ - return r; \ - } \ - \ - if (!g_variant_is_of_type(var, \ - G_VARIANT_TYPE("(v)"))) \ - return -EBADMSG; \ - \ - g_variant_get(var, "(v)", &inner); \ - if (!g_variant_is_of_type(inner, \ - g_variant_type_##type)) \ - return -EBADMSG; \ - \ - *result = g_variant_get_function_##type(inner); \ - g_variant_unref(var); \ - \ - return 0; \ -} - - -/* int deviced_systemd_get_manager_property_as_int32(const char *iface, const char *property, int *result); */ -DEFINE_SYSTEMD_GET_PROPERTY(manager, int32, int) -/* int deviced_systemd_get_manager_property_as_uint32(const char *iface, const char *property, unsigned int *result); */ -DEFINE_SYSTEMD_GET_PROPERTY(manager, uint32, uint) -/* int deviced_systemd_get_manager_property_as_int64(const char *iface, const char *property, long long *result); */ -DEFINE_SYSTEMD_GET_PROPERTY(manager, int64, long long) -/* int deviced_systemd_get_manager_property_as_uint64(const char *iface, const char *property, unsigned long long *result); */ -DEFINE_SYSTEMD_GET_PROPERTY(manager, uint64, unsigned long long) -/* int deviced_systemd_get_manager_property_as_string(const char *iface, const char *property, char **result); */ -DEFINE_SYSTEMD_GET_PROPERTY(manager, string, char*) -/* int deviced_systemd_get_unit_property_as_int32(const char *unit, const char *property, int *result); */ -DEFINE_SYSTEMD_GET_PROPERTY(unit, int32, int) -/* int deviced_systemd_get_unit_property_as_uint32(const char *unit, const char *property, unsigned int *result); */ -DEFINE_SYSTEMD_GET_PROPERTY(unit, uint32, uint) -/* int deviced_systemd_get_unit_property_as_int64(const char *unit, const char *property, long long *result); */ -DEFINE_SYSTEMD_GET_PROPERTY(unit, int64, long long) -/* int deviced_systemd_get_unit_property_as_uint64(const char *unit, const char *property, unsigned long long *result); */ -DEFINE_SYSTEMD_GET_PROPERTY(unit, uint64, unsigned long long) -/* int deviced_systemd_get_unit_property_as_string(const char *unit, const char *property, char **result); */ -DEFINE_SYSTEMD_GET_PROPERTY(unit, string, char*) -/* int deviced_systemd_get_service_property_as_int32(const char *unit, const char *property, int *result); */ -DEFINE_SYSTEMD_GET_PROPERTY(service, int32, int) -/* int deviced_systemd_get_service_property_as_uint32(const char *unit, const char *property, unsigned int *result); */ -DEFINE_SYSTEMD_GET_PROPERTY(service, uint32, uint) -/* int deviced_systemd_get_service_property_as_int64(const char *unit, const char *property, long long *result); */ -DEFINE_SYSTEMD_GET_PROPERTY(service, int64, long long) -/* int deviced_systemd_get_service_property_as_uint64(const char *unit, const char *property, unsigned long long *result); */ -DEFINE_SYSTEMD_GET_PROPERTY(service, uint64, unsigned long long) -/* int deviced_systemd_get_service_property_as_string(const char *unit, const char *property, char **result); */ -DEFINE_SYSTEMD_GET_PROPERTY(service, string, char*) - -int deviced_systemd_instance_new_from_template(const char *template, - const char *instance, - const char **name) -{ - /* p point '@' */ - /* e point '.' */ - const char *p, *e; - char *prefix = NULL, *n = NULL; - int r; - - assert(template); - p = strchr(template, '@'); - if (!p) { - r = -EINVAL; - goto finish; - } - - prefix = strndup(template, p - template + 1); - if (!prefix) { - r = -ENOMEM; - goto finish; - } - - e = strrchr(p + 1, '.'); - if (!e) { - r = -EINVAL; - goto finish; - } - - /* verifying template. prefix@.service */ - if (e != p + 1) { - r = -EINVAL; - goto finish; - } - - r = asprintf(&n, "%s%s%s", prefix, instance, e); - if (r < 0) { - r = -ENOMEM; - goto finish; - } - - *name = n; - r = 0; -finish: - if (prefix) - free(prefix); - - return r; -} -#endif diff --git a/src/shared/deviced-systemd.h b/src/shared/deviced-systemd.h deleted file mode 100644 index 5a6f44f..0000000 --- a/src/shared/deviced-systemd.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __DEVICED_SYSTEMD_H__ -#define __DEVICED_SYSTEMD_H__ - -#include - -#define DBUS_IFACE_DBUS_PROPERTIES "org.freedesktop.DBus.Properties" - -#define SYSTEMD_DBUS_DEST "org.freedesktop.systemd1" -#define SYSTEMD_DBUS_IFACE_MANAGER SYSTEMD_DBUS_DEST ".Manager" -#define SYSTEMD_DBUS_IFACE_UNIT SYSTEMD_DBUS_DEST ".Unit" -#define SYSTEMD_DBUS_IFACE_SERVICE SYSTEMD_DBUS_DEST ".Service" -#define SYSTEMD_DBUS_IFACE_TARGET SYSTEMD_DBUS_DEST ".Target" - -#define SYSTEMD_DBUS_PATH "/org/freedesktop/systemd1" -#define SYSTEMD_DBUS_UNIT_PATH SYSTEMD_DBUS_PATH "/unit/" - -int deviced_systemd_start_unit(char *name); -int deviced_systemd_stop_unit(char *name); -int check_systemd_active(void); - -GVariant * deviced_systemd_get_manager_property(const char *property); -GVariant * deviced_systemd_get_unit_property(const char *unit, const char *property); -GVariant * deviced_systemd_get_service_property(const char* unit, const char* property); - -#if 0 -int deviced_systemd_get_manager_property_as_int32(const char *iface, const char *property, int *result); -int deviced_systemd_get_manager_property_as_uint32(const char *iface, const char *property, unsigned int *result); -int deviced_systemd_get_manager_property_as_int64(const char *iface, const char *property, long long *result); -int deviced_systemd_get_manager_property_as_uint64(const char *iface, const char *property, unsigned long long *result); -int deviced_systemd_get_manager_property_as_string(const char *iface, const char *property, char **result); -int deviced_systemd_get_unit_property_as_int32(const char *unit, const char *property, int *result); -int deviced_systemd_get_unit_property_as_uint32(const char *unit, const char *property, unsigned int *result); -int deviced_systemd_get_unit_property_as_int64(const char *unit, const char *property, long long *result); -int deviced_systemd_get_unit_property_as_uint64(const char *unit, const char *property, unsigned long long *result); -int deviced_systemd_get_unit_property_as_string(const char *unit, const char *property, char **result); -int deviced_systemd_get_service_property_as_int32(const char *unit, const char *property, int *result); -int deviced_systemd_get_service_property_as_uint32(const char *unit, const char *property, unsigned int *result); -int deviced_systemd_get_service_property_as_int64(const char *unit, const char *property, long long *result); -int deviced_systemd_get_service_property_as_uint64(const char *unit, const char *property, unsigned long long *result); -int deviced_systemd_get_service_property_as_string(const char *unit, const char *property, char **result); - -int deviced_systemd_instance_new_from_template(const char *template, const char *instance, const char **name); -#endif - -#endif -- 2.7.4 From 5b02a82957a4834b5f84c19562ace8be42cc2045 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 26 Mar 2020 10:21:46 +0900 Subject: [PATCH 15/16] Add vconf set for charger type Change-Id: I83a35de22a2e5df90b2921be6077d49033ff1ddc Signed-off-by: Youngjae Cho --- src/battery/power-supply.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 71663cc..c1cc500 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -861,6 +861,10 @@ static void process_power_supply(void *data) } if (old_battery.online_type != battery.online_type) { + ret = vconf_set_int(VCONFKEY_SYSMAN_CHARGER_TYPE, battery.online_type); + if (ret < 0) + _E("Failed to set vconf value for charger type: %d", vconf_get_ext_errno()); + if (power_supply_broadcast(CHARGER_TYPE_SIGNAL, battery.online_type) < 0) broadcasted = false; } -- 2.7.4 From 239c93cfa394c48c47c6eb206bdcc498e168c76a Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 26 Mar 2020 12:30:55 +0900 Subject: [PATCH 16/16] Fix g_timeout_add_seconds with double type timeout Use g_timeout_add instead with milisecond scale. Change-Id: I60630308cf2e1588d2ec7b0c78202d483f8d96b8 Signed-off-by: Youngjae Cho --- plugins/iot/display/core.c | 6 +++--- plugins/mobile/display/core.c | 6 +++--- plugins/tv/display/core.c | 6 +++--- plugins/wearable/display/core.c | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 4e34698..42a4511 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -986,7 +986,7 @@ void reset_timeout(int timeout) return; if (timeout > 0) - timeout_src_id = g_timeout_add_seconds(MSEC_TO_SEC((double)timeout), + timeout_src_id = g_timeout_add(timeout, timeout_handler, NULL); else if (timeout == 0) states[pm_cur_state].trans(EVENT_TIMEOUT); @@ -1453,8 +1453,8 @@ static void proc_condition_lock(PMMsg *data) /* To pass a pid_t data through the timer infrastructure * without memory allocation, a pid_t data becomes typecast * to intptr_t and void *(64bit) type. */ - cond_timeout_id = g_timeout_add_seconds( - MSEC_TO_SEC((double)data->timeout), + cond_timeout_id = g_timeout_add( + data->timeout, states[state].timeout_cb, (void*)((intptr_t)pid)); if (!cond_timeout_id) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index f7fd0da..2d95ab9 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -992,7 +992,7 @@ void reset_timeout(int timeout) return; if (timeout > 0) - timeout_src_id = g_timeout_add_seconds(MSEC_TO_SEC((double)timeout), + timeout_src_id = g_timeout_add(timeout, timeout_handler, NULL); else if (timeout == 0) states[pm_cur_state].trans(EVENT_TIMEOUT); @@ -1463,8 +1463,8 @@ static void proc_condition_lock(PMMsg *data) /* To pass a pid_t data through the timer infrastructure * without memory allocation, a pid_t data becomes typecast * to intptr_t and void *(64bit) type. */ - cond_timeout_id = g_timeout_add_seconds( - MSEC_TO_SEC((double)data->timeout), + cond_timeout_id = g_timeout_add( + data->timeout, states[state].timeout_cb, (void*)((intptr_t)pid)); if (!cond_timeout_id) diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 788de3b..10adea5 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -983,7 +983,7 @@ void reset_timeout(int timeout) return; if (timeout > 0) - timeout_src_id = g_timeout_add_seconds(MSEC_TO_SEC((double)timeout), + timeout_src_id = g_timeout_add(timeout, timeout_handler, NULL); else if (timeout == 0) states[pm_cur_state].trans(EVENT_TIMEOUT); @@ -1450,8 +1450,8 @@ static void proc_condition_lock(PMMsg *data) /* To pass a pid_t data through the timer infrastructure * without memory allocation, a pid_t data becomes typecast * to intptr_t and void *(64bit) type. */ - cond_timeout_id = g_timeout_add_seconds( - MSEC_TO_SEC((double)data->timeout), + cond_timeout_id = g_timeout_add( + data->timeout, states[state].timeout_cb, (void*)((intptr_t)pid)); if (!cond_timeout_id) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index fa9a261..844a946 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -1008,7 +1008,7 @@ void reset_timeout(int timeout) return; if (timeout > 0) - timeout_src_id = g_timeout_add_seconds(MSEC_TO_SEC((double)timeout), + timeout_src_id = g_timeout_add(timeout, timeout_handler, NULL); else if (timeout == 0) states[pm_cur_state].trans(EVENT_TIMEOUT); @@ -1502,8 +1502,8 @@ static void proc_condition_lock(PMMsg *data) /* To pass a pid_t data through the timer infrastructure * without memory allocation, a pid_t data becomes typecast * to intptr_t and void *(64bit) type. */ - cond_timeout_id = g_timeout_add_seconds( - MSEC_TO_SEC((double)data->timeout), + cond_timeout_id = g_timeout_add( + data->timeout, states[state].timeout_cb, (void*)((intptr_t)pid)); if (!cond_timeout_id) -- 2.7.4