From 4f9d2d05af887bd689876f1ed8c2536ece5a60ca Mon Sep 17 00:00:00 2001 From: taeyoung Date: Thu, 19 Nov 2015 12:55:27 +0900 Subject: [PATCH 01/16] usb: enable sdb before launching deviced - sdb should be enabled even if deviced is not available for debugging. Thus sdb-prestart.service is added Change-Id: Icb73619d13eae267698332257f86041978911800 Signed-off-by: taeyoung --- packaging/deviced.spec | 12 +++++ scripts/direct_set_debug.sh | 101 ++----------------------------------------- systemd/sdb-prestart.service | 9 ++++ 3 files changed, 25 insertions(+), 97 deletions(-) create mode 100644 systemd/sdb-prestart.service diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 6d1d441..f5b7d74 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -17,6 +17,9 @@ %define usb_module on %define usbhost_module off +#Just For debugging +%define sdb_prestart on + %if "%{?profile}" == "mobile" %define battery_module on %define block_module on @@ -32,6 +35,7 @@ %if "%{?profile}" == "tv" %define block_module on %define tzip_module off +%define sdb_prestart off %endif Name: deviced @@ -258,6 +262,9 @@ rm -rf %{buildroot} %install_service multi-user.target.wants deviced.service %install_service sockets.target.wants deviced.socket %install_service graphical.target.wants zbooting-done.service +%if %{?sdb_prestart} == on +%install_service basic.target.wants sdb-prestart.service +%endif %post #memory type vconf key init @@ -328,6 +335,11 @@ systemctl daemon-reload %config %{_sysconfdir}/deviced/usb-operation.conf %endif +%if %{?sdb_prestart} == on +%{_unitdir}/sdb-prestart.service +%{_unitdir}/basic.target.wants/sdb-prestart.service +%endif + %files tools %manifest %{name}.manifest %{_bindir}/devicectl diff --git a/scripts/direct_set_debug.sh b/scripts/direct_set_debug.sh index f99469d..d59d9e1 100755 --- a/scripts/direct_set_debug.sh +++ b/scripts/direct_set_debug.sh @@ -1,36 +1,9 @@ #!/bin/sh -VERSION= - -check_driver_version() { - if [ -f /sys/class/usb_mode/version ] - then - VERSION=`cat /sys/class/usb_mode/version` - else - VERSION="0.0" - fi -} - -load_usb_gadget_0_0() { - echo 4 > /sys/devices/platform/usb_mode/UsbMenuSel -} - -load_usb_gadget_1_0() { - echo 0 > /sys/class/usb_mode/usb0/enable - echo 04e8 > /sys/class/usb_mode/usb0/idVendor - echo $1 > /sys/class/usb_mode/usb0/idProduct - echo $2 > /sys/class/usb_mode/usb0/functions - echo 239 > /sys/class/usb_mode/usb0/bDeviceClass - echo 2 > /sys/class/usb_mode/usb0/bDeviceSubClass - echo 1 > /sys/class/usb_mode/usb0/bDeviceProtocol - echo 1 > /sys/class/usb_mode/usb0/enable -} - -load_usb_gadget_1_1() { +load_usb_gadget() { echo 0 > /sys/class/usb_mode/usb0/enable echo 04e8 > /sys/class/usb_mode/usb0/idVendor echo $1 > /sys/class/usb_mode/usb0/idProduct - echo " " > /sys/class/usb_mode/usb0/functions echo $2 > /sys/class/usb_mode/usb0/funcs_fconf echo $3 > /sys/class/usb_mode/usb0/funcs_sconf echo 239 > /sys/class/usb_mode/usb0/bDeviceClass @@ -39,104 +12,38 @@ load_usb_gadget_1_1() { echo 1 > /sys/class/usb_mode/usb0/enable } -unload_usb_gadget_1() { +unload_usb_gadget() { echo 0 > /sys/class/usb_mode/usb0/enable } sdb_set() { - case "$VERSION" in - "1.0") - load_usb_gadget_1_0 "6860" "mtp,acm,sdb" - ;; - "1.1") - load_usb_gadget_1_1 "6860" "mtp" "mtp,acm,sdb" - ;; - *) - echo "USB driver version $VERSION is not supported" - return - ;; - esac - + load_usb_gadget "6860" "sdb" "acm,sdb" /usr/bin/systemctl start sdbd.service echo "SDB enabled" } -ssh_set() { - case "$VERSION" in - "0.0") - load_usb_gadget_0_0 - ;; - "1.0") - load_usb_gadget_1_0 "6864" "rndis" - ;; - "1.1") - load_usb_gadget_1_1 "6864" "rndis" " " - ;; - *) - echo "USB driver version $VERSION is not supported" - return - ;; - esac - - /sbin/ifconfig usb0 192.168.129.3 up - /sbin/route add -net 192.168.129.0 netmask 255.255.255.0 dev usb0 - /usr/bin/systemctl start sshd.service - echo "SSH enabled" -} - -usb_unset() { - case "$VERSION" in - "1.0" | "1.1") - unload_usb_gadget_1 - ;; - *) - echo "USB driver version $VERSION is not supported" - return - ;; - esac -} - sdb_unset() { - usb_unset + unload_usb_gadget /usr/bin/systemctl stop sdbd.service echo "SDB disabled" } -ssh_unset() { - usb_unset - /sbin/ifconfig usb0 down - /usr/bin/systemctl stop sshd.service - echo "SSH disabled" -} - show_options() { echo "direct_set_debug.sh: usage:" echo " --help This message" echo " --sdb-set Load sdb without usb-manager" echo " --sdb-unset Unload sdb without usb-manager" - echo " --ssh-set Load ssh without usb-manager" - echo " --ssh-unset Unload ssh without usb-manager" } -check_driver_version - case "$1" in "--sdb-set") sdb_set ;; -"--ssh-set") - ssh_set - ;; - "--sdb-unset") sdb_unset ;; -"--ssh-unset") - ssh_unset - ;; - "--help") show_options ;; diff --git a/systemd/sdb-prestart.service b/systemd/sdb-prestart.service new file mode 100644 index 0000000..4e8e0e1 --- /dev/null +++ b/systemd/sdb-prestart.service @@ -0,0 +1,9 @@ +[Unit] +Description=Enadle sdb at booting time +DefaultDependencies=no + +[Service] +ExecStart=/usr/bin/direct_set_debug.sh --sdb-set + +[Install] +WantedBy=basic.target -- 2.7.4 From b27db7d92886d2e5cdf4db9b7fef01a63e95ac1e Mon Sep 17 00:00:00 2001 From: taeyoung Date: Thu, 19 Nov 2015 23:08:20 +0900 Subject: [PATCH 02/16] usb: fix build break issue in case that sdb_prestart option is off - All of service files are added to /usr/lib/systemd/system. Thus unpacked file breaks build if sdb_prestart option is off. - The issue is fixed by installing all service files always. Change-Id: I66bd3e29192f844a6d3714929ff424253dc66622 Signed-off-by: taeyoung --- packaging/deviced.spec | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index f5b7d74..d493760 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -18,7 +18,7 @@ %define usbhost_module off #Just For debugging -%define sdb_prestart on +%define sdb_prestart off %if "%{?profile}" == "mobile" %define battery_module on @@ -26,16 +26,17 @@ %define haptic_module on %define led_module on %define telephony_module on +%define sdb_prestart on %endif %if "%{?profile}" == "wearable" %define battery_module on %define haptic_module on %define telephony_module on +%define sdb_prestart on %endif %if "%{?profile}" == "tv" %define block_module on %define tzip_module off -%define sdb_prestart off %endif Name: deviced @@ -335,8 +336,8 @@ systemctl daemon-reload %config %{_sysconfdir}/deviced/usb-operation.conf %endif -%if %{?sdb_prestart} == on %{_unitdir}/sdb-prestart.service +%if %{?sdb_prestart} == on %{_unitdir}/basic.target.wants/sdb-prestart.service %endif -- 2.7.4 From e501a2a75998f1772d04dd57a819b70b5360ce52 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Fri, 20 Nov 2015 16:39:25 +0900 Subject: [PATCH 03/16] tzip: disable tzip until libfuse is enabled - Currently, deviced cannot be launched since libfuse is not installed in deviced. Thus tzip is disabled for a moment Change-Id: I0bc8a3809eb9763d0cdf689016e4f0d4b53ceb44 Signed-off-by: taeyoung --- packaging/deviced.spec | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index d493760..ee644ad 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -13,7 +13,7 @@ %define led_module off %define power_module on %define telephony_module off -%define tzip_module on +%define tzip_module off %define usb_module on %define usbhost_module off @@ -36,7 +36,6 @@ %endif %if "%{?profile}" == "tv" %define block_module on -%define tzip_module off %endif Name: deviced -- 2.7.4 From 7aa0500511d60d16a72ba884eb337c14e033ab88 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Fri, 20 Nov 2015 17:57:09 +0900 Subject: [PATCH 04/16] usb: enable sdb using udev rule - UDC(USB Device Controller) is enabled only if usb gadget is enabled with connected usb cable. Thus udev rule detects usb cable connection and enables usb gadget - TM1 target uses switch subsystem. Thus the udev rule is related with switch subsystem. Change-Id: Ib75620f5a9b8ea97c98a6928f59322cfe9f4edf1 Signed-off-by: taeyoung --- packaging/deviced.spec | 11 +++++++++-- rules/99-deviced-sdb-enable.rules | 2 ++ scripts/direct_set_debug.sh | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 rules/99-deviced-sdb-enable.rules diff --git a/packaging/deviced.spec b/packaging/deviced.spec index ee644ad..a575b97 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -26,13 +26,11 @@ %define haptic_module on %define led_module on %define telephony_module on -%define sdb_prestart on %endif %if "%{?profile}" == "wearable" %define battery_module on %define haptic_module on %define telephony_module on -%define sdb_prestart on %endif %if "%{?profile}" == "tv" %define block_module on @@ -266,6 +264,11 @@ rm -rf %{buildroot} %install_service basic.target.wants sdb-prestart.service %endif +%if "%{?tizen_target_name}" == "TM1" +mkdir -p %{buildroot}%{_prefix}/lib/udev/rules.d/ +install -m 644 rules/99-deviced-sdb-enable.rules %{buildroot}%{_prefix}/lib/udev/rules.d/ +%endif + %post #memory type vconf key init users_gid=$(getent group %{TZ_SYS_USER_GROUP} | cut -f3 -d':') @@ -340,6 +343,10 @@ systemctl daemon-reload %{_unitdir}/basic.target.wants/sdb-prestart.service %endif +%if "%{?tizen_target_name}" == "TM1" +%{_prefix}/lib/udev/rules.d/99-deviced-sdb-enable.rules +%endif + %files tools %manifest %{name}.manifest %{_bindir}/devicectl diff --git a/rules/99-deviced-sdb-enable.rules b/rules/99-deviced-sdb-enable.rules new file mode 100644 index 0000000..8d460c8 --- /dev/null +++ b/rules/99-deviced-sdb-enable.rules @@ -0,0 +1,2 @@ +SUBSYSTEM=="switch", ENV{SWITCH_NAME}=="usb_cable", ENV{SWITCH_STATE}=="1", RUN+="/usr/bin/direct_set_debug.sh --sdb-set" +SUBSYSTEM=="switch", ENV{SWITCH_NAME}=="usb_cable", ENV{SWITCH_STATE}=="0", RUN+="/usr/bin/direct_set_debug.sh --sdb-unset" diff --git a/scripts/direct_set_debug.sh b/scripts/direct_set_debug.sh index d59d9e1..75d232f 100755 --- a/scripts/direct_set_debug.sh +++ b/scripts/direct_set_debug.sh @@ -17,7 +17,7 @@ unload_usb_gadget() { } sdb_set() { - load_usb_gadget "6860" "sdb" "acm,sdb" + load_usb_gadget "6860" "sdb" "" /usr/bin/systemctl start sdbd.service echo "SDB enabled" } -- 2.7.4 From ec364cc86fe174c85bbc32f3239dbd270fd6424d Mon Sep 17 00:00:00 2001 From: taeyoung Date: Mon, 23 Nov 2015 11:31:25 +0900 Subject: [PATCH 05/16] tzip: enable tzip with mobile and wearable profile. - tzip is used for installing apps without unzipping zip files. The zip file is just mounted to a certain directory. Change-Id: I605bdaa888540a1d25f0dc48765e1d05be3f9f9e Signed-off-by: taeyoung --- packaging/deviced.spec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index a575b97..8ba2e11 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -26,11 +26,13 @@ %define haptic_module on %define led_module on %define telephony_module on +%define tzip_module on %endif %if "%{?profile}" == "wearable" %define battery_module on %define haptic_module on %define telephony_module on +%define tzip_module on %endif %if "%{?profile}" == "tv" %define block_module on -- 2.7.4 From 45d4c57f93be104318d1350f7e0df1a3b5d5446b Mon Sep 17 00:00:00 2001 From: taeyoung Date: Mon, 23 Nov 2015 16:02:57 +0900 Subject: [PATCH 06/16] usb: enable sdb at booting time - Currently, udev rule is used to detect usb cable and to enable sdb. However, usb cable is connected during booting, udevd cannot receive the kernel uevent and sdb cannot be enabled before re-connecting the usb cable. Thus sdb is enabled during booting time. Change-Id: I0c1bf4bb8fdc2bbf07df1b2f6fc4ba0973a64cab Signed-off-by: taeyoung --- packaging/deviced.spec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index a575b97..f11ea98 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -18,7 +18,7 @@ %define usbhost_module off #Just For debugging -%define sdb_prestart off +%define sdb_prestart on %if "%{?profile}" == "mobile" %define battery_module on @@ -34,6 +34,7 @@ %endif %if "%{?profile}" == "tv" %define block_module on +%define sdb_prestart off %endif Name: deviced -- 2.7.4 From 155b5ff67ec9e29b4b7ae7844c6098dc50a1ba53 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Mon, 23 Nov 2015 14:50:49 +0900 Subject: [PATCH 07/16] telephony: add tethering and flightmode handlers - tethering and flightmode should be handled for change or restrict services for that situation. Change-Id: Iaa5cb4a07328a16ddb6172d49b2a0eb262ce4b4a Signed-off-by: taeyoung --- src/telephony/telephony.c | 80 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 71 insertions(+), 9 deletions(-) diff --git a/src/telephony/telephony.c b/src/telephony/telephony.c index 2e02e90..e414708 100644 --- a/src/telephony/telephony.c +++ b/src/telephony/telephony.c @@ -31,6 +31,7 @@ #include "core/log.h" #include "core/common.h" #include "core/devices.h" +#include "core/device-notifier.h" #include "core/edbus-handler.h" #include "display/core.h" #include "power/power-handler.h" @@ -43,6 +44,49 @@ static TapiHandle *tapi_handle; static Ecore_Timer *poweroff_timer_id; +static int reboot_opt; + +int get_flight_mode(bool *mode) +{ + + return vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, (void *)mode); +} + +int set_flight_mode(bool mode) +{ + return vconf_set_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, mode); +} + +int get_mobile_hotspot_mode(int *mode) +{ + return vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, mode); +} + +static void flight_mode_changed(keynode_t *key_nodes, void *data) +{ + bool mode; + + if (key_nodes == NULL) { + _E("wrong parameter, key_nodes is null"); + return; + } + mode = vconf_keynode_get_bool(key_nodes); + + device_notify(DEVICE_NOTIFIER_FLIGHT_MODE, &mode); +} + +static void mobile_hotspot_mode_changed(keynode_t *key_nodes, void *data) +{ + int mode; + + if (key_nodes == NULL) { + _E("wrong parameter, key_nodes is null"); + return; + } + mode = vconf_keynode_get_int(key_nodes); + + device_notify(DEVICE_NOTIFIER_MOBILE_HOTSPOT_MODE, &mode); +} static Eina_Bool telephony_powerdown_ap_internal(void *data) { @@ -56,7 +100,7 @@ static void telephony_powerdown_ap(TapiHandle *handle, const char *noti_id, void static void telephony_restart_ap(TapiHandle *handle, const char *noti_id, void *data, void *user_data) { - restart_ap(data); + restart_ap(reboot_opt); } static Eina_Bool telephony_restart_ap_by_force(void *data) @@ -65,7 +109,7 @@ static Eina_Bool telephony_restart_ap_by_force(void *data) ecore_timer_del(poweroff_timer_id); poweroff_timer_id = NULL; } - restart_ap(data); + restart_ap(reboot_opt); return EINA_TRUE; } @@ -74,6 +118,11 @@ static void powerdown_res_cb(TapiHandle *handle, int result, void *data, void *u _D("poweroff command request : %d", result); } +static void restart_res_cb(TapiHandle *handle, int result, void *data, void *user_data) +{ + _D("restart command request : %d", result); +} + static Eina_Bool telephony_powerdown_ap_by_force(void *data) { if (poweroff_timer_id) { @@ -130,6 +179,12 @@ static void telephony_exit(void *data) return; } + vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, + flight_mode_changed); + + vconf_ignore_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE, + mobile_hotspot_mode_changed); + if (!strncmp(data, POWER_POWEROFF, POWER_POWEROFF_LEN)) { _I("Terminate"); ret = tel_register_noti_event(tapi_handle, TAPI_NOTI_MODEM_POWER, @@ -157,23 +212,24 @@ static void telephony_exit(void *data) } _I("Option: %s", data); + reboot_opt = SYSTEMD_STOP_POWER_RESTART; ret = tel_register_noti_event(tapi_handle, TAPI_NOTI_MODEM_POWER, telephony_restart_ap, NULL); if (ret != TAPI_API_SUCCESS) { _E("tel_register_event is not subscribed. error %d", ret); - telephony_restart_ap_by_force(NULL); + telephony_restart_ap_by_force((void *)reboot_opt); return; } ret = tel_process_power_command(tapi_handle, TAPI_PHONE_POWER_OFF, - powerdown_res_cb, NULL); + restart_res_cb, NULL); if (ret != TAPI_API_SUCCESS) { _E("tel_process_power_command() error %d", ret); - telephony_restart_ap_by_force(NULL); + telephony_restart_ap_by_force((void *)reboot_opt); return; } - poweroff_timer_id = ecore_timer_add(15,telephony_restart_ap_by_force, - NULL); + poweroff_timer_id = ecore_timer_add(15, telephony_restart_ap_by_force, + (void *)reboot_opt); } static void telephony_flight_mode_on(TapiHandle *handle, int result, void *data, void *user_data) @@ -186,7 +242,7 @@ static void telephony_flight_mode_on(TapiHandle *handle, int result, void *data, return; } _D("enter flight mode result : %d", result); - ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &bCurFlightMode); + ret = get_flight_mode(&bCurFlightMode); if (ret == 0) _D("Flight Mode is %d", bCurFlightMode); else @@ -203,7 +259,7 @@ static void telephony_flight_mode_off(TapiHandle *handle, int result, void *data return; } _D("leave flight mode result : %d", result); - ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &bCurFlightMode); + ret = get_flight_mode(&bCurFlightMode); if (ret == 0) _D("Flight Mode is %d", bCurFlightMode); else @@ -399,6 +455,12 @@ static void telephony_init(void *data) ARRAY_SIZE(edbus_methods)); if (ret < 0) _E("fail to init edbus method(%d)", ret); + + vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, + flight_mode_changed, NULL); + + vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE, + mobile_hotspot_mode_changed, NULL); } static const struct device_ops tel_device_ops = { -- 2.7.4 From a72ac9a0546af9803b0afdd9a37caa05a651608f Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Fri, 20 Nov 2015 16:16:54 +0900 Subject: [PATCH 08/16] haptic: Add function to vibrate with buffers and device handle. - Add function to vibrate with buffers beside vibrating monotone which is already existed. - Add device_handle. Change-Id: I575ff6710bf3f13b2c34a898d4ec04d11495c6a1 Signed-off-by: pr.jung --- src/haptic/haptic.c | 14 ++- src/haptic/standard.c | 316 ++++++++++++++++++++++++++++++++++++++---------- src/libdeviced/haptic.c | 112 +++++++++-------- 3 files changed, 319 insertions(+), 123 deletions(-) diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c index 9001a1e..83623a8 100644 --- a/src/haptic/haptic.c +++ b/src/haptic/haptic.c @@ -43,7 +43,7 @@ #define HARDKEY_VIB_ITERATION 1 #define HARDKEY_VIB_FEEDBACK 3 #define HARDKEY_VIB_PRIORITY 2 -#define HARDKEY_VIB_DURATION 300 +#define HARDKEY_VIB_DURATION 30 #define HAPTIC_FEEDBACK_STEP 20 #define DEFAULT_FEEDBACK_LEVEL 3 @@ -60,6 +60,7 @@ #endif #define CHECK_VALID_OPS(ops, r) ((ops) ? true : !(r = -ENODEV)) +#define RETRY_CNT 3 struct haptic_info { char *sender; @@ -79,6 +80,7 @@ static bool haptic_disabled; struct haptic_config { int level; int *level_arr; + int sound_capture; }; static struct haptic_config haptic_conf; @@ -689,7 +691,9 @@ static int parse_section(struct parse_result *result, void *user_data, int index if (!result->section || !result->name || !result->value) return 0; - if (MATCH(result->name, "level")) { + if (MATCH(result->name, "sound_capture")) { + conf->sound_capture = atoi(result->value); + } else if (MATCH(result->name, "level")) { conf->level = atoi(result->value); conf->level_arr = calloc(sizeof(int), conf->level); if (!conf->level_arr) { @@ -793,7 +797,8 @@ static void haptic_init(void *data) register_notifier(DEVICE_NOTIFIER_POWEROFF_HAPTIC, haptic_poweroff_cb); /* add watch for sound capturing value */ - vconf_notify_key_changed(VCONFKEY_RECORDER_STATE, sound_capturing_cb, NULL); + if (haptic_conf.sound_capture) + vconf_notify_key_changed(VCONFKEY_RECORDER_STATE, sound_capturing_cb, NULL); } static void haptic_exit(void *data) @@ -803,7 +808,8 @@ static void haptic_exit(void *data) int r; /* remove watch */ - vconf_ignore_key_changed(VCONFKEY_RECORDER_STATE, sound_capturing_cb); + if (haptic_conf.sound_capture) + vconf_ignore_key_changed(VCONFKEY_RECORDER_STATE, sound_capturing_cb); /* unregister notifier for below each event */ unregister_notifier(DEVICE_NOTIFIER_TOUCH_HARDKEY, haptic_hardkey_changed_cb); diff --git a/src/haptic/standard.c b/src/haptic/standard.c index d9435be..4171ba1 100644 --- a/src/haptic/standard.c +++ b/src/haptic/standard.c @@ -46,16 +46,62 @@ #define LONG(x) ((x)/BITS_PER_LONG) #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1) +#define MAX_DATA 16 +#define FF_INFO_MAGIC 0xDEADFEED + +struct ff_info_header { + unsigned int magic; + int iteration; + int ff_info_data_count; +}; + +struct ff_info_data { + int type;/* play, stop etc */ + int magnitude; /* strength */ + int length; /* in ms for stop, play*/ +}; + +struct ff_info_buffer { + struct ff_info_header header; + struct ff_info_data data[MAX_DATA]; +}; struct ff_info { - unsigned int id; + int handle; Ecore_Timer *timer; struct ff_effect effect; + struct ff_info_buffer *ffinfobuffer; + int currentindex; }; static int ff_fd; static dd_list *ff_list; +static dd_list *handle_list; static char ff_path[PATH_MAX]; +static int unique_number; + +struct ff_info *read_from_list(int handle) +{ + struct ff_info *temp; + dd_list *elem; + + DD_LIST_FOREACH(ff_list, elem, temp) { + if (temp->handle == handle) + return temp; + } + return NULL; +} + +/* for debug */ +static void print_list(void) +{ + struct ff_info *temp; + dd_list *elem; + int i = 0; + + DD_LIST_FOREACH(ff_list, elem, temp) + _D("[%d] %x", i++, temp); +} static bool check_valid_handle(struct ff_info *info) { @@ -72,10 +118,25 @@ static bool check_valid_handle(struct ff_info *info) return true; } +static bool check_fd(int *fd) +{ + int ffd; + + if (*fd > 0) + return true; + + ffd = open(ff_path, O_RDWR); + if (!ffd) + return false; + + *fd = ffd; + return true; +} + static int ff_stop(int fd, struct ff_effect *effect); static Eina_Bool timer_cb(void *data) { - struct ff_info *info = (struct ff_info*)data; + struct ff_info *info = (struct ff_info *)data; if (!info) return ECORE_CALLBACK_CANCEL; @@ -136,7 +197,7 @@ static int ff_find_device(void) if (test_bit(FF_RUMBLE, features)) _D("%s type : rumble", ev_path); - if (test_bit(FF_PERIODIC, features)) { + if (test_bit(FF_RUMBLE, features)) { memcpy(ff_path, ev_path, strlen(ev_path)); close(fd); closedir(dir); @@ -155,23 +216,13 @@ static int ff_init_effect(struct ff_effect *effect) if (!effect) return -EINVAL; - /* initialize member variables in effect struct */ - effect->type = FF_PERIODIC; + /*Only rumble supported as of now*/ + effect->type = FF_RUMBLE; + effect->replay.length = 0; + effect->replay.delay = 10; effect->id = -1; - effect->u.periodic.waveform = FF_SQUARE; - effect->u.periodic.period = 0.1*0x100; /* 0.1 second */ - effect->u.periodic.magnitude = 0; /* temporary value */ - effect->u.periodic.offset = 0; - effect->u.periodic.phase = 0; - effect->direction = 0x4000; /* Along X axis */ - effect->u.periodic.envelope.attack_length = 0; - effect->u.periodic.envelope.attack_level = 0; - effect->u.periodic.envelope.fade_length = 0; - effect->u.periodic.envelope.fade_level = 0; - effect->trigger.button = 0; - effect->trigger.interval = 0; - effect->replay.length = 0; /* temporary value */ - effect->replay.delay = 0; + effect->u.rumble.strong_magnitude = 0x100; + effect->u.rumble.weak_magnitude = 0x50; return 0; } @@ -198,21 +249,32 @@ static int ff_set_effect(struct ff_effect *effect, int length, int level) static int ff_play(int fd, struct ff_effect *effect) { struct input_event play; + int ret; - if (fd < 0 || !effect) + if (fd < 0 || !effect) { + if (fd < 0) + _E("fail to check fd"); + else + _E("fail to check effect"); return -EINVAL; + } /* upload an effect */ - if (ioctl(fd, EVIOCSFF, effect) == -1) + if (ioctl(fd, EVIOCSFF, effect) == -1) { + _E("fail to ioctl"); return -errno; + } /* play vibration*/ play.type = EV_FF; play.code = effect->id; play.value = 1; /* 1 : PLAY, 0 : STOP */ - if (write(fd, (const void*)&play, sizeof(play)) == -1) + ret = write(fd, (const void *)&play, sizeof(play)); + if (ret == -1) { + _E("fail to write"); return -errno; + } return 0; } @@ -220,6 +282,7 @@ static int ff_play(int fd, struct ff_effect *effect) static int ff_stop(int fd, struct ff_effect *effect) { struct input_event stop; + int ret; if (fd < 0) return -EINVAL; @@ -228,8 +291,8 @@ static int ff_stop(int fd, struct ff_effect *effect) stop.type = EV_FF; stop.code = effect->id; stop.value = 0; /* 1 : PLAY, 0 : STOP */ - - if (write(fd, (const void*)&stop, sizeof(stop)) == -1) + ret = write(fd, (const void *)&stop, sizeof(stop)); + if (ret == -1) return -errno; /* removing an effect from the device */ @@ -242,29 +305,6 @@ static int ff_stop(int fd, struct ff_effect *effect) return 0; } -static int create_unique_id(void) -{ - static int i = 0; - return i++; /* TODO: overflow */ -} - -static struct ff_info *get_element_from_list(int id) -{ - dd_list *elem; - struct ff_info *info; - - if (id < 0) - return NULL; - - /* find matched element */ - DD_LIST_FOREACH(ff_list, elem, info) { - if (info->id == id) - return info; - } - - return NULL; -} - /* START: Haptic Module APIs */ static int get_device_count(int *count) { @@ -279,6 +319,8 @@ static int open_device(int device_index, int *device_handle) { struct ff_info *info; int n; + bool found = false; + dd_list *elem; if (!device_handle) return -EINVAL; @@ -302,16 +344,26 @@ static int open_device(int device_index, int *device_handle) return -errno; } - /* create unique id */ - info->id = create_unique_id(); - /* initialize ff_effect structure */ ff_init_effect(&info->effect); + if (unique_number == INT_MAX) + unique_number = 0; + + while (found != true) { + ++unique_number; + elem = DD_LIST_FIND(handle_list, unique_number); + if (!elem) + found = true; + } + + info->handle = unique_number; + /* add info to local list */ DD_LIST_APPEND(ff_list, info); + DD_LIST_APPEND(handle_list, info->handle); - *device_handle = info->id; + *device_handle = info->handle; return 0; } @@ -320,10 +372,16 @@ static int close_device(int device_handle) struct ff_info *info; int r, n; - info = get_element_from_list(device_handle); + info = read_from_list(device_handle); if (!info) return -EINVAL; + if (!check_valid_handle(info)) + return -EINVAL; + + if (!check_fd(&ff_fd)) + return -ENODEV; + /* stop vibration */ r = ff_stop(ff_fd, &info->effect); if (r < 0) @@ -331,10 +389,14 @@ static int close_device(int device_handle) /* unregister existing timer */ if (r >= 0 && info->timer) { + _D("device handle %d is closed and timer deleted", device_handle); ecore_timer_del(info->timer); info->timer = NULL; } + DD_LIST_REMOVE(handle_list, info->handle); + + safe_free(info->ffinfobuffer); /* remove info from local list */ DD_LIST_REMOVE(ff_list, info); safe_free(info); @@ -356,15 +418,33 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p struct ff_info *info; int ret; - info = get_element_from_list(device_handle); - if (!info) + info = read_from_list(device_handle); + if (!info) { + _E("fail to check list"); + return -EINVAL; + } + + if (!check_valid_handle(info)) { + _E("fail to check handle"); return -EINVAL; + } + + if (!check_fd(&ff_fd)) + return -ENODEV; /* Zero(0) is the infinitely vibration value */ if (duration == HAPTIC_MODULE_DURATION_UNLIMITED) duration = 0; + /* unregister existing timer */ + if (info->timer) { + ff_stop(ff_fd, &info->effect); + ecore_timer_del(info->timer); + info->timer = NULL; + } + /* set effect as per arguments */ + ff_init_effect(&info->effect); ret = ff_set_effect(&info->effect, duration, feedback); if (ret < 0) { _E("failed to set effect(duration:%d, feedback:%d) : %d", @@ -375,17 +455,11 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p /* play effect as per arguments */ ret = ff_play(ff_fd, &info->effect); if (ret < 0) { - _E("failed to play haptic effect(id:%d) : %d", - info->effect.id, ret); + _E("failed to play haptic effect(fd:%d id:%d) : %d", + ff_fd, info->effect.id, ret); return ret; } - /* unregister existing timer */ - if (info->timer) { - ecore_timer_del(info->timer); - info->timer = NULL; - } - /* register timer */ if (duration) { info->timer = ecore_timer_add(duration/1000.f, timer_cb, info); @@ -393,17 +467,121 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p _E("Failed to add timer callback"); } - _D("effect id : %d", info->effect.id); + _D("device handle %d effect id : %d %dms", device_handle, info->effect.id, duration); if (effect_handle) *effect_handle = info->effect.id; return 0; } +static Eina_Bool _buffer_play(void *cbdata) +{ + struct ff_info *info = (struct ff_info *)cbdata; + struct ff_info_header *header = &info->ffinfobuffer->header; + struct ff_info_data *data = info->ffinfobuffer->data; + int index = info->currentindex; + int play_type = (index < header->ff_info_data_count) ? data[index].type : 0; + int length = (index < header->ff_info_data_count) ? data[index].length : 1; + int ret; + + ff_set_effect(&info->effect, length, 1); + if (play_type != 0) { + _D("Going to play for %d ms", length); + ret = ff_play(ff_fd, &info->effect); + if (ret < 0) + _D("Failed to play the effect %d", ret); + } else { + _D("Going to stop for %d ms", length); + ret = ff_stop(ff_fd, &info->effect); + if (ret < 0) + _D("Failed to stop the effect %d", ret); + } + + if (info->currentindex < header->ff_info_data_count) { + info->currentindex++; + info->timer = ecore_timer_add(length/1000.0f, _buffer_play, info); + } else { + --header->iteration; + if (header->iteration > 0) { + info->currentindex = 0; + info->timer = ecore_timer_add(0.0, _buffer_play, info); + } else + info->timer = NULL; + } + + return ECORE_CALLBACK_CANCEL; +} + +static void print_buffer(const unsigned char *vibe_buffer) +{ + struct ff_info_buffer fb; + int i = 0; + memcpy(&fb.header, vibe_buffer, sizeof(struct ff_info_header)); + memcpy(&fb.data, (unsigned char *)vibe_buffer+sizeof(struct ff_info_header), + sizeof(struct ff_info_data) * fb.header.ff_info_data_count); + _D("\nMagic %x\niteration %d\ncount %d\n", fb.header.magic, + fb.header.iteration, fb.header.ff_info_data_count); + + for (i = 0; i < fb.header.ff_info_data_count; i++) + _D("type %d\nmagn 0x%x\nlen %d\n", fb.data[i].type, + fb.data[i].magnitude, fb.data[i].length); +} + +static int vibrate_custom_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle) +{ + struct ff_info *info; + struct ff_info_header *header; + struct ff_info_data *data; + + info = read_from_list(device_handle); + if (!info) + return -EINVAL; + + if (!check_valid_handle(info)) + return -EINVAL; + + if (!check_fd(&ff_fd)) + return -ENODEV; + + if (!info->ffinfobuffer) + info->ffinfobuffer = (struct ff_info_buffer *)calloc(sizeof(struct ff_info_buffer), 1); + if (!info->ffinfobuffer) + return -ENOMEM; + + header = &info->ffinfobuffer->header; + data = info->ffinfobuffer->data; + + memcpy(header, vibe_buffer, sizeof(struct ff_info_header)); + if (header->ff_info_data_count < 0 || header->ff_info_data_count > MAX_DATA) + return -EINVAL; + + memcpy(data, vibe_buffer+sizeof(struct ff_info_header), sizeof(struct ff_info_data) * header->ff_info_data_count); + + info->currentindex = 0; + if (info->timer) + ecore_timer_del(info->timer); + + if (header->iteration > 0) + _buffer_play(info); + + return 0; +} + static int vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle) { - /* temporary code */ - return vibrate_monotone(device_handle, 300, feedback, priority, effect_handle); + int magic = 0; + + if (!device_handle) + return -EINVAL; + + if (vibe_buffer) + magic = *(int *)vibe_buffer; + + if (magic == FF_INFO_MAGIC) { + print_buffer(vibe_buffer); + return vibrate_custom_buffer(device_handle, vibe_buffer, iteration, feedback, priority, effect_handle); + } else + return vibrate_monotone(device_handle, 300, feedback, priority, effect_handle); } static int stop_device(int device_handle) @@ -411,10 +589,16 @@ static int stop_device(int device_handle) struct ff_info *info; int r; - info = get_element_from_list(device_handle); + info = read_from_list(device_handle); if (!info) return -EINVAL; + if (!check_valid_handle(info)) + return -EINVAL; + + if (!check_fd(&ff_fd)) + return -ENODEV; + /* stop effect */ r = ff_stop(ff_fd, &info->effect); if (r < 0) diff --git a/src/libdeviced/haptic.c b/src/libdeviced/haptic.c index 81c62e4..528b5d1 100644 --- a/src/libdeviced/haptic.c +++ b/src/libdeviced/haptic.c @@ -48,7 +48,7 @@ #define TEMP_BUFFER_SIZE (64*1024) /* START of Static Function Section */ -static unsigned char* convert_file_to_buffer(const char *file_name, int *size) +static unsigned char *convert_file_to_buffer(const char *file_name, int *size) { FILE *pf; long file_size; @@ -74,7 +74,7 @@ static unsigned char* convert_file_to_buffer(const char *file_name, int *size) if (file_size < 0) goto error; - pdata = (unsigned char*)malloc(file_size); + pdata = (unsigned char *)malloc(file_size); if (!pdata) goto error; @@ -141,12 +141,18 @@ static haptic_feedback_e convert_setting_to_module_level(void) return -1; switch (setting_fb_level) { - case SETTING_VIB_FEEDBACK_LEVEL0 : return HAPTIC_FEEDBACK_0; - case SETTING_VIB_FEEDBACK_LEVEL1 : return HAPTIC_FEEDBACK_1; - case SETTING_VIB_FEEDBACK_LEVEL2 : return HAPTIC_FEEDBACK_2; - case SETTING_VIB_FEEDBACK_LEVEL3 : return HAPTIC_FEEDBACK_3; - case SETTING_VIB_FEEDBACK_LEVEL4 : return HAPTIC_FEEDBACK_4; - case SETTING_VIB_FEEDBACK_LEVEL5 : return HAPTIC_FEEDBACK_5; + case SETTING_VIB_FEEDBACK_LEVEL0: + return HAPTIC_FEEDBACK_0; + case SETTING_VIB_FEEDBACK_LEVEL1: + return HAPTIC_FEEDBACK_1; + case SETTING_VIB_FEEDBACK_LEVEL2: + return HAPTIC_FEEDBACK_2; + case SETTING_VIB_FEEDBACK_LEVEL3: + return HAPTIC_FEEDBACK_3; + case SETTING_VIB_FEEDBACK_LEVEL4: + return HAPTIC_FEEDBACK_4; + case SETTING_VIB_FEEDBACK_LEVEL5: + return HAPTIC_FEEDBACK_5; default: break; } @@ -215,8 +221,8 @@ API int haptic_close(haptic_device_h device_handle) int ret; /* check if handle is valid */ - if (device_handle < 0) { - _E("Invalid parameter : device_handle(0)"); + if (device_handle == NULL) { + _E("Invalid parameter : device_handle"); return HAPTIC_ERROR_INVALID_PARAMETER; } @@ -243,10 +249,10 @@ API int haptic_vibrate_monotone(haptic_device_h device_handle, int duration, hap } API int haptic_vibrate_monotone_with_detail(haptic_device_h device_handle, - int duration, - haptic_feedback_e feedback, - haptic_priority_e priority, - haptic_effect_h *effect_handle) + int duration, + haptic_feedback_e feedback, + haptic_priority_e priority, + haptic_effect_h *effect_handle) { char str_handle[32]; char str_duration[32]; @@ -256,8 +262,8 @@ API int haptic_vibrate_monotone_with_detail(haptic_device_h device_handle, int ret; /* check if handle is valid */ - if (device_handle < 0) { - _E("Invalid parameter : device_handle(0)"); + if (device_handle == NULL) { + _E("Invalid parameter : device_handle"); return HAPTIC_ERROR_INVALID_PARAMETER; } @@ -297,7 +303,7 @@ API int haptic_vibrate_monotone_with_detail(haptic_device_h device_handle, if (ret < 0) return HAPTIC_ERROR_OPERATION_FAILED; - if (effect_handle) + if (effect_handle != NULL) *effect_handle = (haptic_effect_h)ret; return HAPTIC_ERROR_NONE; @@ -326,11 +332,11 @@ API int haptic_vibrate_file(haptic_device_h device_handle, const char *file_path } API int haptic_vibrate_file_with_detail(haptic_device_h device_handle, - const char *file_path, - haptic_iteration_e iteration, - haptic_feedback_e feedback, - haptic_priority_e priority, - haptic_effect_h *effect_handle) + const char *file_path, + haptic_iteration_e iteration, + haptic_feedback_e feedback, + haptic_priority_e priority, + haptic_effect_h *effect_handle) { char *vibe_buffer; int size, ret; @@ -364,11 +370,11 @@ API int haptic_vibrate_buffer(haptic_device_h device_handle, const unsigned char } API int haptic_vibrate_buffer_with_detail(haptic_device_h device_handle, - const unsigned char *vibe_buffer, - haptic_iteration_e iteration, - haptic_feedback_e feedback, - haptic_priority_e priority, - haptic_effect_h *effect_handle) + const unsigned char *vibe_buffer, + haptic_iteration_e iteration, + haptic_feedback_e feedback, + haptic_priority_e priority, + haptic_effect_h *effect_handle) { return haptic_vibrate_buffers_with_detail(device_handle, vibe_buffer, @@ -394,12 +400,12 @@ API int haptic_vibrate_buffers(haptic_device_h device_handle, } API int haptic_vibrate_buffers_with_detail(haptic_device_h device_handle, - const unsigned char *vibe_buffer, - int size, - haptic_iteration_e iteration, - haptic_feedback_e feedback, - haptic_priority_e priority, - haptic_effect_h *effect_handle) + const unsigned char *vibe_buffer, + int size, + haptic_iteration_e iteration, + haptic_feedback_e feedback, + haptic_priority_e priority, + haptic_effect_h *effect_handle) { char str_handle[32]; char str_iteration[32]; @@ -410,8 +416,8 @@ API int haptic_vibrate_buffers_with_detail(haptic_device_h device_handle, int ret; /* check if handle is valid */ - if (device_handle < 0) { - _E("Invalid parameter : device_handle(0)"); + if (device_handle == NULL) { + _E("Invalid parameter : device_handle"); return HAPTIC_ERROR_INVALID_PARAMETER; } @@ -444,7 +450,7 @@ API int haptic_vibrate_buffers_with_detail(haptic_device_h device_handle, arr[0] = str_handle; bytes.size = size; bytes.data = vibe_buffer; - arr[2] = (char*)&bytes; + arr[2] = (char *)&bytes; snprintf(str_iteration, sizeof(str_iteration), "%d", iteration); arr[3] = str_iteration; snprintf(str_feedback, sizeof(str_feedback), "%d", feedback); @@ -459,7 +465,7 @@ API int haptic_vibrate_buffers_with_detail(haptic_device_h device_handle, if (ret < 0) return HAPTIC_ERROR_OPERATION_FAILED; - if (effect_handle >= 0) + if (effect_handle != NULL) *effect_handle = (haptic_effect_h)ret; return HAPTIC_ERROR_NONE; @@ -477,8 +483,8 @@ API int haptic_stop_all_effects(haptic_device_h device_handle) int ret; /* check if handle is valid */ - if (device_handle < 0) { - _E("Invalid parameter : device_handle(0)"); + if (device_handle == NULL) { + _E("Invalid parameter : device_handle"); return HAPTIC_ERROR_INVALID_PARAMETER; } @@ -502,8 +508,8 @@ API int haptic_get_effect_state(haptic_device_h device_handle, haptic_effect_h e int ret; /* check if handle is valid */ - if (device_handle < 0) { - _E("Invalid parameter : device_handle(0)"); + if (device_handle == NULL) { + _E("Invalid parameter : device_handle"); return HAPTIC_ERROR_INVALID_PARAMETER; } @@ -528,9 +534,9 @@ API int haptic_get_effect_state(haptic_device_h device_handle, haptic_effect_h e } API int haptic_create_effect(unsigned char *vibe_buffer, - int max_bufsize, - haptic_effect_element_s *elem_arr, - int max_elemcnt) + int max_bufsize, + haptic_effect_element_s *elem_arr, + int max_elemcnt) { DBusError err; DBusMessage *msg; @@ -574,8 +580,8 @@ API int haptic_create_effect(unsigned char *vibe_buffer, snprintf(str_bufsize, sizeof(str_bufsize), "%d", max_bufsize); arr[0] = str_bufsize; bytes.size = sizeof(haptic_effect_element_s)*max_elemcnt; - bytes.data = (unsigned char*)elem_arr; - arr[2] = (char*)&bytes; + bytes.data = (unsigned char *)elem_arr; + arr[2] = (char *)&bytes; snprintf(str_elemcnt, sizeof(str_elemcnt), "%d", max_elemcnt); arr[3] = str_elemcnt; @@ -615,8 +621,8 @@ err: } API int haptic_save_effect(const unsigned char *vibe_buffer, - int max_bufsize, - const char *file_path) + int max_bufsize, + const char *file_path) { struct stat buf; int size, ret; @@ -688,8 +694,8 @@ API int haptic_get_buffers_duration(haptic_device_h device_handle, const unsigne int ret; /* check if handle is valid */ - if (device_handle < 0) { - _E("Invalid parameter : device_handle(0)"); + if (device_handle == NULL) { + _E("Invalid parameter : device_handle"); return HAPTIC_ERROR_INVALID_PARAMETER; } @@ -708,7 +714,7 @@ API int haptic_get_buffers_duration(haptic_device_h device_handle, const unsigne arr[0] = str_handle; bytes.size = size; bytes.data = vibe_buffer; - arr[2] = (char*)&bytes; + arr[2] = (char *)&bytes; /* request to deviced to open haptic device */ ret = dbus_method_sync(DEVICED_BUS_NAME, @@ -753,8 +759,8 @@ API int haptic_save_led(const unsigned char *vibe_buffer, int max_bufsize, const bytes.size = max_bufsize; bytes.data = vibe_buffer; - arr[1] = (char*)&bytes; - arr[2] = (char*)file_path; + arr[1] = (char *)&bytes; + arr[2] = (char *)file_path; /* request to deviced to open haptic device */ ret = dbus_method_sync(DEVICED_BUS_NAME, -- 2.7.4 From 0fd89dc816cdcd444eed37f108b059ca22a94887 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Fri, 20 Nov 2015 16:47:11 +0900 Subject: [PATCH 09/16] haptic: Remove strerror, readdir usecase which are not thread-safe. Change-Id: I99e6577fbb1ef095ad5437ca0ceeabb15b3918d4 Signed-off-by: pr.jung --- src/haptic/standard.c | 11 ++++++++--- src/libdeviced/haptic.c | 13 ++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/haptic/standard.c b/src/haptic/standard.c index 4171ba1..c43b130 100644 --- a/src/haptic/standard.c +++ b/src/haptic/standard.c @@ -158,6 +158,7 @@ static Eina_Bool timer_cb(void *data) static int ff_find_device(void) { DIR *dir; + struct dirent entry; struct dirent *dent; char ev_path[PATH_MAX]; unsigned long features[1+FF_MAX/sizeof(unsigned long)]; @@ -167,7 +168,11 @@ static int ff_find_device(void) if (!dir) return -errno; - while ((dent = readdir(dir))) { + while (1) { + ret = readdir_r(dir, &entry, &dent); + if (ret != 0 || dent == NULL) + break; + if (dent->d_type == DT_DIR || !strstr(dent->d_name, "event")) continue; @@ -332,7 +337,7 @@ static int open_device(int device_index, int *device_handle) /* open ff driver */ ff_fd = open(ff_path, O_RDWR); if (!ff_fd) { - _E("Failed to open %s : %s", ff_path, strerror(errno)); + _E("Failed to open %s : %d", ff_path, errno); return -errno; } } @@ -340,7 +345,7 @@ static int open_device(int device_index, int *device_handle) /* allocate memory */ info = calloc(sizeof(struct ff_info), 1); if (!info) { - _E("Failed to allocate memory : %s", strerror(errno)); + _E("Failed to allocate memory : %d", errno); return -errno; } diff --git a/src/libdeviced/haptic.c b/src/libdeviced/haptic.c index 528b5d1..255ae9d 100644 --- a/src/libdeviced/haptic.c +++ b/src/libdeviced/haptic.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -60,7 +59,7 @@ static unsigned char *convert_file_to_buffer(const char *file_name, int *size) /* Get File Stream Pointer */ pf = fopen(file_name, "rb"); if (!pf) { - _E("fopen failed : %s", strerror(errno)); + _E("fopen failed : %d", errno); return NULL; } @@ -91,7 +90,7 @@ err_free: error: fclose(pf); - _E("failed to convert file to buffer (%s)", strerror(errno)); + _E("failed to convert file to buffer (%d)", errno); return NULL; } @@ -102,25 +101,25 @@ static int save_data(const unsigned char *data, int size, const char *file_path) file = fopen(file_path, "wb+"); if (file == NULL) { - _E("To open file is failed : %s", strerror(errno)); + _E("To open file is failed : %d", errno); return -1; } if (fwrite(data, 1, size, file) != size) { - _E("To write file is failed : %s", strerror(errno)); + _E("To write file is failed : %d", errno); fclose(file); return -1; } fd = fileno(file); if (fd < 0) { - _E("To get file descriptor is failed : %s", strerror(errno)); + _E("To get file descriptor is failed : %d", errno); fclose(file); return -1; } if (fsync(fd) < 0) { - _E("To be synchronized with the disk is failed : %s", strerror(errno)); + _E("To be synchronized with the disk is failed : %d", errno); fclose(file); return -1; } -- 2.7.4 From f6365f4a5fbd3650735da62b5cae9798c83d87ef Mon Sep 17 00:00:00 2001 From: taeyoung Date: Tue, 24 Nov 2015 11:09:14 +0900 Subject: [PATCH 10/16] storage: monitor storage size available - If storage size available is not enough to use, warning message is shown to user Change-Id: Ibfea8a29b18ccda7e228a1e0c8e81bb6512936ee Signed-off-by: taeyoung --- CMakeLists.txt | 12 ++ packaging/deviced.spec | 8 + src/storage/storage.c | 411 +++++++++++++++++++++++-------------------------- 3 files changed, 216 insertions(+), 215 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 99bb3c9..ee15efa 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,11 @@ IF(LED_MODULE STREQUAL on) SET(SRCS ${SRCS} ${LED_SRCS}) ENDIF() +IF(STORAGE_MODULE STREQUAL on) + ADD_SOURCE(src/storage STORAGE_SRCS) + SET(SRCS ${SRCS} ${STORAGE_SRCS}) +ENDIF() + IF(TZIP_MODULE STREQUAL on) ADD_SOURCE(src/tzip TZIP_SRCS) SET(SRCS ${SRCS} ${TZIP_SRCS}) @@ -156,6 +161,9 @@ IF(DISPLAY_MODULE STREQUAL on) ENDIF() SET(PKG_MODULES ${PKG_MODULES} libinput sensor) ENDIF() +IF(STORAGE_MODULE STREQUAL on) + SET(PKG_MODULES ${PKG_MODULES} storage) +ENDIF() IF(TELEPHONY_MODULE STREQUAL on) SET(PKG_MODULES ${PKG_MODULES} tapi) ENDIF() @@ -204,6 +212,10 @@ IF(BLOCK_MODULE STREQUAL on) INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/mmc-smack-label DESTINATION bin) ENDIF() +IF(STORAGE_MODULE STREQUAL on) + INSTALL_CONF(src/storage storage) +ENDIF() + # USB connection IF(${USB_MODULE} STREQUAL on) INSTALL_CONF(src/usb usb-setting) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index f37de51..ef29bfb 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -12,6 +12,7 @@ %define haptic_module off %define led_module off %define power_module on +%define storage_module on %define telephony_module off %define tzip_module off %define usb_module on @@ -77,6 +78,9 @@ BuildRequires: pkgconfig(xext) BuildRequires: pkgconfig(libinput) BuildRequires: pkgconfig(sensor) %endif +%if %{?storage_module} == on +BuildRequires: pkgconfig(storage) +%endif %if %{?telephony_module} == on BuildRequires: pkgconfig(tapi) %endif @@ -241,6 +245,7 @@ Haptic Device manager library for device control (devel) -DHAPTIC_MODULE=%{haptic_module} \ -DLED_MODULE=%{led_module} \ -DPOWER_MODULE=%{power_module} \ + -DSTORAGE_MODULE=%{storage_module} \ -DTELEPHONY_MODULE=%{telephony_module} \ -DTZIP_MODULE=%{tzip_module} \ -DUSB_MODULE=%{usb_module} \ @@ -336,6 +341,9 @@ systemctl daemon-reload %{_datadir}/license/newfs_msdos %config %{_sysconfdir}/deviced/block.conf %endif +%if %{?storage_module} == on +%config %{_sysconfdir}/deviced/storage.conf +%endif %if %{?usb_module} == on %config %{_sysconfdir}/deviced/usb-setting.conf %config %{_sysconfdir}/deviced/usb-operation.conf diff --git a/src/storage/storage.c b/src/storage/storage.c index 2d772e7..97d47ec 100755 --- a/src/storage/storage.c +++ b/src/storage/storage.c @@ -35,36 +35,21 @@ #include "core/edbus-handler.h" #include "core/device-notifier.h" #include "core/config-parser.h" +#include "apps/apps.h" -#define MEMNOTIFY_NORMAL 0x0000 -#define MEMNOTIFY_LOW 0xfaac -#define MEMNOTIFY_CRITICAL 0xdead -#define MEMNOTIFY_REBOOT 0xb00f +#define MEMORY_STATUS_TMP_PATH "/tmp" +#define MEMNOTI_TMP_CRITICAL_VALUE (20) #define MEMORY_STATUS_USR_PATH "/opt/usr" #define MEMORY_MEGABYTE_VALUE 1048576 -#define MEMNOTI_WARNING_VALUE (5) // 5% under -#define MEMNOTI_CRITICAL_VALUE (0.1) // 0.1% under -#define MEMNOTI_FULL_VALUE (0.0) // 0.0% under +#define MEMNOTI_WARNING_VALUE (5) /* 5% under */ +#define MEMNOTI_CRITICAL_VALUE (0.1) /* 0.1% under */ +#define MEMNOTI_FULL_VALUE (0.0) /* 0.0% under */ #define SIGNAL_LOWMEM_STATE "ChangeState" #define SIGNAL_LOWMEM_FULL "Full" - -#define POPUP_KEY_MEMNOTI "_MEM_NOTI_" -#define POPUP_KEY_APPNAME "_APP_NAME_" - -#define LOWMEM_POPUP_NAME "lowmem-syspopup" - #define MEMNOTI_TIMER_INTERVAL 5 -#define MEM_TRIM_TIMER_INTERVAL 86400 /* 24 hour */ -#define MEM_FSTRIM_PATH "/sbin/fstrim" - -#define MEM_TRIM_START_TIME 2 // AM 02:00:00 -#define MIN_SEC (60) -#define HOUR_SEC (MIN_SEC * MIN_SEC) - -#define BUF_MAX 1024 #define STORAGE_CONF_FILE "/etc/deviced/storage.conf" @@ -72,223 +57,204 @@ enum memnoti_level { MEMNOTI_LEVEL_CRITICAL = 0, MEMNOTI_LEVEL_WARNING, MEMNOTI_LEVEL_NORMAL, -} ; + MEMNOTI_LEVEL_FULL, +}; + +enum memnoti_status { + MEMNOTI_DISABLE, + MEMNOTI_ENABLE, +}; struct storage_config_info { + enum memnoti_level current_noti_level; double warning_level; double critical_level; double full_level; }; -static Ecore_Fd_Handler *lowmem_efd = NULL; -static int lowmem_fd; -static int cur_mem_state = MEMNOTIFY_NORMAL; +static Ecore_Timer *memnoti_timer; -static Ecore_Timer *memnoti_timer = NULL; -static Ecore_Timer *mem_trim_timer = NULL; +static struct storage_config_info storage_internal_info = { + .current_noti_level = MEMNOTI_LEVEL_NORMAL, + .warning_level = MEMNOTI_WARNING_VALUE, + .critical_level = MEMNOTI_CRITICAL_VALUE, + .full_level = MEMNOTI_FULL_VALUE, +}; -static struct storage_config_info storage_info = { - .warning_level = MEMNOTI_WARNING_VALUE, - .critical_level = MEMNOTI_CRITICAL_VALUE, - .full_level = MEMNOTI_FULL_VALUE, +static struct storage_config_info storage_tmp_info = { + .current_noti_level = MEMNOTI_LEVEL_NORMAL, + .warning_level = MEMNOTI_TMP_CRITICAL_VALUE, + .critical_level = MEMNOTI_TMP_CRITICAL_VALUE, + .full_level = MEMNOTI_FULL_VALUE, }; -static void memnoti_send_broadcast(int status) +static void memnoti_send_broadcast(char *signal, int status) { - static int old = 0; char *arr[1]; char str_status[32]; - if (old == status) - return; - - old = status; + _I("signal %s status %d", signal, status); snprintf(str_status, sizeof(str_status), "%d", status); arr[0] = str_status; broadcast_edbus_signal(DEVICED_PATH_LOWMEM, DEVICED_INTERFACE_LOWMEM, - SIGNAL_LOWMEM_STATE, "i", arr); -} - -static void memnoti_level_broadcast(enum memnoti_level level) -{ - static int status = 0; - if (level == MEMNOTI_LEVEL_CRITICAL && status == 0) - status = 1; - else if (level != MEMNOTI_LEVEL_CRITICAL && status == 1) - status = 0; - else - return; - _D("send user mem noti : %d %d", level, status); - memnoti_send_broadcast(status); + signal, "i", arr); } static int memnoti_popup(enum memnoti_level level) { int ret = -1; + int val = -1; char *value = NULL; if (level != MEMNOTI_LEVEL_WARNING && level != MEMNOTI_LEVEL_CRITICAL) { - _E("level check error : %d",level); + _E("level check error : %d", level); return 0; } - if (level == MEMNOTI_LEVEL_WARNING) { - value = "Warning"; - } else if (level == MEMNOTI_LEVEL_CRITICAL) { - value = "Critical"; + if (level == MEMNOTI_LEVEL_WARNING) + value = "lowstorage_warning"; + else if (level == MEMNOTI_LEVEL_CRITICAL) + value = "lowstorage_critical"; + + ret = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &val); + if (val == 0 || ret != 0) + goto out; + + if (value) { + ret = launch_system_app(APP_DEFAULT, + 2, APP_KEY_TYPE, value); + if (ret < 0) + _E("Failed to launch (%s) popup", value); } - ret = manage_notification("Low memory", value); - if (ret == -1) - return -1; return 0; +out: + return -1; } -static enum memnoti_level check_memnoti_level(double total, double avail) +static void storage_status_broadcast(struct storage_config_info *info, double total, double avail) { - double tmp_size = (avail/total)*100; + double level = (avail/total)*100; + int status = MEMNOTI_DISABLE; + + if (level <= info->full_level) { + if (info->current_noti_level == MEMNOTI_LEVEL_FULL) + return; + info->current_noti_level = MEMNOTI_LEVEL_FULL; + status = MEMNOTI_ENABLE; + memnoti_send_broadcast(SIGNAL_LOWMEM_FULL, status); + return; + } + + if (level <= info->critical_level) { + if (info->current_noti_level == MEMNOTI_LEVEL_CRITICAL) + return; + if (info->current_noti_level == MEMNOTI_LEVEL_FULL) + memnoti_send_broadcast(SIGNAL_LOWMEM_FULL, status); + info->current_noti_level = MEMNOTI_LEVEL_CRITICAL; + status = MEMNOTI_ENABLE; + memnoti_send_broadcast(SIGNAL_LOWMEM_STATE, status); + return; + } - if (tmp_size > storage_info.warning_level) - return MEMNOTI_LEVEL_NORMAL; - if (tmp_size > storage_info.critical_level) - return MEMNOTI_LEVEL_WARNING; - return MEMNOTI_LEVEL_CRITICAL; + if (info->current_noti_level == MEMNOTI_LEVEL_FULL) + memnoti_send_broadcast(SIGNAL_LOWMEM_FULL, status); + if (info->current_noti_level == MEMNOTI_LEVEL_CRITICAL) + memnoti_send_broadcast(SIGNAL_LOWMEM_STATE, status); + if (level <= info->warning_level) + info->current_noti_level = MEMNOTI_LEVEL_WARNING; + else + info->current_noti_level = MEMNOTI_LEVEL_NORMAL; } -static void memnoti_full_broadcast(double total, double avail) +static int storage_get_memory_size(char *path, struct statvfs *s) { - static int status = 0; - int tmp = 0; - double tmp_size = (avail/total)*100; - char *arr[1]; - char str_status[32]; + int ret; - tmp = status; - if (tmp_size <= storage_info.full_level && status == 0) - status = 1; - else if (tmp_size > storage_info.full_level && status == 1) - status = 0; - if (status == tmp) - return; + if (!path) { + _E("input param error"); + return -EINVAL; + } - _D("send memory full noti : %d (total: %4.4lf avail: %4.4lf)", status, total, avail); - snprintf(str_status, sizeof(str_status), "%d", status); - arr[0] = str_status; - broadcast_edbus_signal(DEVICED_PATH_LOWMEM, DEVICED_INTERFACE_LOWMEM, - SIGNAL_LOWMEM_FULL, "i", arr); + ret = statvfs(path, s); + if (ret) { + _E("fail to get storage size"); + return -errno; + } + + return 0; +} + +static void get_storage_status(char *path, struct statvfs *s) +{ + if (strcmp(path, MEMORY_STATUS_USR_PATH) == 0) + storage_get_internal_memory_size(s); + else + storage_get_memory_size(path, s); } -static void memory_status_set_full_mem_size(void) +static void init_storage_config_info(char *path, struct storage_config_info *info) { struct statvfs s; - double dTotal = 0.0; double dAvail = 0.0; + double dTotal = 0.0; - storage_get_internal_memory_size(&s); - dTotal = (double)s.f_frsize * s.f_blocks; - dAvail = (double)s.f_bsize * s.f_bavail; + get_storage_status(path, &s); - storage_info.full_level += (MEMORY_MEGABYTE_VALUE/dTotal)*100; - _I("full : %4.4lf avail : %4.4lf warning : %4.4lf critical : %4.4lf", - storage_info.full_level, (dAvail*100/dTotal), - storage_info.warning_level, storage_info.critical_level); + dTotal = (double)(s.f_frsize * s.f_blocks); + dAvail = (double)(s.f_bsize * s.f_bavail); + + info->full_level += (MEMORY_MEGABYTE_VALUE/dTotal)*100; + + _I("%s t: %4.0lf a: %4.0lf(%4.2lf) c:%4.4lf f:%4.4lf", + path, dTotal, dAvail, (dAvail*100/dTotal), info->critical_level, info->full_level); } -static Eina_Bool memory_status_get_available_size(void *data) +static void check_internal_storage_popup(struct storage_config_info *info) { static enum memnoti_level old = MEMNOTI_LEVEL_NORMAL; - enum memnoti_level now; int ret; + + if (info->current_noti_level < MEMNOTI_LEVEL_NORMAL && info->current_noti_level < old) { + ret = memnoti_popup(info->current_noti_level); + if (ret != 0) + info->current_noti_level = MEMNOTI_LEVEL_NORMAL; + } + old = info->current_noti_level; +} + +static Eina_Bool check_storage_status(void *data) +{ struct statvfs s; double dAvail = 0.0; double dTotal = 0.0; + /* check internal */ storage_get_internal_memory_size(&s); dTotal = (double)s.f_frsize * s.f_blocks; dAvail = (double)s.f_bsize * s.f_bavail; + storage_status_broadcast(&storage_internal_info, dTotal, dAvail); + check_internal_storage_popup(&storage_internal_info); + /* check tmp */ + storage_get_memory_size(MEMORY_STATUS_TMP_PATH, &s); + dTotal = (double)s.f_frsize * s.f_blocks; + dAvail = (double)s.f_bsize * s.f_bavail; + storage_status_broadcast(&storage_tmp_info, dTotal, dAvail); - memnoti_full_broadcast(dTotal, dAvail); - - now = check_memnoti_level(dTotal, dAvail); - - memnoti_level_broadcast(now); - - if (now < MEMNOTI_LEVEL_NORMAL && now < old) { - ret = memnoti_popup(now); - if (ret != 0) - now = MEMNOTI_LEVEL_NORMAL; - } - old = now; if (memnoti_timer) ecore_timer_interval_set(memnoti_timer, MEMNOTI_TIMER_INTERVAL); -out: + return EINA_TRUE; } -static int __memnoti_fd_init(void) +static int init_storage_config_info_all(void) { - memory_status_set_full_mem_size(); - memory_status_get_available_size(NULL); + init_storage_config_info(MEMORY_STATUS_USR_PATH, &storage_internal_info); + init_storage_config_info(MEMORY_STATUS_TMP_PATH, &storage_tmp_info); memnoti_timer = ecore_timer_add(MEMNOTI_TIMER_INTERVAL, - memory_status_get_available_size, NULL); + check_storage_status, NULL); if (memnoti_timer == NULL) - _E("fail mem available noti timer add"); - return 0; -} - -static Eina_Bool memory_trim_cb(void *data) -{ - ecore_timer_interval_set(memnoti_timer, MEM_TRIM_TIMER_INTERVAL); - if (launch_if_noexist(MEM_FSTRIM_PATH, MEMORY_STATUS_USR_PATH) == -1) { - _E("fail to launch fstrim"); - } else { - _D("fs memory trim is operated"); - } - return EINA_TRUE; -} - -static int __mem_trim_delta(struct tm *cur_tm) -{ - int delta = 0; - int sign_val; - - if (cur_tm->tm_hour < MEM_TRIM_START_TIME) - sign_val = 1; - else - sign_val = -1; - delta += ((sign_val) * (MEM_TRIM_START_TIME - cur_tm->tm_hour) * HOUR_SEC); - delta -= ((sign_val) * (cur_tm->tm_min * MIN_SEC + cur_tm->tm_sec)); - return delta; -} - -static int __run_mem_trim(void) -{ - time_t now; - struct tm *cur_tm; - int mem_trim_time; - - now = time(NULL); - cur_tm = (struct tm *)malloc(sizeof(struct tm)); - if (cur_tm == NULL) { - _E("Fail to memory allocation"); - return -1; - } - - if (localtime_r(&now, cur_tm) == NULL) { - _E("Fail to get localtime"); - free(cur_tm); - return -1; - } - - mem_trim_time = MEM_TRIM_TIMER_INTERVAL + __mem_trim_delta(cur_tm); - _D("start mem trim timer", mem_trim_time); - mem_trim_timer = ecore_timer_add(mem_trim_time, memory_trim_cb, NULL); - if (mem_trim_timer == NULL) { - _E("Fail to add mem trim timer"); - free(cur_tm); - return -1; - } - free(cur_tm); + _E("fail mem available noti timer add"); return 0; } @@ -296,71 +262,88 @@ static DBusMessage *edbus_getstatus(E_DBus_Object *obj, DBusMessage *msg) { DBusMessageIter iter; DBusMessage *reply; - int ret; struct statvfs s; - double dAvail = 0.0; - double dTotal = 0.0; + unsigned long long dAvail = 0.0; + unsigned long long dTotal = 0.0; storage_get_internal_memory_size(&s); - dTotal = (double)s.f_frsize * s.f_blocks; - dAvail = (double)s.f_bsize * s.f_bavail; + dTotal = (unsigned long long)s.f_frsize * s.f_blocks; + dAvail = (unsigned long long)s.f_bsize * s.f_bavail; reply = dbus_message_new_method_return(msg); dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT64, &dTotal); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT64, &dAvail); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT64, &dTotal); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT64, &dAvail); return reply; } -static DBusMessage *edbus_memtrim(E_DBus_Object *obj, DBusMessage *msg) +static DBusMessage *edbus_get_storage_status(E_DBus_Object *obj, DBusMessage *msg) { DBusMessageIter iter; DBusMessage *reply; - int ret; - - ret = launch_if_noexist(MEM_FSTRIM_PATH, MEMORY_STATUS_USR_PATH); - if (ret == -1) { - _E("fail to launch fstrim"); - } else { - _D("fs memory trim is operated"); + DBusError err; + char *path; + struct statvfs s; + pid_t pid; + unsigned long long dAvail = 0.0; + unsigned long long dTotal = 0.0; + + dbus_error_init(&err); + if (!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID)) { + _E("Bad message: [%s:%s]", err.name, err.message); + dbus_error_free(&err); + goto out; } + if (!strcmp(path, MEMORY_STATUS_USR_PATH)) + storage_get_internal_memory_size(&s); + else + storage_get_memory_size(path, &s); + + dTotal = (unsigned long long)s.f_frsize * s.f_blocks; + dAvail = (unsigned long long)s.f_bsize * s.f_bavail; + + pid = get_edbus_sender_pid(msg); + + _D("[request %d] path %s total %4.0lf avail %4.0lf", pid, path, dTotal, dAvail); + +out: reply = dbus_message_new_method_return(msg); dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT64, &dTotal); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT64, &dAvail); return reply; } static const struct edbus_method edbus_methods[] = { - { "getstorage", NULL, "i", edbus_getstatus }, - { "MemTrim", NULL, "i", edbus_memtrim }, + { "getstorage", NULL, "tt", edbus_getstatus }, + { "GetStatus", "s", "tt", edbus_get_storage_status}, /* Add methods here */ }; static int booting_done(void *data) { - static int done = 0; - - if (data != NULL) { - done = *(int*)data; - if (done) - _I("booting done"); - if (__memnoti_fd_init() == -1) - _E("fail remain mem noti control fd init"); - } + static int done; + + if (data == NULL) + return done; + done = *(int *)data; + if (done == 0) + return done; + + _I("booting done"); + + if (init_storage_config_info_all() == -1) + _E("fail remain mem noti control fd init"); return done; } -static int lowmem_poweroff(void *data) +static int storage_poweroff(void *data) { if (memnoti_timer) { ecore_timer_del(memnoti_timer); memnoti_timer = NULL; } - if (mem_trim_timer) { - ecore_timer_del(mem_trim_timer); - mem_trim_timer = NULL; - } return 0; } @@ -376,6 +359,8 @@ static int load_config(struct parse_result *result, void *user_data) if (!MATCH(result->section, "LOWSTORAGE")) return -EINVAL; + _D("%s,%s,%s", result->section, result->name, result->value); + name = result->name; value = result->value; @@ -398,32 +383,28 @@ static void storage_config_load(struct storage_config_info *info) _E("Failed to load %s, %d Use default value!", STORAGE_CONF_FILE, ret); } -static void lowmem_init(void *data) +static void storage_init(void *data) { int ret; - storage_config_load(&storage_info); + storage_config_load(&storage_internal_info); register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); - register_notifier(DEVICE_NOTIFIER_POWEROFF, lowmem_poweroff); + register_notifier(DEVICE_NOTIFIER_POWEROFF, storage_poweroff); ret = register_edbus_method(DEVICED_PATH_STORAGE, edbus_methods, ARRAY_SIZE(edbus_methods)); if (ret < 0) _E("fail to init edbus method(%d)", ret); - - if (__run_mem_trim() < 0) { - _E("fail mem trim timer start"); - } } -static void lowmem_exit(void *data) +static void storage_exit(void *data) { unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); - unregister_notifier(DEVICE_NOTIFIER_POWEROFF, lowmem_poweroff); + unregister_notifier(DEVICE_NOTIFIER_POWEROFF, storage_poweroff); } -static const struct device_ops lowmem_device_ops = { - .name = "lowmem", - .init = lowmem_init, - .exit = lowmem_exit, +static const struct device_ops storage_device_ops = { + .name = "storage", + .init = storage_init, + .exit = storage_exit, }; -DEVICE_OPS_REGISTER(&lowmem_device_ops) +DEVICE_OPS_REGISTER(&storage_device_ops) -- 2.7.4 From e83f2ed425091cf3272ed6ce98186ba683fb35ae Mon Sep 17 00:00:00 2001 From: taeyoung Date: Tue, 24 Nov 2015 11:32:09 +0900 Subject: [PATCH 11/16] systemd: add dbus method calls for systemd related operation - start and stop services are available by dbus method Change-Id: I979c262643c85f4c92f0e6bc6d4d5eea73295973 Signed-off-by: taeyoung --- src/shared/CMakeLists.txt | 1 + src/shared/deviced-systemd.c | 417 +++++++++++++++++++++++++++++++++++++++++++ src/shared/deviced-systemd.h | 51 ++++++ 3 files changed, 469 insertions(+) create mode 100644 src/shared/deviced-systemd.c create mode 100644 src/shared/deviced-systemd.h diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index f318e5a..4b77b74 100755 --- a/src/shared/CMakeLists.txt +++ b/src/shared/CMakeLists.txt @@ -2,6 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) SET(SHARED_SRCS dbus.c + deviced-systemd.c ) INCLUDE(FindPkgConfig) diff --git a/src/shared/deviced-systemd.c b/src/shared/deviced-systemd.c new file mode 100644 index 0000000..13b345e --- /dev/null +++ b/src/shared/deviced-systemd.c @@ -0,0 +1,417 @@ +/* + * 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 "dbus.h" + +#include "core/log.h" + + +#define DBUS_IFACE_DBUS_PROPERTIES DBUS_SERVICE_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/" + +#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) +{ + int ret; + GVariant *reply = NULL; + + _I("Starting: %s %s", method, name); + ret = deviced_systemd_proxy_call_sync(SYSTEMD_DBUS_DEST, + SYSTEMD_DBUS_PATH, + SYSTEMD_DBUS_IFACE_MANAGER, + method, + g_variant_new("(ss)", + name, + "replace"), + &reply); + if (ret < 0) + goto finish; + + if (!g_variant_is_of_type(reply, G_VARIANT_TYPE("(o)"))) { + ret = -EBADMSG; + goto finish; + } + + ret = 0; +finish: + _I("Finished(%d): %s %s", ret, method, name); + + if (reply) + g_variant_unref(reply); + + return ret; +} + +int deviced_systemd_start_unit(char *name) +{ + assert(name); + + return deviced_systemd_start_or_stop_unit("StartUnit", name); +} + +int deviced_systemd_stop_unit(char *name) +{ + assert(name); + + 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, escape; + size_t p, k, prefix_len, unit_len = strlen(unit); + int path_len, len; + + 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 int deviced_systemd_get_property(const char *name, + const char *path, + const char *iface, + const char *method, + const char *interface, + const char *property, + GVariant **reply) +{ + int ret; + GVariant *variant; + + variant = g_variant_new("(ss)", + interface, + property); + + ret = deviced_systemd_proxy_call_sync(name, + path, + iface, + method, + variant, + reply); + + return ret; +} + +int deviced_systemd_get_manager_property(const char *iface, + const char *property, + GVariant **variant) +{ + assert(iface); + assert(property); + + return deviced_systemd_get_property(SYSTEMD_DBUS_DEST, + SYSTEMD_DBUS_PATH, + DBUS_IFACE_DBUS_PROPERTIES, + "Get", + iface, + property, + variant); +} + +int deviced_systemd_get_unit_property(const char *unit, + const char *property, + GVariant **variant) +{ + int r; + char *escaped; + + assert(unit); + assert(property); + + escaped = deviced_systemd_get_unit_dbus_path(unit); + + r = deviced_systemd_get_property(SYSTEMD_DBUS_DEST, + escaped, + DBUS_IFACE_DBUS_PROPERTIES, + "Get", + SYSTEMD_DBUS_IFACE_UNIT, + property, + variant); + free(escaped); + return r; +} + +int deviced_systemd_get_service_property(const char *unit, + const char *property, + GVariant **variant) +{ + int ret; + char *escaped; + + assert(unit); + assert(property); + + escaped = deviced_systemd_get_unit_dbus_path(unit); + + ret = deviced_systemd_get_property(SYSTEMD_DBUS_DEST, + escaped, + DBUS_IFACE_DBUS_PROPERTIES, + "Get", + SYSTEMD_DBUS_IFACE_SERVICE, + property, + variant); + free(escaped); + return ret; +} + +#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; +} diff --git a/src/shared/deviced-systemd.h b/src/shared/deviced-systemd.h new file mode 100644 index 0000000..3a560f4 --- /dev/null +++ b/src/shared/deviced-systemd.h @@ -0,0 +1,51 @@ +/* + * 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 +#include + +int deviced_systemd_start_unit(char *name); +int deviced_systemd_stop_unit(char *name); + +int deviced_systemd_get_manager_property(const char *iface, const char *property, GVariant **variant); +int deviced_systemd_get_unit_property(const char *unit, const char *property, GVariant **variant); +int deviced_systemd_get_service_property(const char* unit, const char* property, GVariant **variant); + +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 -- 2.7.4 From 59174a12caa46a07b45a53ecc818d3feb22593e5 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Tue, 24 Nov 2015 11:59:43 +0900 Subject: [PATCH 12/16] proc: remove not used operations - VIP process is handled by resourced - Battery related operations are not the public operations - Thus they are removed from deviced Change-Id: If9cf6e326b54acbd5d651534e2de5a8793b00561 Signed-off-by: taeyoung --- src/battery/power-supply.c | 1 - src/core/device-notifier.h | 2 + src/display/auto-brightness.c | 4 - src/power/power-handler.c | 1 - src/proc/proc-handler.c | 632 +++--------------------------------------- src/proc/proc-handler.h | 30 -- 6 files changed, 45 insertions(+), 625 deletions(-) delete mode 100644 src/proc/proc-handler.h diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index d816fe6..5b4e3b8 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -29,7 +29,6 @@ #include "core/config-parser.h" #include "display/poll.h" #include "display/setting.h" -#include "proc/proc-handler.h" #include "power-supply.h" #include "battery.h" diff --git a/src/core/device-notifier.h b/src/core/device-notifier.h index b751fed..5b4f6bc 100644 --- a/src/core/device-notifier.h +++ b/src/core/device-notifier.h @@ -35,6 +35,8 @@ enum device_notifier_type { DEVICE_NOTIFIER_BATTERY_CHARGING, DEVICE_NOTIFIER_POWEROFF, DEVICE_NOTIFIER_POWEROFF_HAPTIC, + DEVICE_NOTIFIER_PMQOS_OOM, + DEVICE_NOTIFIER_PROCESS_BACKGROUND, DEVICE_NOTIFIER_MAX, }; diff --git a/src/display/auto-brightness.c b/src/display/auto-brightness.c index 69a9569..fa05627 100644 --- a/src/display/auto-brightness.c +++ b/src/display/auto-brightness.c @@ -33,7 +33,6 @@ #include "core.h" #include "display-ops.h" #include "device-node.h" -#include "proc/proc-handler.h" #include "core/device-notifier.h" #include "core/config-parser.h" @@ -141,9 +140,6 @@ static void alc_set_brightness(int setting, int value, int lux) if (value < min_brightness) value = min_brightness; - if (cur_siop_level() != 0) - value = get_siop_brightness(value); - if (tmp_value != value) { if (!setting && min_brightness == PM_MIN_BRIGHTNESS && display_conf.accel_sensor_on == true) { diff --git a/src/power/power-handler.c b/src/power/power-handler.c index b4ff114..0f6879d 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -39,7 +39,6 @@ #include "core/device-idler.h" #include "core/common.h" #include "core/devices.h" -#include "proc/proc-handler.h" #include "display/poll.h" #include "display/setting.h" #include "core/edbus-handler.h" diff --git a/src/proc/proc-handler.c b/src/proc/proc-handler.c index dce0895..59b2df3 100644 --- a/src/proc/proc-handler.c +++ b/src/proc/proc-handler.c @@ -18,233 +18,35 @@ #include -#include #include -#include -#include -#include -#include -#include +//#include +//#include +//#include +//#include +//#include #include #include -#include -#include +//#include #include "core/log.h" #include "core/common.h" #include "core/devices.h" #include "core/device-notifier.h" -#include "proc-handler.h" #include "core/edbus-handler.h" +#include "shared/score-defines.h" -#define TEMPERATURE_DBUS_INTERFACE "org.tizen.trm.siop" -#define TEMPERATURE_DBUS_PATH "/Org/Tizen/Trm/Siop" -#define TEMPERATURE_DBUS_SIGNAL "ChangedTemperature" - -#define LIMITED_PROCESS_OOMADJ 15 - -#define PROCESS_VIP "process_vip" -#define PROCESS_PERMANENT "process_permanent" #define OOMADJ_SET "oomadj_set" - -#define PREDEF_BACKGRD "backgrd" -#define PREDEF_FOREGRD "foregrd" -#define PREDEF_ACTIVE "active" -#define PREDEF_INACTIVE "inactive" -#define PROCESS_GROUP_SET "process_group_set" - -#define VCONFKEY_INTERNAL_PRIVATE_SIOP_DISABLE "memory/private/sysman/siop_disable" - -#define BUFF_MAX 255 -#define SIOP_CTRL_LEVEL_MASK 0xFFFF -#define SIOP_CTRL_LEVEL(val) ((val & SIOP_CTRL_LEVEL_MASK) << 16) -#define SIOP_CTRL_VALUE(s, r) (s | (r << 4)) -#define SIOP_VALUE(d, val) ((d) * (val & 0xF)) -#define REAR_VALUE(val) (val >> 4) - -#define SIGNAL_SIOP_CHANGED "ChangedSiop" -#define SIGNAL_REAR_CHANGED "ChangedRear" -#define SIOP_LEVEL_GET "GetSiopLevel" -#define REAR_LEVEL_GET "GetRearLevel" -#define SIOP_LEVEL_SET "SetSiopLevel" - -#define SIGNAL_NAME_OOMADJ_SET "OomadjSet" - -enum SIOP_DOMAIN_TYPE { - SIOP_NEGATIVE = -1, - SIOP_POSITIVE = 1, +#define OOM_PMQOS_TIME 2000 /* ms */ +#define SIGNAL_PROC_STATUS "ProcStatus" + +enum proc_status_type { + PROC_STATUS_LAUNCH, + PROC_STATUS_RESUME, + PROC_STATUS_TERMINATE, + PROC_STATUS_FOREGROUND, + PROC_STATUS_BACKGROUND, }; -struct siop_data { - int siop; - int rear; -}; - -static int siop; -static int mode; -static int siop_domain = SIOP_POSITIVE; - -enum siop_scenario { - MODE_NONE = 0, - MODE_LCD = 1, -}; -#ifdef NOUSE -struct Node { - pid_t pid; - struct Node *next; -}; - -static struct Node *head; - -static struct Node *find_node(pid_t pid) -{ - struct Node *t = head; - - while (t != NULL) { - if (t->pid == pid) - break; - t = t->next; - } - return t; -} - -static struct Node *add_node(pid_t pid) -{ - struct Node *n; - - n = (struct Node *) malloc(sizeof(struct Node)); - if (n == NULL) { - _E("Not enough memory, add cond. fail"); - return NULL; - } - - n->pid = pid; - n->next = head; - head = n; - - return n; -} - -static int del_node(struct Node *n) -{ - struct Node *t; - struct Node *prev; - - if (n == NULL) - return 0; - - t = head; - prev = NULL; - while (t != NULL) { - if (t == n) { - if (prev != NULL) - prev->next = t->next; - else - head = head->next; - free(t); - break; - } - prev = t; - t = t->next; - } - return 0; -} -#endif - -int cur_siop_level(void) -{ - return SIOP_VALUE(siop_domain, siop); -} - -static void siop_level_action(int level) -{ - int val = SIOP_CTRL_LEVEL(level); - static int old; - static int siop_level; - static int rear_level; - static int initialized; - static int domain; - char *arr[1]; - char str_level[32]; - - if (initialized && siop == level && mode == old && domain == siop_domain) - return; - initialized = 1; - siop = level; - domain = siop_domain; - if (siop_domain == SIOP_NEGATIVE) - val = 0; - old = mode; - val |= old; - - val = SIOP_VALUE(siop_domain, level); - if (siop_level != val) { - siop_level = val; - snprintf(str_level, sizeof(str_level), "%d", siop_level); - arr[0] = str_level; - _I("broadcast siop %s", str_level); - broadcast_edbus_signal(DEVICED_PATH_PROCESS, DEVICED_INTERFACE_PROCESS, - SIGNAL_SIOP_CHANGED, "i", arr); - } - - val = REAR_VALUE(level); - if (rear_level != val) { - rear_level = val; - snprintf(str_level, sizeof(str_level), "%d", rear_level); - arr[0] = str_level; - _I("broadcast rear %s", str_level); - broadcast_edbus_signal(DEVICED_PATH_PROCESS, DEVICED_INTERFACE_PROCESS, - SIGNAL_REAR_CHANGED, "i", arr); - } - _I("level is d:%d(0x%x) s:%d r:%d", siop_domain, siop, siop_level, rear_level); -} - -static int siop_changed(int argc, char **argv) -{ - int siop_level = 0; - int rear_level = 0; - int level; - - if (argc != 2 || argv[0] == NULL) { - _E("fail to check value"); - return -1; - } - - if (argv[0] == NULL) - goto out; - - level = atoi(argv[0]); - if (level <= SIOP_NEGATIVE) - siop_domain = SIOP_NEGATIVE; - else - siop_domain = SIOP_POSITIVE; - siop_level = siop_domain * level; - - if (argv[1] == NULL) - goto out; - - level = atoi(argv[1]); - rear_level = level; - -out: - level = SIOP_CTRL_VALUE(siop_level, rear_level); - siop_level_action(level); - return 0; -} - -static int siop_mode_lcd(keynode_t *key_nodes, void *data) -{ - int pm_state; - if (vconf_get_int(VCONFKEY_PM_STATE, &pm_state) != 0) - _E("Fail to get vconf value for pm state\n"); - if (pm_state == VCONFKEY_PM_STATE_LCDOFF) - mode = MODE_LCD; - else - mode = MODE_NONE; - siop_level_action(siop); - return 0; -} - static void memcg_move_group(int pid, int oom_score_adj) { char buf[100]; @@ -259,9 +61,9 @@ static void memcg_move_group(int pid, int oom_score_adj) _SD("memcg_move_group : %s, pid = %d", exe_name, pid); if (oom_score_adj >= OOMADJ_BACKGRD_LOCKED) - sprintf(buf, "/sys/fs/cgroup/memory/background/cgroup.procs"); + snprintf(buf, sizeof(buf), "/sys/fs/cgroup/memory/background/cgroup.procs"); else if (oom_score_adj >= OOMADJ_FOREGRD_LOCKED && oom_score_adj < OOMADJ_BACKGRD_LOCKED) - sprintf(buf, "/sys/fs/cgroup/memory/foreground/cgroup.procs"); + snprintf(buf, sizeof(buf), "/sys/fs/cgroup/memory/foreground/cgroup.procs"); else return; @@ -274,67 +76,6 @@ static void memcg_move_group(int pid, int oom_score_adj) fclose(f); } -int get_oom_score_adj(int pid, int *oom_score_adj) -{ - char buf[PATH_MAX]; - FILE *fp; - - if (pid < 0) - return -1; - - fp = open_proc_oom_score_adj_file(pid, "r"); - if (fp == NULL) - return -1; - if (fgets(buf, PATH_MAX, fp) == NULL) { - fclose(fp); - return -1; - } - - *oom_score_adj = atoi(buf); - fclose(fp); - return 0; -} - -int set_oom_score_adj(pid_t pid, int new_oom_score_adj) -{ - FILE *fp; - int old_oom_score_adj; - char exe_name[PATH_MAX]; - - if (get_cmdline_name(pid, exe_name, PATH_MAX) < 0) - snprintf(exe_name, sizeof(exe_name), "Unknown (maybe dead)"); - - if (get_oom_score_adj(pid, &old_oom_score_adj) < 0) - return -1; - - _SI("Process %s, pid %d, old_oom_score_adj %d new_oom_score_adj %d", - exe_name, pid, old_oom_score_adj, new_oom_score_adj); - - if (new_oom_score_adj < OOMADJ_SU) - new_oom_score_adj = OOMADJ_SU; - - fp = open_proc_oom_score_adj_file(pid, "w"); - if (fp == NULL) - return -1; - - fprintf(fp, "%d", new_oom_score_adj); - fclose(fp); - - return 0; -} - -int set_su_oom_score_adj(pid_t pid) -{ - return set_oom_score_adj(pid, OOMADJ_SU); -} - -int check_oom_score_adj(int oom_score_adj) -{ - if (oom_score_adj != OOMADJ_FOREGRD_LOCKED && oom_score_adj != OOMADJ_FOREGRD_UNLOCKED) - return 0; - return -1; -} - int set_oom_score_adj_action(int argc, char **argv) { FILE *fp; @@ -362,180 +103,6 @@ int set_oom_score_adj_action(int argc, char **argv) return 0; } -int set_active_action(int argc, char **argv) -{ - int pid = -1; - int ret = 0; - int oom_score_adj = 0; - - if (argc < 1) - return -1; - pid = atoi(argv[0]); - if (pid < 0) - return -1; - ret = get_oom_score_adj(pid, &oom_score_adj); - if (ret < 0) - return -1; - - switch (oom_score_adj) { - case OOMADJ_FOREGRD_LOCKED: - case OOMADJ_BACKGRD_LOCKED: - case OOMADJ_SU: - ret = 0; - break; - case OOMADJ_FOREGRD_UNLOCKED: - ret = set_oom_score_adj((pid_t) pid, OOMADJ_FOREGRD_LOCKED); - break; - case OOMADJ_BACKGRD_UNLOCKED: - ret = set_oom_score_adj((pid_t) pid, OOMADJ_BACKGRD_LOCKED); - break; - case OOMADJ_INIT: - ret = set_oom_score_adj((pid_t) pid, OOMADJ_BACKGRD_LOCKED); - break; - default: - if (oom_score_adj > OOMADJ_BACKGRD_UNLOCKED) { - ret = set_oom_score_adj((pid_t) pid, OOMADJ_BACKGRD_LOCKED); - } else { - _E("Unknown oom_score_adj value (%d) !", oom_score_adj); - ret = -1; - } - break; - } - return ret; -} - -int set_inactive_action(int argc, char **argv) -{ - int pid = -1; - int ret = 0; - int oom_score_adj = 0; - - if (argc < 1) - return -1; - pid = atoi(argv[0]); - if (pid < 0) - return -1; - - ret = get_oom_score_adj(pid, &oom_score_adj); - if (ret < 0) - return -1; - - switch (oom_score_adj) { - case OOMADJ_FOREGRD_UNLOCKED: - case OOMADJ_BACKGRD_UNLOCKED: - case OOMADJ_SU: - ret = 0; - break; - case OOMADJ_FOREGRD_LOCKED: - ret = set_oom_score_adj((pid_t) pid, OOMADJ_FOREGRD_UNLOCKED); - break; - case OOMADJ_BACKGRD_LOCKED: - ret = set_oom_score_adj((pid_t) pid, OOMADJ_BACKGRD_UNLOCKED); - break; - case OOMADJ_INIT: - ret = set_oom_score_adj((pid_t) pid, OOMADJ_BACKGRD_UNLOCKED); - break; - default: - if (oom_score_adj > OOMADJ_BACKGRD_UNLOCKED) { - ret = 0; - } else { - _E("Unknown oom_score_adj value (%d) !", oom_score_adj); - ret = -1; - } - break; - - } - return ret; -} - -int set_process_action(int argc, char **argv) -{ - int pid = -1; - int ret = 0; - - if (argc < 1) - return -1; - pid = atoi(argv[0]); - if (pid < 0) - return -1; - - return ret; -} - -int set_process_group_action(int argc, char **argv) -{ - int pid = -1; - int ret = -1; - - if (argc != 2) - return -1; - pid = atoi(argv[0]); - if (pid < 0) - return -1; - - if (strncmp(argv[1], PROCESS_VIP, strlen(PROCESS_VIP)) == 0) - ret = device_set_property(DEVICE_TYPE_PROCESS, PROP_PROCESS_MP_VIP, pid); - else if (strncmp(argv[1], PROCESS_PERMANENT, strlen(PROCESS_PERMANENT)) == 0) - ret = device_set_property(DEVICE_TYPE_PROCESS, PROP_PROCESS_MP_PNP, pid); - - if (ret == 0) - _I("%s : pid %d", argv[1], pid); - else - _E("fail to set %s : pid %d", argv[1], pid); - return 0; -} - -static DBusMessage *dbus_proc_handler(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusError err; - DBusMessageIter iter; - DBusMessage *reply; - pid_t pid; - int ret; - int argc; - char *type_str; - char *argv; - - dbus_error_init(&err); - - if (!dbus_message_get_args(msg, &err, - DBUS_TYPE_STRING, &type_str, - DBUS_TYPE_INT32, &argc, - DBUS_TYPE_STRING, &argv, DBUS_TYPE_INVALID)) { - _E("there is no message"); - ret = -EINVAL; - goto out; - } - - if (argc < 0) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - pid = get_edbus_sender_pid(msg); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (strncmp(type_str, PREDEF_FOREGRD, strlen(PREDEF_FOREGRD)) == 0) - ret = set_process_action(argc, (char **)&argv); - else if (strncmp(type_str, PREDEF_BACKGRD, strlen(PREDEF_BACKGRD)) == 0) - ret = set_process_action(argc, (char **)&argv); - else if (strncmp(type_str, PREDEF_ACTIVE, strlen(PREDEF_ACTIVE)) == 0) - ret = set_active_action(argc, (char **)&argv); - else if (strncmp(type_str, PREDEF_INACTIVE, strlen(PREDEF_INACTIVE)) == 0) - ret = set_inactive_action(argc, (char **)&argv); -out: - reply = dbus_message_new_method_return(msg); - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); - - return reply; -} - static DBusMessage *dbus_oom_handler(E_DBus_Object *obj, DBusMessage *msg) { DBusError err; @@ -574,60 +141,9 @@ static DBusMessage *dbus_oom_handler(E_DBus_Object *obj, DBusMessage *msg) if (strncmp(type_str, OOMADJ_SET, strlen(OOMADJ_SET)) == 0) ret = set_oom_score_adj_action(argc, (char **)&argv); - else if (strncmp(type_str, PROCESS_GROUP_SET, strlen(PROCESS_GROUP_SET)) == 0) - ret = set_process_group_action(argc, (char **)&argv); -out: - reply = dbus_message_new_method_return(msg); - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); - - return reply; -} - -static DBusMessage *dbus_get_siop_level(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - int level; - - level = SIOP_VALUE(siop_domain, siop); - reply = dbus_message_new_method_return(msg); - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &level); - return reply; -} - -static DBusMessage *dbus_get_rear_level(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - int level; - - level = REAR_VALUE(siop); - reply = dbus_message_new_method_return(msg); - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &level); - return reply; -} - -static DBusMessage *dbus_set_siop_level(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusError err; - DBusMessageIter iter; - DBusMessage *reply; - int ret; - char *argv[2]; - - dbus_error_init(&err); - - if (!dbus_message_get_args(msg, &err, - DBUS_TYPE_STRING, &argv[0], - DBUS_TYPE_STRING, &argv[1], DBUS_TYPE_INVALID)) { - _E("there is no message"); + else ret = -EINVAL; - goto out; - } - ret = siop_changed(2, (char **)&argv); + out: reply = dbus_message_new_method_return(msg); dbus_message_iter_init_append(reply, &iter); @@ -636,126 +152,64 @@ out: return reply; } -static void dbus_proc_oomadj_set_signal_handler(void *data, DBusMessage *msg) - +static void proc_signal_handler(void *data, DBusMessage *msg) { DBusError err; + int ret, type; pid_t pid; - int ret = -EINVAL; - int argc; - char *type_str; - char *argv; - - dbus_error_init(&err); - if (!dbus_message_get_args(msg, &err, - DBUS_TYPE_STRING, &type_str, - DBUS_TYPE_INT32, &argc, - DBUS_TYPE_STRING, &argv, DBUS_TYPE_INVALID)) { - _E("there is no message"); + ret = dbus_message_is_signal(msg, RESOURCED_INTERFACE_PROCESS, + SIGNAL_PROC_STATUS); + if (!ret) { + _E("It's not active signal!"); return; } - if (argc < 0) { - _E("message is invalid!"); - return; - } + dbus_error_init(&err); - pid = get_edbus_sender_pid(msg); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); + if (dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &type, + DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID) == 0) { + _E("There's no arguments!"); return; } - if (strncmp(type_str, PREDEF_FOREGRD, strlen(PREDEF_FOREGRD)) == 0) - ret = set_process_action(argc, (char **)&argv); - else if (strncmp(type_str, PREDEF_BACKGRD, strlen(PREDEF_BACKGRD)) == 0) - ret = set_process_action(argc, (char **)&argv); - else if (strncmp(type_str, PREDEF_ACTIVE, strlen(PREDEF_ACTIVE)) == 0) - ret = set_active_action(argc, (char **)&argv); - else if (strncmp(type_str, PREDEF_INACTIVE, strlen(PREDEF_INACTIVE)) == 0) - ret = set_inactive_action(argc, (char **)&argv); - - if (ret < 0) - _E("set_process_action error!"); + if (type == PROC_STATUS_BACKGROUND) + device_notify(DEVICE_NOTIFIER_PROCESS_BACKGROUND, &pid); } static const struct edbus_method edbus_methods[] = { - { PREDEF_FOREGRD, "sis", "i", dbus_proc_handler }, - { PREDEF_BACKGRD, "sis", "i", dbus_proc_handler }, - { PREDEF_ACTIVE, "sis", "i", dbus_proc_handler }, - { PREDEF_INACTIVE, "sis", "i", dbus_proc_handler }, { OOMADJ_SET, "siss", "i", dbus_oom_handler }, - { PROCESS_GROUP_SET, "siss", "i", dbus_oom_handler }, - { SIOP_LEVEL_GET, NULL, "i", dbus_get_siop_level }, - { REAR_LEVEL_GET, NULL, "i", dbus_get_rear_level }, - { SIOP_LEVEL_SET, "ss", "i", dbus_set_siop_level }, }; -static int proc_booting_done(void *data) -{ - static int done; - - if (data == NULL) - goto out; - done = *(int *)data; - if (vconf_notify_key_changed(VCONFKEY_PM_STATE, (void *)siop_mode_lcd, NULL) < 0) - _E("Vconf notify key chaneged failed: KEY(%s)", VCONFKEY_PM_STATE); - siop_mode_lcd(NULL, NULL); -out: - return done; -} - -static int process_execute(void *data) +static void proc_change_lowmemory(keynode_t *key, void *data) { - struct siop_data *key_data = (struct siop_data *)data; - int siop_level = 0; - int rear_level = 0; - int level; - int booting_done; + int state = 0; - booting_done = proc_booting_done(NULL); - if (!booting_done) - return 0; - - if (key_data == NULL) - goto out; - - level = key_data->siop; - if (level <= SIOP_NEGATIVE) - siop_domain = SIOP_NEGATIVE; - else - siop_domain = SIOP_POSITIVE; - siop_level = siop_domain * level; - - level = key_data->rear; - rear_level = level; + if (vconf_get_int(VCONFKEY_SYSMAN_LOW_MEMORY, &state)) + return; -out: - level = SIOP_CTRL_VALUE(siop_level, rear_level); - siop_level_action(level); - return 0; + if (state == VCONFKEY_SYSMAN_LOW_MEMORY_HARD_WARNING) + device_notify(DEVICE_NOTIFIER_PMQOS_OOM, (void *)OOM_PMQOS_TIME); } static void process_init(void *data) { int ret; - register_edbus_signal_handler(DEVICED_PATH_PROCESS, DEVICED_INTERFACE_PROCESS, - SIGNAL_NAME_OOMADJ_SET, - dbus_proc_oomadj_set_signal_handler); + register_edbus_signal_handler(RESOURCED_PATH_PROCESS, + RESOURCED_INTERFACE_PROCESS, SIGNAL_PROC_STATUS, proc_signal_handler); ret = register_edbus_method(DEVICED_PATH_PROCESS, edbus_methods, ARRAY_SIZE(edbus_methods)); if (ret < 0) _E("fail to init edbus method(%d)", ret); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, proc_booting_done); + vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, + proc_change_lowmemory, NULL); } static const struct device_ops process_device_ops = { - .name = PROC_OPS_NAME, + .name = "process", .init = process_init, - .execute = process_execute, }; DEVICE_OPS_REGISTER(&process_device_ops) diff --git a/src/proc/proc-handler.h b/src/proc/proc-handler.h deleted file mode 100644 index 1f352b3..0000000 --- a/src/proc/proc-handler.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __PROC_HANDLER_H__ -#define __PROC_HANDLER_H__ - -#include "shared/score-defines.h" - -#define PROC_OPS_NAME "process" - -int get_oom_score_adj(int pid, int *oom_score_adj); -int set_oom_score_adj(int pid, int new_oom_score_adj); -int cur_siop_level(void); -#endif /* __PROC_HANDLER_H__ */ -- 2.7.4 From d7bf3bdbe7dd0111dc67182baa8fd7a3ecc16379 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Tue, 24 Nov 2015 14:14:03 +0900 Subject: [PATCH 13/16] common: remove unused codes - predefine_act_plugin module is not used anymore Change-Id: Id10287f43e2448b71302533fee6fe6bcf0a3bcc1 Signed-off-by: taeyoung --- src/predefine_act_plugin/CMakeLists.txt | 38 --------------------------- src/predefine_act_plugin/build.sh | 7 ----- src/predefine_act_plugin/xxx-predefine.c | 45 -------------------------------- 3 files changed, 90 deletions(-) delete mode 100644 src/predefine_act_plugin/CMakeLists.txt delete mode 100755 src/predefine_act_plugin/build.sh delete mode 100644 src/predefine_act_plugin/xxx-predefine.c diff --git a/src/predefine_act_plugin/CMakeLists.txt b/src/predefine_act_plugin/CMakeLists.txt deleted file mode 100644 index 100c04f..0000000 --- a/src/predefine_act_plugin/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(xxx-predefine C) - -SET(SRCS xxx-predefine.c) - -SET(PREFIX ${CMAKE_INSTALL_PREFIX}) -SET(EXEC_PREFIX "\${prefix}") -SET(LIBDIR "\${prefix}/lib") -SET(INCLUDEDIR "\${prefix}/include") -SET(VERSION 1.0) - -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) - -INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED sysman) - -FOREACH(flag ${pkgs_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer") - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") -MESSAGE("FLAGS: ${CMAKE_C_FLAGS}") - -ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") -ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"") -ADD_DEFINITIONS("-DDEBUG") -IF( $ENV{ARCH} MATCHES "arm" ) - ADD_DEFINITIONS("-DTARGET") -ENDIF() - -SET(CMAKE_LDFLAGS "-Wl,zdefs") -ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS}) - -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib COMPONENT RuntimeLibraries) - diff --git a/src/predefine_act_plugin/build.sh b/src/predefine_act_plugin/build.sh deleted file mode 100755 index c0cc290..0000000 --- a/src/predefine_act_plugin/build.sh +++ /dev/null @@ -1,7 +0,0 @@ -cd `dirname $0` - -. ../../../../../setup.conf || exit 1 - -. ${TPLDIR}/cmake.tpl -run - diff --git a/src/predefine_act_plugin/xxx-predefine.c b/src/predefine_act_plugin/xxx-predefine.c deleted file mode 100644 index 507bf09..0000000 --- a/src/predefine_act_plugin/xxx-predefine.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * system-server - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: DongGi Jang - * - * 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 - -int SS_PREDEFINE_ACT_FUNC(int argc, char **argv) -{ - int i; - printf("kqwekrqkwerqwer\n"); - for (i = 0; i < argc; i++) - printf("%s\n", argv[i]); - return 0; -} - -int SS_IS_ACCESSABLE_FUNC(int pid) -{ - printf("qwerqerqewr %d\n", pid); - return 1; -} - -int SS_UI_VIEWABLE_FUNC() -{ - printf("kakak viewable\n"); - return 1; -} -- 2.7.4 From 8586195e2935c49851a92169f1f6671802b26a62 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Tue, 24 Nov 2015 21:16:47 +0900 Subject: [PATCH 14/16] earjack: send system event when earjack state is chagned - eventsystem is common event delivery api from Tizen 2.4 Change-Id: I711883b7d18b11f8ec6af1ad45e153766114c0c8 Signed-off-by: taeyoung --- CMakeLists.txt | 1 + packaging/deviced.spec | 1 + src/extcon/earjack.c | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ee15efa..75ffc64 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,6 +150,7 @@ SET(PKG_MODULES capi-base-common dbus-1 gio-2.0 + eventsystem libtzplatform-config notification hwcommon diff --git a/packaging/deviced.spec b/packaging/deviced.spec index ef29bfb..9be19c5 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -67,6 +67,7 @@ BuildRequires: pkgconfig(dbus-1) BuildRequires: pkgconfig(dbus-glib-1) BuildRequires: pkgconfig(libudev) BuildRequires: pkgconfig(gio-2.0) +BuildRequires: pkgconfig(eventsystem) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(notification) BuildRequires: pkgconfig(hwcommon) diff --git a/src/extcon/earjack.c b/src/extcon/earjack.c index 4751370..eb73b22 100644 --- a/src/extcon/earjack.c +++ b/src/extcon/earjack.c @@ -19,12 +19,15 @@ #include #include +#include +#include #include "core/log.h" #include "display/poll.h" #include "extcon/extcon.h" #define SIGNAL_EARJACK_STATE "ChangedEarjack" +#define GET_EARJACK_STATE "Earjack" static void earjack_send_broadcast(int status) { @@ -44,11 +47,28 @@ static void earjack_send_broadcast(int status) SIGNAL_EARJACK_STATE, "i", arr); } +static void earjack_send_system_event(int status) +{ + bundle *b; + const char *str; + + if (status) + str = EVT_VAL_EARJACK_CONNECTED; + else + str = EVT_VAL_EARJACK_DISCONNECTED; + + b = bundle_create(); + bundle_add_str(b, EVT_KEY_EARJACK_STATUS, str); + eventsystem_send_system_event(SYS_EVENT_EARJACK_STATUS, b); + bundle_free(b); +} + static int earjack_update(int status) { _I("jack - earjack changed %d", status); vconf_set_int(VCONFKEY_SYSMAN_EARJACK, status); earjack_send_broadcast(status); + earjack_send_system_event(status); if (status != 0) pm_change_internal(getpid(), LCD_NORMAL); -- 2.7.4 From 1885c2d9e1a07eeb1864ffc98160dea6429e3e46 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Tue, 24 Nov 2015 22:37:40 +0900 Subject: [PATCH 15/16] power: remove unnecessary methods and add operations which should be run during power off - The poweroff popup can be launched only powerkey longpress. Thus the dbus method for launching popup is removed. - Systemd journal is disabled not to remain garbage backup files - eventsystem is used to notify power off situation Change-Id: Icec995eec8858c8ef0b94fedbfaf56f0dee97d3e Signed-off-by: taeyoung --- src/power/power-handler.c | 180 +++++++++++++++++++++++++--------------------- 1 file changed, 97 insertions(+), 83 deletions(-) diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 0f6879d..ec32192 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +33,9 @@ #include #include #include +#include +#include + #include "dd-deviced.h" #include "core/log.h" #include "core/launch.h" @@ -44,8 +48,9 @@ #include "core/edbus-handler.h" #include "display/core.h" #include "power-handler.h" +#include "apps/apps.h" +#include "shared/deviced-systemd.h" -#define SIGNAL_NAME_POWEROFF_POPUP "poweroffpopup" #define SIGNAL_BOOTING_DONE "BootingDone" #define POWEROFF_DURATION 2 @@ -87,29 +92,77 @@ static int telephony_exit(void *data) return ret; } +static void system_shutdown_send_system_event(void) +{ + bundle *b; + const char *str = EVT_VAL_SYSTEM_SHUTDOWN_TRUE; + + b = bundle_create(); + bundle_add_str(b, EVT_KEY_SYSTEM_SHUTDOWN, str); + eventsystem_send_system_event(SYS_EVENT_SYSTEM_SHUTDOWN, b); + bundle_free(b); +} + +static void boot_complete_send_system_event(void) +{ + bundle *b; + const char *str = EVT_VAL_BOOT_COMPLETED_TRUE; + + b = bundle_create(); + bundle_add_str(b, EVT_KEY_BOOT_COMPLETED, str); + eventsystem_send_system_event(SYS_EVENT_BOOT_COMPLETED, b); + bundle_free(b); +} + +static void poweroff_stop_systemd_service(void) +{ + _D("systemd service stop"); + umount2("/sys/fs/cgroup", MNT_FORCE |MNT_DETACH); +} + +static int stop_systemd_journald(void) +{ + int ret; + + ret = deviced_systemd_stop_unit("systemd-journald.socket"); + if (ret < 0) { + _E("failed to stop 'systemd-journald.socket'"); + return ret; + } + + ret |= deviced_systemd_stop_unit("systemd-journald.service"); + if (ret < 0) { + _E("failed to stop 'systemd-journald.service'"); + return ret; + } + + return 0; +} + static void poweroff_start_animation(void) { char params[128]; snprintf(params, sizeof(params), "/usr/bin/boot-animation --stop --clear"); launch_app_cmd_with_nice(params, -20); + gettimeofday(&tv_start_poweroff, NULL); launch_evenif_exist("/usr/bin/sound_server", "--poweroff"); device_notify(DEVICE_NOTIFIER_POWEROFF_HAPTIC, NULL); } -int previous_poweroff(void) +static int poweroff(void) { int ret; static const struct device_ops *display_device_ops = NULL; + poweroff_start_animation(); telephony_start(); FIND_DEVICE_INT(display_device_ops, "display"); + pm_change_internal(getpid(), LCD_NORMAL); display_device_ops->exit(NULL); sync(); - gettimeofday(&tv_start_poweroff, NULL); - ret = telephony_exit(POWER_POWEROFF); if (ret < 0) { @@ -119,37 +172,17 @@ int previous_poweroff(void) return ret; } -static int poweroff(void) -{ - int retry_count = 0; - poweroff_start_animation(); - while (retry_count < MAX_RETRY) { - if (previous_poweroff() < 0) { - _E("failed to request poweroff to deviced"); - retry_count++; - continue; - } - return 0; - } - return -1; -} - static int pwroff_popup(void) { - int ret; - - ret = manage_notification("Poweroff", "Poweroff"); - if (ret == -1) - return -1; - - return 0; + return launch_system_app(APP_POWEROFF, + 2, APP_KEY_TYPE, APP_POWEROFF); } static int power_reboot(void) { int ret; - const struct device_ops *display_device_ops = NULL; + poweroff_start_animation(); telephony_start(); @@ -159,8 +192,6 @@ static int power_reboot(void) display_device_ops->exit(NULL); sync(); - gettimeofday(&tv_start_poweroff, NULL); - ret = telephony_exit(POWER_REBOOT); if (ret < 0) { restart_ap(NULL); @@ -169,27 +200,6 @@ static int power_reboot(void) return ret; } -static void poweroff_popup_edbus_signal_handler(void *data, DBusMessage *msg) -{ - DBusError err; - char *str; - int val = 0; - - if (dbus_message_is_signal(msg, DEVICED_INTERFACE_NAME, SIGNAL_NAME_POWEROFF_POPUP) == 0) { - _E("there is no power off popup signal"); - return; - } - - dbus_error_init(&err); - - if (dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID) == 0) { - _E("there is no message"); - return; - } - - power_execute(str); -} - static int booting_done(void *data) { static int done = 0; @@ -211,6 +221,11 @@ static void booting_done_edbus_signal_handler(void *data, DBusMessage *msg) _E("there is no bootingdone signal"); return; } + + _I("real booting done, unlock LCD_OFF"); + pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN); + boot_complete_send_system_event(); + done = booting_done(NULL); if (done) return; @@ -239,18 +254,9 @@ static void poweroff_send_broadcast(int status) SIGNAL_POWEROFF_STATE, "i", arr); } -static void poweroff_stop_systemd_service(void) -{ - char buf[256]; - _D("systemd service stop"); - umount2("/sys/fs/cgroup", MNT_FORCE |MNT_DETACH); -} - static void poweroff_idler_cb(void *data) { - enum poweroff_type val = (int)data; - int ret; - int recovery; + enum poweroff_type val = (long)data; telephony_start(); @@ -260,6 +266,7 @@ static void poweroff_idler_cb(void *data) if (val == POWER_OFF_DIRECT || val == POWER_OFF_RESTART) { poweroff_send_broadcast(val); device_notify(DEVICE_NOTIFIER_POWEROFF, &val); + system_shutdown_send_system_event(); } /* TODO for notify. will be removed asap. */ @@ -275,6 +282,8 @@ static void poweroff_idler_cb(void *data) case POWER_OFF_RESTART: power_reboot(); break; + default: + return; } if (update_pm_setting) @@ -284,25 +293,26 @@ static void poweroff_idler_cb(void *data) static int power_execute(void *data) { int ret; - int val; + long val; + char *str = (char *)data; if (!data) { _E("Invalid parameter : data(NULL)"); return -EINVAL; } - if (strncmp(POWER_POWEROFF, (char *)data, POWER_POWEROFF_LEN) == 0) + if (strncmp(POWER_POWEROFF, str, POWER_POWEROFF_LEN) == 0) val = POWER_OFF_DIRECT; - else if (strncmp(PWROFF_POPUP, (char *)data, PWROFF_POPUP_LEN) == 0) + else if (strncmp(PWROFF_POPUP, str, PWROFF_POPUP_LEN) == 0) val = POWER_OFF_POPUP; - else if (strncmp(POWER_REBOOT, (char *)data, POWER_REBOOT_LEN) == 0) + else if (strncmp(POWER_REBOOT, str, POWER_REBOOT_LEN) == 0) val = POWER_OFF_RESTART; else { - _E("Invalid parameter : data(%s)", (char *)data); + _E("Invalid parameter : data(%s)", str); return -EINVAL; } - ret = add_idle_request(poweroff_idler_cb, (int*)val); + ret = add_idle_request(poweroff_idler_cb, (void *)val); if (ret < 0) { _E("fail to add poweroff idle request : %d", ret); return ret; @@ -314,35 +324,40 @@ static int power_execute(void *data) /* umount usr data partition */ static void unmount_rw_partition() { - int retry = 0; + int retry = 0, r; + struct timespec time = {0,}; sync(); -#ifdef MICRO_DD + if (!mount_check(UMOUNT_RW_PATH)) return; -#endif while (1) { switch (retry++) { case 0: /* Second, kill app with SIGTERM */ _I("Kill app with SIGTERM"); terminate_process(UMOUNT_RW_PATH, false); - sleep(3); + time.tv_nsec = 700 * NANO_SECOND_MULTIPLIER; + nanosleep(&time, NULL); break; case 1: /* Last time, kill app with SIGKILL */ _I("Kill app with SIGKILL"); terminate_process(UMOUNT_RW_PATH, true); + time.tv_nsec = 300 * NANO_SECOND_MULTIPLIER; + nanosleep(&time, NULL); sleep(1); break; default: - if (umount2(UMOUNT_RW_PATH, 0) != 0) { - _I("Failed to unmount %s", UMOUNT_RW_PATH); - return; - } - _I("%s unmounted successfully", UMOUNT_RW_PATH); + r = umount2(UMOUNT_RW_PATH, 0); + if (r != 0) + _I("Failed to unmount %s(%d)", UMOUNT_RW_PATH, r); + else + _I("%s unmounted successfully", UMOUNT_RW_PATH); return; } - if (umount2(UMOUNT_RW_PATH, 0) == 0) { + + r = umount2(UMOUNT_RW_PATH, 0); + if (r == 0) { _I("%s unmounted successfully", UMOUNT_RW_PATH); return; } @@ -361,6 +376,9 @@ static void powerdown(void) _E("during power off"); return; } + + stop_systemd_journald(); + /* if this fails, that's OK */ telephony_stop(); power_off = 1; @@ -472,25 +490,21 @@ void restart_ap(void *data) static const struct edbus_method edbus_methods[] = { { POWER_REBOOT, "si", "i", dbus_power_handler }, - { PWROFF_POPUP, "si", "i", dbus_power_handler }, - /* be linked to device_power_reboot() public API. */ + /* Public API device_power_reboot() calls this dbus method. */ { "Reboot", "s", "i", request_reboot }, /* Add methods here */ }; static void power_init(void *data) { - int bTelReady = 0; int ret; /* init dbus interface */ - ret = register_edbus_method(DEVICED_PATH_POWER, edbus_methods, ARRAY_SIZE(edbus_methods)); + ret = register_edbus_method(DEVICED_PATH_POWER, + edbus_methods, ARRAY_SIZE(edbus_methods)); if (ret < 0) _E("fail to init edbus method(%d)", ret); - register_edbus_signal_handler(DEVICED_OBJECT_PATH, DEVICED_INTERFACE_NAME, - SIGNAL_NAME_POWEROFF_POPUP, - poweroff_popup_edbus_signal_handler); register_edbus_signal_handler(DEVICED_PATH_CORE, DEVICED_INTERFACE_CORE, SIGNAL_BOOTING_DONE, -- 2.7.4 From 4b5a931591c714c7adc7e183248a86f683d71208 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Thu, 26 Nov 2015 22:05:36 +0900 Subject: [PATCH 16/16] battery: add charge_status property - charge_status is used for send system event. If charge_status is same as previous status, system event is not delivered. - In addition, application related codes are fixed to launch popup. Change-Id: I0ba02703c25eed91db4198f1ef7da2c8df7ec4cd Signed-off-by: taeyoung --- src/battery/battery.h | 2 - src/battery/config.c | 6 -- src/battery/lowbat-handler.c | 59 +++++++++++++++---- src/battery/power-supply.c | 131 ++++++++++++++++++++++++++++--------------- src/battery/power-supply.h | 10 ++++ src/core/udev.h | 2 - 6 files changed, 144 insertions(+), 66 deletions(-) diff --git a/src/battery/battery.h b/src/battery/battery.h index e352e3c..f1496bb 100644 --- a/src/battery/battery.h +++ b/src/battery/battery.h @@ -37,8 +37,6 @@ struct battery_config_info { int critical; int poweroff; int realoff; - char warning_method[METHOD_NAME_MAX]; - char critical_method[METHOD_NAME_MAX]; }; int battery_charge_err_low_act(void *data); diff --git a/src/battery/config.c b/src/battery/config.c index 00d39ad..4dd42c1 100644 --- a/src/battery/config.c +++ b/src/battery/config.c @@ -59,12 +59,6 @@ static int load_config(struct parse_result *result, void *user_data) info->poweroff = atoi(value); else if (MATCH(name, "RealOff")) info->realoff = atoi(value); - else if (MATCH(name, "WarningMethod")) - snprintf(info->warning_method, - sizeof(info->warning_method), "%s", value); - else if (MATCH(name, "CriticalMethod")) - snprintf(info->critical_method, - sizeof(info->critical_method), "%s", value); return 0; } diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 4dbc660..cad1bf7 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include "battery.h" #include "config.h" @@ -37,6 +39,7 @@ #include "display/poll.h" #include "core/edbus-handler.h" #include "power/power-handler.h" +#include "apps/apps.h" #include "power-supply.h" #define CHARGE_POWERSAVE_FREQ_ACT "charge_powersave_freq_act" @@ -79,8 +82,6 @@ static struct battery_config_info battery_info = { .critical = BATTERY_CRITICAL, .poweroff = BATTERY_POWEROFF, .realoff = BATTERY_REALOFF, - .warning_method = "warning", - .critical_method = "critical", }; static dd_list *lpe; @@ -251,25 +252,25 @@ static int lowbat_popup(char *option) launched_poweroff = 0; if (!strcmp(option, CRITICAL_LOW_BAT_ACT)) { - value = battery_info.critical_method; + value = "lowbattery_critical"; lowbat_popup_option = LOWBAT_OPT_CHECK; } else if (!strcmp(option, WARNING_LOW_BAT_ACT)) { - value = battery_info.warning_method; + value = "lowbattery_warning"; lowbat_popup_option = LOWBAT_OPT_WARNING; } else if (!strcmp(option, POWER_OFF_BAT_ACT)) { value = "poweroff"; lowbat_popup_option = LOWBAT_OPT_POWEROFF; } else if (!strcmp(option, CHARGE_ERROR_ACT)) { - value = "Charger error"; + value = "chargeerr"; lowbat_popup_option = LOWBAT_OPT_CHARGEERR; } else if (!strcmp(option, CHARGE_ERROR_LOW_ACT)) { - value = "Charger low temperature error"; + value = "chargeerrlow"; lowbat_popup_option = LOWBAT_OPT_CHARGEERR; } else if (!strcmp(option, CHARGE_ERROR_HIGH_ACT)) { - value = "Charger high temperature error"; + value = "chargeerrhigh"; lowbat_popup_option = LOWBAT_OPT_CHARGEERR; } else if (!strcmp(option, CHARGE_ERROR_OVP_ACT)) { - value = "Charger ovp error"; + value = "chargeerrovp"; lowbat_popup_option = LOWBAT_OPT_CHARGEERR; } else if (!strcmp(option, CHARGE_CHECK_ACT)) { launched_poweroff = 0; @@ -290,6 +291,11 @@ direct_launch: if (lowbat_popup_option == LOWBAT_OPT_POWEROFF) launched_poweroff = 1; + ret = launch_system_app(APP_DEFAULT, + 2, APP_KEY_TYPE, "remove_battery_popups"); + if (ret < 0) + _E("Failed to close all of battery popups"); + r_disturb = vconf_get_int("memory/shealth/sleep/do_not_disturb", &s_disturb); r_block = vconf_get_bool("db/setting/blockmode_wearable", &s_block); if ((r_disturb != 0 && r_block != 0) || @@ -299,9 +305,8 @@ direct_launch: else _I("block LCD"); - ret = manage_notification("Low battery", value); - if (ret == -1) - return -1; + return launch_system_app(APP_DEFAULT, + 2, APP_KEY_TYPE, value); } else { _D("boot-animation running yet"); } @@ -387,6 +392,36 @@ static void lowbat_scenario_init(void) lowbat_add_scenario(battery_info.realoff, battery_info.realoff, battery_power_off_act); } +static void battery_level_send_system_event(int bat_percent) +{ + bundle *b; + const char *str; + static const char *prev; + + if (bat_percent > BATTERY_LEVEL_CHECK_FULL) + str = EVT_VAL_BATTERY_LEVEL_FULL; + else if (bat_percent > BATTERY_LEVEL_CHECK_HIGH) + str = EVT_VAL_BATTERY_LEVEL_HIGH; + else if (bat_percent > BATTERY_LEVEL_CHECK_LOW) + str = EVT_VAL_BATTERY_LEVEL_LOW; + else if (bat_percent > BATTERY_LEVEL_CHECK_CRITICAL) + str = EVT_VAL_BATTERY_LEVEL_CRITICAL; + else + str = EVT_VAL_BATTERY_LEVEL_EMPTY; + + if (prev == str) + return; + + prev = str; + + _D("system_event(%s)", str); + + b = bundle_create(); + bundle_add_str(b, EVT_KEY_BATTERY_LEVEL_STATUS, str); + eventsystem_send_system_event(SYS_EVENT_BATTERY_LEVEL_STATUS, b); + bundle_free(b); +} + static void change_lowbat_level(int bat_percent) { int prev, now; @@ -430,6 +465,7 @@ static int lowbat_process(int bat_percent, void *ad) if (new_bat_capacity < 0) return -EINVAL; change_lowbat_level(new_bat_capacity); + battery_level_send_system_event(new_bat_capacity); if (new_bat_capacity != cur_bat_capacity) { _D("[BAT_MON] cur = %d new = %d", cur_bat_capacity, new_bat_capacity); @@ -532,6 +568,7 @@ static int check_lowbat_percent(int *pct) if (bat_percent > 100) bat_percent = 100; change_lowbat_level(bat_percent); + battery_level_send_system_event(bat_percent); *pct = bat_percent; return 0; } diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 5b4e3b8..3a8d70a 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -22,6 +22,9 @@ #include #include #include +#include +#include + #include "core/devices.h" #include "core/device-notifier.h" #include "core/udev.h" @@ -29,6 +32,7 @@ #include "core/config-parser.h" #include "display/poll.h" #include "display/setting.h" +#include "apps/apps.h" #include "power-supply.h" #include "battery.h" @@ -52,16 +56,9 @@ #define METHOD_FULL_NOTI_OFF "BatteryFullNotiOff" #define METHOD_CHARGE_NOTI_ON "BatteryChargeNotiOn" -#define CHARGE_SIOP_DISABLE_SIGNAL "SiopDisable" - #define RETRY_MAX 5 #define BATTERY_CHECK_TIMER_INTERVAL (0.5) -enum siop_disable_status_type { - SIOP_ENABLE = 0, - SIOP_DISABLE = 1, -}; - enum power_supply_init_type { POWER_SUPPLY_NOT_READY = 0, POWER_SUPPLY_INITIALIZED = 1, @@ -73,7 +70,6 @@ static const struct uevent_handler uh = { .uevent_func = uevent_power_handler, }; -static int siop_disable = SIOP_ENABLE; struct battery_status battery; static int noti_id; static Ecore_Timer *power_timer; @@ -101,16 +97,15 @@ static void pm_check_and_change(int bInserted) static int changed_battery_cf(enum present_type status) { - int ret; + char *value; - if (status != PRESENT_ABNORMAL) - return 0; - - ret = manage_notification("Battery disconnect", "Battery disconnect"); - if (ret < 0) - return -1; + if (status == PRESENT_ABNORMAL) + value = "battdisconnect"; + else + value = "remove_battery_popups"; - return 0; + return launch_system_app(APP_DEFAULT, + 2, APP_KEY_TYPE, value); } static void abnormal_popup_timer_init(void) @@ -142,7 +137,6 @@ static Eina_Bool health_timer_cb(void *data) return EINA_FALSE; _I("popup - Battery health status is not good"); - siop_disable = SIOP_DISABLE; device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)HEALTH_BAD); pm_change_internal(getpid(), LCD_NORMAL); pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, 0); @@ -351,6 +345,38 @@ static void check_power_supply(int state) update_pm_setting(SETTING_CHARGING, state); } +static void charger_state_send_system_event(int state) +{ + bundle *b; + const char *str; + + switch (state) { + case CHARGE_STATUS_CHARGING: + str = EVT_VAL_BATTERY_CHARGER_CHARGING; + break; + case CHARGE_STATUS_FULL: + case CHARGE_STATUS_DISCHARGING: + str = EVT_VAL_BATTERY_CHARGER_DISCHARGING; + break; + case CHARGE_STATUS_CONNECTED: + str = EVT_VAL_BATTERY_CHARGER_CONNECTED; + break; + case CHARGE_STATUS_DISCONNECTED: + str = EVT_VAL_BATTERY_CHARGER_DISCONNECTED; + break; + default: + _E("invalid parameter(%d)", state); + return; + } + + _D("system_event(%s)", str); + + b = bundle_create(); + bundle_add_str(b, EVT_KEY_BATTERY_CHARGER_STATUS, str); + eventsystem_send_system_event(SYS_EVENT_BATTERY_CHARGER_STATUS, b); + bundle_free(b); +} + static void update_present(enum battery_noti_status status) { static int old = DEVICE_NOTI_OFF; @@ -385,7 +411,6 @@ static void update_health(enum battery_noti_status status) pm_change_internal(getpid(), LCD_NORMAL); if (status == DEVICE_NOTI_ON) { _I("popup - Battery health status is not good"); - siop_disable = SIOP_DISABLE; device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)HEALTH_BAD); pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, 0); if (battery.temp == TEMP_LOW) @@ -393,7 +418,6 @@ static void update_health(enum battery_noti_status status) else if (battery.temp == TEMP_HIGH) battery_charge_err_high_act(NULL); } else { - siop_disable = SIOP_ENABLE; device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)HEALTH_GOOD); pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, PM_SLEEP_MARGIN); health_status_broadcast(); @@ -457,6 +481,13 @@ static void check_battery_status(void) static void check_online(void) { static int old_online; + static int old_charge_status; + int charge_status; + + if (battery.charge_status == CHARGE_STATUS_FULL) + charge_status = CHARGE_STATUS_DISCHARGING; + else + charge_status = battery.charge_status; if (battery.online > POWER_SUPPLY_TYPE_BATTERY && old_online == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED) { @@ -464,33 +495,60 @@ static void check_online(void) vconf_set_int(VCONFKEY_SYSMAN_CHARGER_STATUS, old_online); power_supply_broadcast(CHARGER_STATUS_SIGNAL, old_online); check_power_supply(old_online); + charger_state_send_system_event(CHARGE_STATUS_CONNECTED); + if (charge_status != old_charge_status) + charger_state_send_system_event(charge_status); + } else if (battery.online <= POWER_SUPPLY_TYPE_BATTERY && old_online == VCONFKEY_SYSMAN_CHARGER_CONNECTED) { old_online = VCONFKEY_SYSMAN_CHARGER_DISCONNECTED; vconf_set_int(VCONFKEY_SYSMAN_CHARGER_STATUS, old_online); power_supply_broadcast(CHARGER_STATUS_SIGNAL, old_online); check_power_supply(old_online); + if (charge_status != old_charge_status) + charger_state_send_system_event(charge_status); + charger_state_send_system_event(CHARGE_STATUS_DISCONNECTED); + + } else { + if (charge_status != old_charge_status) + charger_state_send_system_event(charge_status); } + + old_charge_status = charge_status; } static void check_charge_status(const char *env_value) { if (env_value == NULL) return; + + _D("Charge Status(%s)", env_value); + if (strncmp(env_value, CHARGEFULL_NAME, - sizeof(CHARGEFULL_NAME)) == 0) { + sizeof(CHARGEFULL_NAME)) == 0) + battery.charge_status = CHARGE_STATUS_FULL; + else if (strncmp(env_value, CHARGENOW_NAME, + sizeof(CHARGENOW_NAME)) == 0) + battery.charge_status = CHARGE_STATUS_CHARGING; + else if (strncmp(env_value, DISCHARGE_NAME, + sizeof(DISCHARGE_NAME)) == 0) + battery.charge_status = CHARGE_STATUS_DISCHARGING; + else if (strncmp(env_value, NOTCHARGE_NAME, + sizeof(NOTCHARGE_NAME)) == 0) + battery.charge_status = CHARGE_STATUS_NOT_CHARGING; + else + battery.charge_status = CHARGE_STATUS_UNKNOWN; + + if (battery.charge_status == CHARGE_STATUS_FULL) { battery.charge_full = CHARGING_FULL; battery.charge_now = CHARGER_DISCHARGING; - } else if (strncmp(env_value, CHARGENOW_NAME, - sizeof(CHARGENOW_NAME)) == 0) { + } else if (battery.charge_status == CHARGE_STATUS_CHARGING) { battery.charge_full = CHARGING_NOT_FULL; battery.charge_now = CHARGER_CHARGING; - } else if (strncmp(env_value, DISCHARGE_NAME, - sizeof(DISCHARGE_NAME)) == 0) { + } else if (battery.charge_status == CHARGE_STATUS_DISCHARGING) { battery.charge_full = CHARGING_NOT_FULL; battery.charge_now = CHARGER_DISCHARGING; - } else if (strncmp(env_value, NOTCHARGE_NAME, - sizeof(NOTCHARGE_NAME)) == 0) { + } else if (battery.charge_status == CHARGE_STATUS_NOT_CHARGING) { battery.charge_full = CHARGING_NOT_FULL; battery.charge_now = CHARGER_ABNORMAL; } else { @@ -568,6 +626,7 @@ static void process_power_supply(void *data) old.capacity = battery.capacity; old.online = battery.online; + old.charge_status = battery.charge_status; old.charge_now = battery.charge_now; old.charge_full = battery.charge_full; @@ -666,10 +725,7 @@ static void power_supply_status_init(void) capacity == battery.capacity) return; - if (charge_now != battery.charge_now || - charge_full != battery.charge_full || - capacity != battery.capacity) - _I("charging %d full %d capacity %d", battery.charge_now, battery.charge_full, battery.capacity); + _I("charging %d full %d capacity %d", battery.charge_now, battery.charge_full, battery.capacity); if (charge_now != battery.charge_now) { vconf_set_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, battery.charge_now); @@ -812,20 +868,6 @@ static DBusMessage *dbus_get_health(E_DBus_Object *obj, DBusMessage *msg) return reply; } -static DBusMessage *dbus_get_siop_disable_status(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - int ret; - - ret = siop_disable; - - reply = dbus_message_new_method_return(msg); - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); - return reply; -} - static DBusMessage *dbus_power_supply_handler(E_DBus_Object *obj, DBusMessage *msg) { DBusError err; @@ -901,7 +943,6 @@ static const struct edbus_method edbus_methods[] = { { CHARGE_CAPACITY_LAW_SIGNAL, NULL, "i", dbus_get_percent_raw }, { CHARGE_FULL_SIGNAL, NULL, "i", dbus_is_full }, { CHARGE_HEALTH_SIGNAL, NULL, "i", dbus_get_health }, - { CHARGE_SIOP_DISABLE_SIGNAL, NULL, "i", dbus_get_siop_disable_status }, { POWER_SUBSYSTEM, "sisssss", "i", dbus_power_supply_handler }, }; diff --git a/src/battery/power-supply.h b/src/battery/power-supply.h index 387af81..47df1e2 100644 --- a/src/battery/power-supply.h +++ b/src/battery/power-supply.h @@ -25,6 +25,15 @@ enum device_change_type { DEVICE_CHANGE_NORMAL = 1, }; +enum charge_status_type { + CHARGE_STATUS_UNKNOWN, + CHARGE_STATUS_DISCONNECTED, + CHARGE_STATUS_CONNECTED, + CHARGE_STATUS_CHARGING, + CHARGE_STATUS_DISCHARGING, + CHARGE_STATUS_NOT_CHARGING, + CHARGE_STATUS_FULL, +}; enum charge_full_type { CHARGING_NOT_FULL = 0, CHARGING_FULL = 1, @@ -68,6 +77,7 @@ enum battery_noti_status { struct battery_status { int capacity; + int charge_status; int charge_full; int charge_now; int health; diff --git a/src/core/udev.h b/src/core/udev.h index f6aa3f8..e3f4ac6 100644 --- a/src/core/udev.h +++ b/src/core/udev.h @@ -34,8 +34,6 @@ #define POWER_PATH "/sys/class/power_supply/battery" #define POWER_SUPPLY_UEVENT POWER_PATH"/uevent" #define CAPACITY "POWER_SUPPLY_CAPACITY" -#define CHARGE_FULL "POWER_SUPPLY_CHARGE_FULL" -#define CHARGE_NOW "POWER_SUPPLY_CHARGE_NOW" #define CHARGE_HEALTH "POWER_SUPPLY_HEALTH" #define CHARGE_PRESENT "POWER_SUPPLY_PRESENT" #define CHARGE_NAME "POWER_SUPPLY_NAME" -- 2.7.4