From 0a409a7bce9c77cced95c8cb7e3883905b761f31 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Fri, 3 Apr 2015 16:35:14 +0900 Subject: [PATCH 01/16] extcon: Do not invoke the update() if the status is the same as before Do not invoke the update func. if the status is the same as before. And do not printout error logs for not matched device. The information of not matched device is already printed out on booting time. So it's redundant logs. Change-Id: I8bd2696036bb4633eb05a128d5a9de46dc35fed1 Signed-off-by: Jiyoung Yun --- src/extcon/cradle.c | 2 +- src/extcon/earjack.c | 2 +- src/extcon/extcon.c | 9 ++++++--- src/extcon/extcon.h | 11 +++++++++-- src/extcon/hdmi.c | 2 +- src/usb/usb.c | 2 +- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/extcon/cradle.c b/src/extcon/cradle.c index 6b4d6b2..6aabe5f 100644 --- a/src/extcon/cradle.c +++ b/src/extcon/cradle.c @@ -121,4 +121,4 @@ static struct extcon_ops cradle_extcon_ops = { .update = cradle_update, }; -EXTCON_OPS_REGISTER(&cradle_extcon_ops); +EXTCON_OPS_REGISTER(cradle_extcon_ops) diff --git a/src/extcon/earjack.c b/src/extcon/earjack.c index db2118c..c5deaeb 100644 --- a/src/extcon/earjack.c +++ b/src/extcon/earjack.c @@ -58,4 +58,4 @@ static struct extcon_ops earjack_extcon_ops = { .update = earjack_update, }; -EXTCON_OPS_REGISTER(&earjack_extcon_ops) +EXTCON_OPS_REGISTER(earjack_extcon_ops) diff --git a/src/extcon/extcon.c b/src/extcon/extcon.c index 3285aab..80ef738 100755 --- a/src/extcon/extcon.c +++ b/src/extcon/extcon.c @@ -85,12 +85,15 @@ static int extcon_update(const char *name, const char *value) return -EINVAL; dev = find_extcon(name); - if (!dev) { - _E("fail to find matched extcon device : name(%s)", name); + if (!dev) return -EINVAL; - } status = atoi(value); + + /* Do not invoke update func. if it's the same value */ + if (dev->status == status) + return 0; + _I("Changed %s device : %d -> %d", name, dev->status, status); dev->status = status; diff --git a/src/extcon/extcon.h b/src/extcon/extcon.h index b06c629..eb10fc9 100755 --- a/src/extcon/extcon.h +++ b/src/extcon/extcon.h @@ -45,11 +45,18 @@ struct extcon_ops { #define EXTCON_OPS_REGISTER(dev) \ static void __CONSTRUCTOR__ extcon_init(void) \ { \ - add_extcon(dev); \ + /** + * If there is no predefined status value, + * default status will set as a negative value(-1). + * It will be updated as the initial value in booting time. + */ \ + if (!dev.status) \ + dev.status = -1; \ + add_extcon(&dev); \ } \ static void __DESTRUCTOR__ extcon_exit(void) \ { \ - remove_extcon(dev); \ + remove_extcon(&dev); \ } void add_extcon(struct extcon_ops *dev); diff --git a/src/extcon/hdmi.c b/src/extcon/hdmi.c index 29fc511..5a6a1d8 100644 --- a/src/extcon/hdmi.c +++ b/src/extcon/hdmi.c @@ -118,4 +118,4 @@ static struct extcon_ops hdmi_extcon_ops = { .update = hdmi_update, }; -EXTCON_OPS_REGISTER(&hdmi_extcon_ops); +EXTCON_OPS_REGISTER(hdmi_extcon_ops) diff --git a/src/usb/usb.c b/src/usb/usb.c index 44d5d2d..c122ae9 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -206,4 +206,4 @@ struct extcon_ops extcon_usb_ops = { .update = usb_state_changed, }; -EXTCON_OPS_REGISTER(&extcon_usb_ops) +EXTCON_OPS_REGISTER(extcon_usb_ops) -- 2.7.4 From aac4d99eaa44340e8d283d19a2efeb1a9a4fe804 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Fri, 3 Apr 2015 17:46:51 +0900 Subject: [PATCH 02/16] udev: Change the device-change-handler to udev module Sliding keyboard and tvout is not supported currently. These logic will add as per the common kernel interface. Change the device-change-handler to udev module. And remove the unnecessary codes and defines. Remove device-handler.h file. Change-Id: Iecb44fd52cafd7fc3708f3834eecf4f3e7b1df12 Signed-off-by: Jiyoung Yun --- CMakeLists.txt | 2 +- src/battery/lowbat-handler.c | 1 - src/battery/power-supply.c | 3 +- src/core/device-change-handler.c | 631 --------------------------------------- src/core/device-handler.h | 31 -- src/core/udev.c | 342 +++++++++++++++++++++ src/core/udev.h | 16 +- src/display/core.c | 1 - src/display/key-filter.c | 1 - src/display/poll.c | 1 - src/extcon/cradle.c | 2 +- src/extcon/earjack.c | 2 +- src/mmc/mmc-handler.c | 1 - src/power/power-handler.c | 1 - 14 files changed, 351 insertions(+), 684 deletions(-) delete mode 100644 src/core/device-change-handler.c delete mode 100644 src/core/device-handler.h create mode 100644 src/core/udev.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d0aa63..10e7be6 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,6 @@ SET(SRCS src/core/common.c src/core/config-parser.c src/control/control.c - src/core/device-change-handler.c src/core/device-notifier.c src/core/devices.c src/core/edbus-handler.c @@ -33,6 +32,7 @@ SET(SRCS src/core/log.c src/core/main.c src/core/sig-handler.c + src/core/udev.c src/extcon/cradle.c src/extcon/earjack.c src/extcon/extcon.c diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 52baa79..ede215d 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -28,7 +28,6 @@ #include "core/log.h" #include "core/launch.h" #include "core/devices.h" -#include "core/device-handler.h" #include "core/device-notifier.h" #include "core/common.h" #include "core/list.h" diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index f63b7da..ea03b1b 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -23,7 +23,6 @@ #include #include #include "core/devices.h" -#include "core/device-handler.h" #include "core/device-notifier.h" #include "core/udev.h" #include "core/log.h" @@ -85,7 +84,7 @@ static void pm_check_and_change(int bInserted) static int old = -1; if (old != bInserted) { old = bInserted; - internal_pm_change_state(LCD_NORMAL); + pm_change_internal(getpid(), LCD_NORMAL); } } diff --git a/src/core/device-change-handler.c b/src/core/device-change-handler.c deleted file mode 100644 index 622d4d1..0000000 --- a/src/core/device-change-handler.c +++ /dev/null @@ -1,631 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "dd-deviced.h" -#include "log.h" -#include "device-notifier.h" -#include "device-handler.h" -#include "device-node.h" -#include "display/poll.h" -#include "devices.h" -#include "udev.h" -#include "common.h" -#include "list.h" -#include "proc/proc-handler.h" -#include "edbus-handler.h" -#include "devices.h" -#include "display/setting.h" -#include "display/core.h" -#include "extcon/extcon.h" - -#define PREDEF_DEVICE_CHANGED "device_changed" -#define PREDEF_POWER_CHANGED POWER_SUBSYSTEM -#define PREDEF_UDEV_CONTROL UDEV - -#define TVOUT_X_BIN "/usr/bin/xberc" -#define TVOUT_FLAG 0x00000001 - -#define MOVINAND_MOUNT_POINT "/opt/media" - -#ifdef ENABLE_EDBUS_USE -#include -static E_DBus_Connection *conn; -#endif /* ENABLE_EDBUS_USE */ - -enum snd_jack_types { - SND_JACK_HEADPHONE = 0x0001, - SND_JACK_MICROPHONE = 0x0002, - SND_JACK_HEADSET = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE, - SND_JACK_LINEOUT = 0x0004, - SND_JACK_MECHANICAL = 0x0008, /* If detected separately */ - SND_JACK_VIDEOOUT = 0x0010, - SND_JACK_AVOUT = SND_JACK_LINEOUT | SND_JACK_VIDEOOUT, -}; - -#define CHANGE_ACTION "change" -#define ENV_FILTER "CHGDET" - -#define TVOUT_NAME "tvout" -#define TVOUT_NAME_LEN 5 - -#define KEYBOARD_NAME "keyboard" -#define KEYBOARD_NAME_LEN 8 - -struct ticker_data { - char *name; - int type; -}; - -struct siop_data { - int siop; - int rear; -}; - -static int ss_flags = 0; - -/* Uevent */ -static struct udev *udev = NULL; -/* Kernel Uevent */ -static struct udev_monitor *mon = NULL; -static Ecore_Fd_Handler *ufdh = NULL; -static int ufd = -1; - -enum udev_subsystem_type { - UDEV_PLATFORM, - UDEV_SWITCH, -}; - -static const struct udev_subsystem { - const enum udev_subsystem_type type; - const char *str; - const char *devtype; -} udev_subsystems[] = { - { UDEV_PLATFORM, PLATFORM_SUBSYSTEM, NULL }, - { UDEV_SWITCH, SWITCH_SUBSYSTEM, NULL }, -}; - -static dd_list *udev_event_list; - -static void tvout_chgdet_cb(void *data) -{ - _I("jack - tvout changed"); - pm_change_internal(getpid(), LCD_NORMAL); -} - -static void keyboard_chgdet_cb(void *data) -{ - int val = -1; - int ret = 0; - - if (data) - val = *(int *)data; - else { - ret = device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_KEYBOARD_ONLINE, &val); - if (ret != 0) { - _E("failed to get status"); - vconf_set_int(VCONFKEY_SYSMAN_SLIDING_KEYBOARD, VCONFKEY_SYSMAN_SLIDING_KEYBOARD_NOT_SUPPORTED); - return; - } - } - _I("jack - keyboard changed %d", val); - if(val != 1) - val = 0; - vconf_set_int(VCONFKEY_SYSMAN_SLIDING_KEYBOARD, val); -} - -static void ums_unmount_cb(void *data) -{ - umount(MOVINAND_MOUNT_POINT); -} - -#ifdef ENABLE_EDBUS_USE -static void cb_xxxxx_signaled(void *data, DBusMessage * msg) -{ - char *args; - DBusError err; - - dbus_error_init(&err); - if (dbus_message_get_args - (msg, &err, DBUS_TYPE_STRING, &args, DBUS_TYPE_INVALID)) { - if (!strcmp(args, "action")) ; /* action */ - } - - return; -} -#endif /* ENABLE_EDBUS_USE */ - -static int siop_execute(const char *siop, const char *rear) -{ - static const struct device_ops *ops = NULL; - struct siop_data params; - - FIND_DEVICE_INT(ops, PROC_OPS_NAME); - - if (!siop) - params.siop = 0; - else - params.siop = atoi(siop); - if (!rear) - params.rear = 0; - else - params.rear = atoi(rear); - return ops->execute((void *)¶ms); -} - -static int changed_device(const char *name, const char *value) -{ - int val = 0; - int *state = NULL; - int i; - - if (!name) - goto out; - - if (value) { - val = atoi(value); - state = &val; - } - - if (strncmp(name, TVOUT_NAME, TVOUT_NAME_LEN) == 0) - tvout_chgdet_cb((void *)state); - else if (strncmp(name, KEYBOARD_NAME, KEYBOARD_NAME_LEN) == 0) - keyboard_chgdet_cb((void *)state); -out: - return 0; -} - -static int booting_done(void *data) -{ - static int done = 0; - int ret; - int val; - - if (data == NULL) - return done; - done = *(int*)data; - if (done == 0) - return done; - - _I("booting done"); - - /* set initial state for devices */ - keyboard_chgdet_cb(NULL); - return done; -} - -static Eina_Bool uevent_kernel_control_cb(void *data, Ecore_Fd_Handler *fd_handler) -{ - struct udev_device *dev = NULL; - struct udev_list_entry *list_entry = NULL; - struct uevent_handler *l; - dd_list *elem; - const char *subsystem = NULL; - const char *env_name = NULL; - const char *env_value = NULL; - const char *devpath; - const char *devnode; - const char *action; - int ret = -1; - int i, len; - - if ((dev = udev_monitor_receive_device(mon)) == NULL) - return EINA_TRUE; - - subsystem = udev_device_get_subsystem(dev); - - for (i = 0; i < ARRAY_SIZE(udev_subsystems); i++) { - len = strlen(udev_subsystems[i].str); - if (!strncmp(subsystem, udev_subsystems[i].str, len)) - break; - } - - if (i >= ARRAY_SIZE(udev_subsystems)) - goto out; - - devpath = udev_device_get_devpath(dev); - - switch (udev_subsystems[i].type) { - case UDEV_SWITCH: - env_name = udev_device_get_property_value(dev, "SWITCH_NAME"); - env_value = udev_device_get_property_value(dev, "SWITCH_STATE"); - changed_device(env_name, env_value); - break; - case UDEV_PLATFORM: - env_value = udev_device_get_property_value(dev, ENV_FILTER); - if (!env_value) - break; - changed_device(env_value, NULL); - break; - } - -out: - - DD_LIST_FOREACH(udev_event_list, elem, l) { - if (!strncmp(subsystem, l->subsystem, strlen(subsystem)) && - l->uevent_func) - l->uevent_func(dev); - } - - udev_device_unref(dev); - return EINA_TRUE; -} - -static int uevent_kernel_control_stop(void) -{ - struct udev_device *dev = NULL; - - if (ufdh) { - ecore_main_fd_handler_del(ufdh); - ufdh = NULL; - } - if (ufd >= 0) { - close(ufd); - ufd = -1; - } - if (mon) { - dev = udev_monitor_receive_device(mon); - if (dev) { - udev_device_unref(dev); - dev = NULL; - } - udev_monitor_unref(mon); - mon = NULL; - } - if (udev) { - udev_unref(udev); - udev = NULL; - } - return 0; -} - -static int uevent_kernel_control_start(void) -{ - struct uevent_handler *l; - dd_list *elem; - int i, ret; - - if (udev && mon) { - _E("uevent control routine is alreay started"); - return -EINVAL; - } - - if (!udev) { - udev = udev_new(); - if (!udev) { - _E("error create udev"); - return -EINVAL; - } - } - - mon = udev_monitor_new_from_netlink(udev, UDEV); - if (mon == NULL) { - _E("error udev_monitor create"); - goto stop; - } - - if (udev_monitor_set_receive_buffer_size(mon, UDEV_MONITOR_SIZE) != 0) { - _E("fail to set receive buffer size"); - goto stop; - } - - for (i = 0; i < ARRAY_SIZE(udev_subsystems); i++) { - ret = udev_monitor_filter_add_match_subsystem_devtype(mon, - udev_subsystems[i].str, udev_subsystems[i].devtype); - if (ret < 0) { - _E("error apply subsystem filter"); - goto stop; - } - } - - DD_LIST_FOREACH(udev_event_list, elem, l) { - ret = udev_monitor_filter_add_match_subsystem_devtype(mon, - l->subsystem, NULL); - if (ret < 0) { - _E("error apply subsystem filter"); - goto stop; - } - } - - ret = udev_monitor_filter_update(mon); - if (ret < 0) - _E("error udev_monitor_filter_update"); - - ufd = udev_monitor_get_fd(mon); - if (ufd == -1) { - _E("error udev_monitor_get_fd"); - goto stop; - } - - ufdh = ecore_main_fd_handler_add(ufd, ECORE_FD_READ, - uevent_kernel_control_cb, NULL, NULL, NULL); - if (!ufdh) { - _E("error ecore_main_fd_handler_add"); - goto stop; - } - - if (udev_monitor_enable_receiving(mon) < 0) { - _E("error unable to subscribe to udev events"); - goto stop; - } - - return 0; -stop: - uevent_kernel_control_stop(); - return -EINVAL; - -} - -int register_kernel_uevent_control(const struct uevent_handler *uh) -{ - struct uevent_handler *l; - dd_list *elem; - int r; - bool matched = false; - - if (!uh) - return -EINVAL; - - /* if udev is not initialized, it just will be added list */ - if (!udev || !mon) - goto add_list; - - /* check if the same subsystem is already added */ - DD_LIST_FOREACH(udev_event_list, elem, l) { - if (!strncmp(l->subsystem, uh->subsystem, strlen(l->subsystem))) { - matched = true; - break; - } - } - - /* the first request to add subsystem */ - if (!matched) { - r = udev_monitor_filter_add_match_subsystem_devtype(mon, - uh->subsystem, NULL); - if (r < 0) { - _E("fail to add %s subsystem : %d", uh->subsystem, r); - return -EPERM; - } - } - - r = udev_monitor_filter_update(mon); - if (r < 0) - _E("fail to update udev monitor filter : %d", r); - -add_list: - DD_LIST_APPEND(udev_event_list, uh); - return 0; -} - -int unregister_kernel_uevent_control(const struct uevent_handler *uh) -{ - struct uevent_handler *l; - dd_list *n, *next; - - DD_LIST_FOREACH_SAFE(udev_event_list, n, next, l) { - if (!strncmp(l->subsystem, uh->subsystem, strlen(l->subsystem)) && - l->uevent_func == uh->uevent_func) { - DD_LIST_REMOVE(udev_event_list, l); - return 0; - } - } - - return -ENOENT; -} - -int uevent_udev_get_path(const char *subsystem, dd_list **list) -{ - struct udev_enumerate *enumerate = NULL; - struct udev_list_entry *devices, *dev_list_entry; - int ret; - - if (!udev) { - udev = udev_new(); - if (!udev) { - _E("error create udev"); - return -EIO; - } - } - - enumerate = udev_enumerate_new(udev); - if (!enumerate) - return -EIO; - - ret = udev_enumerate_add_match_subsystem(enumerate, subsystem); - if (ret < 0) - return -EIO; - - ret = udev_enumerate_scan_devices(enumerate); - if (ret < 0) - return -EIO; - - devices = udev_enumerate_get_list_entry(enumerate); - - udev_list_entry_foreach(dev_list_entry, devices) { - const char *path; - path = udev_list_entry_get_name(dev_list_entry); - _D("subsystem : %s, path : %s", subsystem, path); - DD_LIST_APPEND(*list, (void*)path); - } - - return 0; -} - -static DBusMessage *dbus_device_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[2]; - - dbus_error_init(&err); - - if (!dbus_message_get_args(msg, &err, - DBUS_TYPE_STRING, &type_str, - DBUS_TYPE_INT32, &argc, - DBUS_TYPE_STRING, &argv[0], - DBUS_TYPE_STRING, &argv[1], 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; - } - - changed_device(argv[0], argv[1]); - -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_udev_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(argv, "start", strlen("start")) == 0) { - uevent_kernel_control_start(); - } else if (strncmp(argv, "stop", strlen("stop")) == 0) { - uevent_kernel_control_stop(); - } - -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; -} - -void internal_pm_change_state(unsigned int s_bits) -{ - pm_change_internal(getpid(), s_bits); -} - -static const struct edbus_method edbus_methods[] = { - { PREDEF_DEVICE_CHANGED, "siss", "i", dbus_device_handler }, - { PREDEF_UDEV_CONTROL, "sis","i", dbus_udev_handler }, -}; - -static int device_change_poweroff(void *data) -{ - uevent_kernel_control_stop(); - return 0; -} - -static void device_change_init(void *data) -{ - int ret; - - register_notifier(DEVICE_NOTIFIER_POWEROFF, device_change_poweroff); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); - ret = register_edbus_method(DEVICED_PATH_SYSNOTI, edbus_methods, ARRAY_SIZE(edbus_methods)); - if (ret < 0) - _E("fail to init edbus method(%d)", ret); - - /* dbus noti change cb */ -#ifdef ENABLE_EDBUS_USE - e_dbus_init(); - conn = e_dbus_bus_get(DBUS_BUS_SYSTEM); - if (!conn) - _E("check system dbus running!\n"); - - e_dbus_signal_handler_add(conn, NULL, "/system/uevent/xxxxx", - "system.uevent.xxxxx", - "Change", cb_xxxxx_signaled, data); -#endif /* ENABLE_EDBUS_USE */ - if (uevent_kernel_control_start() != 0) { - _E("fail uevent control init"); - return; - } -} - -static void device_change_exit(void *data) -{ - unregister_notifier(DEVICE_NOTIFIER_POWEROFF, device_change_poweroff); - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); -} - -static const struct device_ops change_device_ops = { - .priority = DEVICE_PRIORITY_NORMAL, - .name = "device change", - .init = device_change_init, - .exit = device_change_exit, -}; - -DEVICE_OPS_REGISTER(&change_device_ops) diff --git a/src/core/device-handler.h b/src/core/device-handler.h deleted file mode 100644 index 64db56d..0000000 --- a/src/core/device-handler.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 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 __DEVICE_HANDLER_H__ -#define __DEVICE_HANDLER_H__ - -#include "common.h" - -enum dock_type { - DOCK_NONE = 0, - DOCK_SOUND = 7, -}; - -void internal_pm_change_state(unsigned int s_bits); -#endif /* __DEVICE_HANDLER_H__ */ diff --git a/src/core/udev.c b/src/core/udev.c new file mode 100644 index 0000000..2180d2b --- /dev/null +++ b/src/core/udev.c @@ -0,0 +1,342 @@ +/* + * deviced + * + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include + +#include "log.h" +#include "device-notifier.h" +#include "devices.h" +#include "udev.h" +#include "list.h" +#include "edbus-handler.h" + +#define PREDEF_UDEV_CONTROL UDEV + +/* Uevent */ +static struct udev *udev; +/* Kernel Uevent */ +static struct udev_monitor *mon; +static Ecore_Fd_Handler *ufdh; +static int ufd = -1; + +static dd_list *udev_event_list; + +static Eina_Bool uevent_kernel_control_cb(void *data, Ecore_Fd_Handler *fd_handler) +{ + struct udev_device *dev; + struct uevent_handler *l; + dd_list *elem; + const char *subsystem; + + if ((dev = udev_monitor_receive_device(mon)) == NULL) + return EINA_TRUE; + + subsystem = udev_device_get_subsystem(dev); + + DD_LIST_FOREACH(udev_event_list, elem, l) { + if (!strncmp(subsystem, l->subsystem, strlen(subsystem)) && + l->uevent_func) + l->uevent_func(dev); + } + + udev_device_unref(dev); + return EINA_TRUE; +} + +static int uevent_kernel_control_stop(void) +{ + struct udev_device *dev = NULL; + + if (ufdh) { + ecore_main_fd_handler_del(ufdh); + ufdh = NULL; + } + if (ufd >= 0) { + close(ufd); + ufd = -1; + } + if (mon) { + dev = udev_monitor_receive_device(mon); + if (dev) { + udev_device_unref(dev); + dev = NULL; + } + udev_monitor_unref(mon); + mon = NULL; + } + if (udev) { + udev_unref(udev); + udev = NULL; + } + return 0; +} + +static int uevent_kernel_control_start(void) +{ + struct uevent_handler *l; + dd_list *elem; + int i, ret; + + if (udev && mon) { + _E("uevent control routine is alreay started"); + return -EINVAL; + } + + if (!udev) { + udev = udev_new(); + if (!udev) { + _E("error create udev"); + return -EINVAL; + } + } + + mon = udev_monitor_new_from_netlink(udev, UDEV); + if (mon == NULL) { + _E("error udev_monitor create"); + goto stop; + } + + if (udev_monitor_set_receive_buffer_size(mon, UDEV_MONITOR_SIZE) != 0) { + _E("fail to set receive buffer size"); + goto stop; + } + + DD_LIST_FOREACH(udev_event_list, elem, l) { + ret = udev_monitor_filter_add_match_subsystem_devtype(mon, + l->subsystem, NULL); + if (ret < 0) { + _E("error apply subsystem filter"); + goto stop; + } + } + + ret = udev_monitor_filter_update(mon); + if (ret < 0) + _E("error udev_monitor_filter_update"); + + ufd = udev_monitor_get_fd(mon); + if (ufd == -1) { + _E("error udev_monitor_get_fd"); + goto stop; + } + + ufdh = ecore_main_fd_handler_add(ufd, ECORE_FD_READ, + uevent_kernel_control_cb, NULL, NULL, NULL); + if (!ufdh) { + _E("error ecore_main_fd_handler_add"); + goto stop; + } + + if (udev_monitor_enable_receiving(mon) < 0) { + _E("error unable to subscribe to udev events"); + goto stop; + } + + return 0; +stop: + uevent_kernel_control_stop(); + return -EINVAL; + +} + +int register_kernel_uevent_control(const struct uevent_handler *uh) +{ + struct uevent_handler *l; + dd_list *elem; + int r; + bool matched = false; + + if (!uh) + return -EINVAL; + + /* if udev is not initialized, it just will be added list */ + if (!udev || !mon) + goto add_list; + + /* check if the same subsystem is already added */ + DD_LIST_FOREACH(udev_event_list, elem, l) { + if (!strncmp(l->subsystem, uh->subsystem, strlen(l->subsystem))) { + matched = true; + break; + } + } + + /* the first request to add subsystem */ + if (!matched) { + r = udev_monitor_filter_add_match_subsystem_devtype(mon, + uh->subsystem, NULL); + if (r < 0) { + _E("fail to add %s subsystem : %d", uh->subsystem, r); + return -EPERM; + } + } + + r = udev_monitor_filter_update(mon); + if (r < 0) + _E("fail to update udev monitor filter : %d", r); + +add_list: + DD_LIST_APPEND(udev_event_list, uh); + return 0; +} + +int unregister_kernel_uevent_control(const struct uevent_handler *uh) +{ + struct uevent_handler *l; + dd_list *n, *next; + + DD_LIST_FOREACH_SAFE(udev_event_list, n, next, l) { + if (!strncmp(l->subsystem, uh->subsystem, strlen(l->subsystem)) && + l->uevent_func == uh->uevent_func) { + DD_LIST_REMOVE(udev_event_list, l); + return 0; + } + } + + return -ENOENT; +} + +int uevent_udev_get_path(const char *subsystem, dd_list **list) +{ + struct udev_enumerate *enumerate = NULL; + struct udev_list_entry *devices, *dev_list_entry; + int ret; + + if (!udev) { + udev = udev_new(); + if (!udev) { + _E("error create udev"); + return -EIO; + } + } + + enumerate = udev_enumerate_new(udev); + if (!enumerate) + return -EIO; + + ret = udev_enumerate_add_match_subsystem(enumerate, subsystem); + if (ret < 0) + return -EIO; + + ret = udev_enumerate_scan_devices(enumerate); + if (ret < 0) + return -EIO; + + devices = udev_enumerate_get_list_entry(enumerate); + + udev_list_entry_foreach(dev_list_entry, devices) { + const char *path; + path = udev_list_entry_get_name(dev_list_entry); + _D("subsystem : %s, path : %s", subsystem, path); + DD_LIST_APPEND(*list, (void*)path); + } + + return 0; +} + +static DBusMessage *dbus_udev_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(argv, "start", strlen("start")) == 0) { + ret = uevent_kernel_control_start(); + } else if (strncmp(argv, "stop", strlen("stop")) == 0) { + ret = uevent_kernel_control_stop(); + } + +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 const struct edbus_method edbus_methods[] = { + { PREDEF_UDEV_CONTROL, "sis","i", dbus_udev_handler }, +}; + +static int device_change_poweroff(void *data) +{ + uevent_kernel_control_stop(); + return 0; +} + +static void udev_init(void *data) +{ + int ret; + + register_notifier(DEVICE_NOTIFIER_POWEROFF, device_change_poweroff); + + ret = register_edbus_method(DEVICED_PATH_SYSNOTI, + edbus_methods, ARRAY_SIZE(edbus_methods)); + if (ret < 0) + _E("fail to init edbus method(%d)", ret); + + if (uevent_kernel_control_start() != 0) { + _E("fail uevent control init"); + return; + } +} + +static void udev_exit(void *data) +{ + unregister_notifier(DEVICE_NOTIFIER_POWEROFF, device_change_poweroff); +} + +static const struct device_ops udev_device_ops = { + .priority = DEVICE_PRIORITY_NORMAL, + .name = "udev", + .init = udev_init, + .exit = udev_exit, +}; + +DEVICE_OPS_REGISTER(&udev_device_ops) diff --git a/src/core/udev.h b/src/core/udev.h index 2c56033..d8d69a6 100644 --- a/src/core/udev.h +++ b/src/core/udev.h @@ -23,9 +23,7 @@ #include #define UDEV "kernel" -#define UDEV_SUBSYSTEM "SUBSYSTEM" -#define UDEV_ACTION "ACTION" #define UDEV_CHANGE "change" #define UDEV_ADD "add" #define UDEV_REMOVE "remove" @@ -36,9 +34,6 @@ #define UDEV_MONITOR_SIZE (10*1024) #define UDEV_MONITOR_SIZE_LARGE (128*1024*1024) -/* platform */ -#define PLATFORM_SUBSYSTEM "platform" - /* battery device */ #define POWER_SUBSYSTEM "power_supply" #define POWER_PATH "/sys/class/power_supply/battery" @@ -52,15 +47,9 @@ #define CHARGE_STATUS "POWER_SUPPLY_STATUS" #define CHARGE_ONLINE "POWER_SUPPLY_ONLINE" -/* switch device */ -#define SWITCH_SUBSYSTEM "switch" - /* extcon */ #define EXTCON_SUBSYSTEM "extcon" -/* host device */ -#define HOST_SUBSYSTEM "host_notify" - /* usb */ #define USB_SUBSYSTEM "usb" #define USB_INTERFACE_DEVTYPE "usb_interface" @@ -85,6 +74,11 @@ enum { POWER_SUPPLY_TYPE_USB, }; +enum dock_type { + DOCK_NONE = 0, + DOCK_SOUND = 7, +}; + struct uevent_handler { char *subsystem; void (*uevent_func)(struct udev_device *dev); diff --git a/src/display/core.c b/src/display/core.c index c4eb988..61e9cb2 100644 --- a/src/display/core.c +++ b/src/display/core.c @@ -45,7 +45,6 @@ #include "display-ops.h" #include "core/devices.h" #include "core/device-notifier.h" -#include "core/device-handler.h" #include "core/udev.h" #include "core/list.h" #include "core/common.h" diff --git a/src/display/key-filter.c b/src/display/key-filter.c index fa95a5b..c5611fa 100644 --- a/src/display/key-filter.c +++ b/src/display/key-filter.c @@ -34,7 +34,6 @@ #include "core/devices.h" #include "core/device-notifier.h" #include "core/edbus-handler.h" -#include "core/device-handler.h" #include "power/power-handler.h" #include diff --git a/src/display/poll.c b/src/display/poll.c index 9052d3c..2369777 100644 --- a/src/display/poll.c +++ b/src/display/poll.c @@ -24,7 +24,6 @@ */ #include -#include "core/device-handler.h" #include "util.h" #include "core.h" #include "poll.h" diff --git a/src/extcon/cradle.c b/src/extcon/cradle.c index 6aabe5f..70614d4 100644 --- a/src/extcon/cradle.c +++ b/src/extcon/cradle.c @@ -23,7 +23,7 @@ #include "core/log.h" #include "core/device-notifier.h" #include "core/edbus-handler.h" -#include "core/device-handler.h" +#include "core/udev.h" #include "display/core.h" #include "extcon/extcon.h" diff --git a/src/extcon/earjack.c b/src/extcon/earjack.c index c5deaeb..d63c71d 100644 --- a/src/extcon/earjack.c +++ b/src/extcon/earjack.c @@ -50,7 +50,7 @@ static int earjack_update(int status) vconf_set_int(VCONFKEY_SYSMAN_EARJACK, status); earjack_send_broadcast(status); if (status != 0) - internal_pm_change_state(LCD_NORMAL); + pm_change_internal(getpid(), LCD_NORMAL); } static struct extcon_ops earjack_extcon_ops = { diff --git a/src/mmc/mmc-handler.c b/src/mmc/mmc-handler.c index 5b2f73d..e7ca722 100644 --- a/src/mmc/mmc-handler.c +++ b/src/mmc/mmc-handler.c @@ -34,7 +34,6 @@ #include #include "core/log.h" -#include "core/device-handler.h" #include "core/device-notifier.h" #include "core/common.h" #include "core/devices.h" diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 9ae300e..a208851 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -35,7 +35,6 @@ #include "dd-deviced.h" #include "core/log.h" #include "core/launch.h" -#include "core/device-handler.h" #include "core/device-notifier.h" #include "core/common.h" #include "core/devices.h" -- 2.7.4 From 1e42bfe9023291ebc29829ec6a8ee432506fd276 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Thu, 2 Apr 2015 13:00:45 +0900 Subject: [PATCH 03/16] usb: Fix usb connection on 64bit machine In 64bit machine, sdb can't connect properly to a host. This patch fixed the issue by changing fconf value. Change-Id: Ib2c8ac40f7e8a06d93c63141b3e5c5a8945b54c7 Signed-off-by: Jiyoung Yun --- src/usb/usb-setting.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usb/usb-setting.conf b/src/usb/usb-setting.conf index 755937f..7ab4ff7 100644 --- a/src/usb/usb-setting.conf +++ b/src/usb/usb-setting.conf @@ -6,7 +6,7 @@ default=SDB [SDB] idVendor=04e8 idProduct=6860 -funcs_fconf=sdb +funcs_fconf= funcs_sconf=sdb bDeviceClass=239 bDeviceSubClass=2 -- 2.7.4 From 1755bafdcddb7514b87a1ca49ce23abe95f5b6eb Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Fri, 3 Apr 2015 20:52:12 +0900 Subject: [PATCH 04/16] deviced: Remove unused vconf key and logics Removed vconf key list: VCONFKEY_SYSMAN_MMC_DEVICE_CHANGED VCONFKEY_STARTER_SEQUENCE VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU VCONFKEY_LCD_BRIGHTNESS_INIT VCONFKEY_INTERNAL_PRIVATE_MMC_ID VCONFKEY_DEVICED_BOOT_POWER_ON_STATUS VCONFKEY_SETAPPL_ACCESSIBILITY_TTS Change-Id: Ia256ac802c65ca6c0725f1bbe690beca6802ffaf Signed-off-by: Jiyoung Yun --- packaging/deviced.spec | 12 - src/battery/lowbat-handler.c | 22 +- src/cpu/cpu-handler.c | 552 ------------------------------------------- src/display/core.c | 36 --- src/display/display-dbus.c | 7 - src/display/setting.c | 11 +- src/display/setting.h | 2 - src/mmc/ext4.c | 11 +- src/mmc/mmc-handler.c | 19 -- src/shared/dbus.h | 1 - src/storage/storage.c | 5 - 11 files changed, 6 insertions(+), 672 deletions(-) delete mode 100644 src/cpu/cpu-handler.c diff --git a/packaging/deviced.spec b/packaging/deviced.spec index cfa986a..aa02ccb 100755 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -234,35 +234,23 @@ users_gid=$(getent group %{TZ_SYS_USER_GROUP} | cut -f3 -d':') vconftool set -t int memory/sysman/usbhost_status -1 -i vconftool set -t int memory/sysman/mmc -1 -i vconftool set -t int memory/sysman/earjack_key 0 -i -vconftool set -t int memory/sysman/added_usb_storage 0 -i -vconftool set -t int memory/sysman/removed_usb_storage 0 -i vconftool set -t int memory/sysman/charger_status -1 -i vconftool set -t int memory/sysman/charge_now -1 -i vconftool set -t int memory/sysman/battery_status_low -1 -i vconftool set -t int memory/sysman/battery_capacity -1 -i vconftool set -t int memory/sysman/usb_status -1 -i vconftool set -t int memory/sysman/earjack -1 -i -vconftool set -t int memory/sysman/low_memory 1 -i -vconftool set -t int memory/sysman/sliding_keyboard -1 -i vconftool set -t int memory/sysman/mmc_mount -1 -i -vconftool set -t int memory/sysman/mmc_unmount -1 -i vconftool set -t int memory/sysman/mmc_format -1 -i vconftool set -t int memory/sysman/mmc_format_progress 0 -i -vconftool set -t int memory/sysman/mmc_err_status 0 -i vconftool set -t int memory/sysman/power_off 0 -g "$users_gid" -i -f vconftool set -t int memory/sysman/battery_level_status -1 -i -vconftool set -t string memory/private/sysman/added_storage_uevent "" -i -vconftool set -t string memory/private/sysman/removed_storage_uevent "" -g "$users_gid" -i vconftool set -t int memory/sysman/hdmi 0 -i vconftool set -t int memory/sysman/stime_changed 0 -i -#db type vconf key init -vconftool set -t int db/sysman/mmc_dev_changed 0 - vconftool set -t int memory/pm/state 0 -i -g "$users_gid" vconftool set -t int memory/pm/battery_timetofull -1 -i vconftool set -t int memory/pm/battery_timetoempty -1 -i -vconftool set -t int memory/pm/sip_status 0 -i -g "$users_gid" vconftool set -t int memory/pm/custom_brightness_status 0 -i -g "$users_gid" vconftool set -t bool memory/pm/brt_changed_lpm 0 -i vconftool set -t int memory/pm/current_brt 60 -i -g "$users_gid" diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index ede215d..cd7df77 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -173,7 +173,7 @@ out: static int lowbat_popup(char *option) { - int ret, state=0; + int ret; int r_disturb, s_disturb, r_block, s_block; int lowbat_popup_option = -1; char *value; @@ -205,8 +205,7 @@ static int lowbat_popup(char *option) return -1; _D("%s", value); - ret = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &state); - if (state == 1 || ret != 0 || booting_done(NULL)) { + if (booting_done(NULL)) { 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) || @@ -470,23 +469,6 @@ void lowbat_monitor(void *data) lowbat_process(bat_percent, NULL); } -static int check_power_save_mode(void) -{ - int ret = 0; - int power_saving_cpu_stat = -1; - - ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, - &power_saving_cpu_stat); - if (ret < 0) { - _E("failed to get vconf key"); - return ret; - } - - if (power_saving_cpu_stat == 1) - ret = 1; - return ret; -} - static int lowbat_monitor_init(void *data) { int status = 1; diff --git a/src/cpu/cpu-handler.c b/src/cpu/cpu-handler.c deleted file mode 100644 index 8724339..0000000 --- a/src/cpu/cpu-handler.c +++ /dev/null @@ -1,552 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include - -#include "core/list.h" -#include "core/log.h" -#include "core/devices.h" -#include "core/edbus-handler.h" -#include "core/common.h" -#include "core/device-notifier.h" -#include "proc/proc-handler.h" - -#define SET_MAX_FREQ "set_max_frequency" -#define SET_MIN_FREQ "set_min_frequency" -#define SET_FREQ_LEN 17 - -#define RELEASE_MAX_FREQ "release_max_frequency" -#define RELEASE_MIN_FREQ "release_min_frequency" -#define RELEASE_FREQ_LEN 21 - -#define POWER_SAVING_CPU_FREQ_RATE (0.7) - -#define DEFAULT_MAX_CPU_FREQ 1200000 -#define DEFAULT_MIN_CPU_FREQ 100000 - -enum emergency_type { - EMERGENCY_UNLOCK = 0, - EMERGENCY_LOCK = 1, -}; - -static int max_cpu_freq_limit = -1; -static int min_cpu_freq_limit = -1; -static int cur_max_cpu_freq = INT_MAX; -static int cur_min_cpu_freq = INT_MIN; -static int power_saving_freq = -1; - -static dd_list *max_cpu_freq_list; -static dd_list *min_cpu_freq_list; - -static int cpu_number_limit = -1; -static int cur_cpu_number = INT_MAX; -static dd_list *cpu_number_list; - -struct cpu_freq_entry { - int pid; - int freq; -}; - -struct cpu_number_entry { - int pid; - int number; -}; - -static int is_entry_enable(int pid) -{ - char pid_path[PATH_MAX]; - - snprintf(pid_path, PATH_MAX, "/proc/%d", pid); - if (access(pid_path, F_OK) < 0) { - return 0; - } - - return 1; -} - -static int write_min_cpu_freq(int freq) -{ - int ret; - - ret = device_set_property(DEVICE_TYPE_CPU, PROP_CPU_SCALING_MIN_FREQ, freq); - if (ret < 0) { - _E("set cpufreq min freq write error: %s", strerror(errno)); - return ret; - } - - return 0; -} - -static int write_max_cpu_freq(int freq) -{ - int ret; - - ret = device_set_property(DEVICE_TYPE_CPU, PROP_CPU_SCALING_MAX_FREQ, freq); - if (ret < 0) { - _E("set cpufreq max freq write error: %s", strerror(errno)); - return ret; - } - - return 0; -} - -static int remove_entry_from_min_cpu_freq_list(int pid) -{ - dd_list *tmp; - struct cpu_freq_entry *entry; - - cur_min_cpu_freq = INT_MIN; - - DD_LIST_FOREACH(min_cpu_freq_list, tmp, entry) { - if ((!is_entry_enable(entry->pid)) || (entry->pid == pid)) { - DD_LIST_REMOVE(min_cpu_freq_list, entry); - free(entry); - continue; - } - if (entry->freq > cur_min_cpu_freq) { - cur_min_cpu_freq = entry->freq; - } - } - - return 0; -} - -static int remove_entry_from_max_cpu_freq_list(int pid) -{ - dd_list *tmp; - struct cpu_freq_entry *entry; - - cur_max_cpu_freq = INT_MAX; - - DD_LIST_FOREACH(max_cpu_freq_list, tmp, entry) { - if ((!is_entry_enable(entry->pid)) || (entry->pid == pid)) { - DD_LIST_REMOVE(max_cpu_freq_list, entry); - free(entry); - continue; - } - if (entry->freq < cur_max_cpu_freq) { - cur_max_cpu_freq = entry->freq; - } - } - - return 0; -} - -int release_max_frequency_action(int argc, char **argv) -{ - int r; - - if (argc < 1) - return -EINVAL; - - r = remove_entry_from_max_cpu_freq_list(atoi(argv[0])); - if (r < 0) { - _E("Remove entry failed"); - return r; - } - - if (cur_max_cpu_freq == INT_MAX) - cur_max_cpu_freq = max_cpu_freq_limit; - - r = write_max_cpu_freq(cur_max_cpu_freq); - if (r < 0) { - _E("Write freq failed"); - return r; - } - - return 0; -} - -int release_min_frequency_action(int argc, char **argv) -{ - int r; - - if (argc < 1) - return -EINVAL; - - r = remove_entry_from_min_cpu_freq_list(atoi(argv[0])); - if (r < 0) { - _E("Remove entry failed"); - return r; - } - - if (cur_min_cpu_freq == INT_MIN) - cur_min_cpu_freq = min_cpu_freq_limit; - - r = write_min_cpu_freq(cur_min_cpu_freq); - if (r < 0) { - _E("Write entry failed"); - return r; - } - - return 0; -} - -static int add_entry_to_max_cpu_freq_list(int pid, int freq) -{ - int r; - struct cpu_freq_entry *entry; - - r = remove_entry_from_max_cpu_freq_list(pid); - if (r < 0) { - _E("Remove duplicated entry failed"); - } - - entry = malloc(sizeof(struct cpu_freq_entry)); - if (!entry) { - _E("Malloc failed"); - return -ENOMEM; - } - - entry->pid = pid; - entry->freq = freq; - - DD_LIST_PREPEND(max_cpu_freq_list, entry); - if (!max_cpu_freq_list) { - _E("eina_list_prepend failed"); - return -ENOSPC; - } - if (freq < cur_max_cpu_freq) { - cur_max_cpu_freq = freq; - } - return 0; -} - -static int add_entry_to_min_cpu_freq_list(int pid, int freq) -{ - int r; - struct cpu_freq_entry *entry; - - r = remove_entry_from_min_cpu_freq_list(pid); - if (r < 0) { - _E("Remove duplicated entry failed"); - } - - entry = malloc(sizeof(struct cpu_freq_entry)); - if (!entry) { - _E("Malloc failed"); - return -ENOMEM; - } - - entry->pid = pid; - entry->freq = freq; - - DD_LIST_PREPEND(min_cpu_freq_list, entry); - if (!min_cpu_freq_list) { - _E("eina_list_prepend failed"); - return -ENOSPC; - } - if (freq > cur_min_cpu_freq) { - cur_min_cpu_freq = freq; - } - return 0; -} - -int set_max_frequency_action(int argc, char **argv) -{ - int r; - - if (argc < 2) - return -EINVAL; - - r = add_entry_to_max_cpu_freq_list(atoi(argv[0]), atoi(argv[1])); - if (r < 0) { - _E("Add entry failed"); - return r; - } - - r = write_max_cpu_freq(cur_max_cpu_freq); - if (r < 0) { - _E("Write entry failed"); - return r; - } - - return 0; -} - -int set_min_frequency_action(int argc, char **argv) -{ - int r; - - if (argc < 2) - return -EINVAL; - - r = add_entry_to_min_cpu_freq_list(atoi(argv[0]), atoi(argv[1])); - if (r < 0) { - _E("Add entry failed"); - return r; - } - - r = write_min_cpu_freq(cur_min_cpu_freq); - if (r < 0) { - _E("Write entry failed"); - return r; - } - - return 0; -} - -static int power_saving_cpu_cb(keynode_t *key_nodes, void *data) -{ - int ret = 0; - int val = 0; - int power_saving_cpu_stat = -1; - - power_saving_cpu_stat = vconf_keynode_get_bool(key_nodes); - if (power_saving_cpu_stat == 1) { - val = 1; - ret = add_entry_to_max_cpu_freq_list(getpid(), power_saving_freq); - if (ret < 0) { - _E("Add entry failed"); - goto out; - } - } else { - ret = remove_entry_from_max_cpu_freq_list(getpid()); - if (ret < 0) { - _E("Remove entry failed"); - goto out; - } - if (cur_max_cpu_freq == INT_MAX) - cur_max_cpu_freq = max_cpu_freq_limit; - } - ret = write_max_cpu_freq(cur_max_cpu_freq); - if (ret < 0) - _E("Write failed"); -out: - device_notify(DEVICE_NOTIFIER_PMQOS_POWERSAVING, (void*)val); - return ret; -} - -static void set_emergency_limit(void) -{ - int ret, val; - - ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &val); - if (ret < 0) { - _E("failed to get vconf key"); - return; - } - if (val == SETTING_PSMODE_EMERGENCY) { - val = EMERGENCY_LOCK; - device_notify(DEVICE_NOTIFIER_PMQOS_EMERGENCY, (void*)val); - } -} - -static int emergency_cpu_cb(keynode_t *key_nodes, void *data) -{ - int val; - - val = vconf_keynode_get_int(key_nodes); - if (val == SETTING_PSMODE_EMERGENCY) - val = EMERGENCY_LOCK; - else - val = EMERGENCY_UNLOCK; - - device_notify(DEVICE_NOTIFIER_PMQOS_EMERGENCY, (void*)val); - return 0; -} - -static void set_freq_limit(void) -{ - int ret = 0; - int val = 0; - int power_saving_stat = -1; - int power_saving_cpu_stat = -1; - - ret = device_get_property(DEVICE_TYPE_CPU, PROP_CPU_CPUINFO_MAX_FREQ, - &max_cpu_freq_limit); - if (ret < 0) { - _E("get cpufreq cpuinfo max readerror: %s", strerror(errno)); - max_cpu_freq_limit = DEFAULT_MAX_CPU_FREQ; - } - - ret = device_get_property(DEVICE_TYPE_CPU, PROP_CPU_CPUINFO_MIN_FREQ, - &min_cpu_freq_limit); - if (ret < 0) { - _E("get cpufreq cpuinfo min readerror: %s", strerror(errno)); - min_cpu_freq_limit = DEFAULT_MIN_CPU_FREQ; - } - power_saving_freq = (int)(max_cpu_freq_limit * POWER_SAVING_CPU_FREQ_RATE); - _I("max(%d) , ps(%d), min(%d)", - max_cpu_freq_limit, - power_saving_freq, - min_cpu_freq_limit); - - ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, - &power_saving_cpu_stat); - if (ret < 0) { - _E("failed to get vconf key"); - return; - } - if (power_saving_cpu_stat != 1) - return; - val = 1; - ret = add_entry_to_max_cpu_freq_list(getpid(), power_saving_freq); - if (ret < 0) { - _E("Add entry failed"); - goto out; - } - ret = write_max_cpu_freq(cur_max_cpu_freq); - if (ret < 0) - _E("Write entry failed"); -out: - _I("init"); - device_notify(DEVICE_NOTIFIER_PMQOS_POWERSAVING, (void*)val); -} - -static int remove_entry_from_cpu_number_list(int pid) -{ - dd_list *tmp; - struct cpu_number_entry *entry; - - cur_cpu_number = INT_MAX; - - DD_LIST_FOREACH(cpu_number_list, tmp, entry) { - if ((!is_entry_enable(entry->pid)) || (entry->pid == pid)) { - DD_LIST_REMOVE(cpu_number_list, entry); - free(entry); - continue; - } - if (entry->number < cur_cpu_number) { - cur_cpu_number = entry->number; - } - } - - return 0; -} - -static int add_entry_to_cpu_number_list(int pid, int number) -{ - int r; - struct cpu_number_entry *entry; - - r = remove_entry_from_cpu_number_list(pid); - if (r < 0) { - _E("Remove duplicated entry failed"); - } - - - - entry = malloc(sizeof(struct cpu_number_entry)); - if (!entry) { - _E("Malloc failed"); - return -ENOMEM; - } - - entry->pid = pid; - entry->number = number; - - DD_LIST_PREPEND(cpu_number_list, entry); - if (!cpu_number_list) { - _E("eina_list_prepend failed"); - return -ENOSPC; - } - if (number < cur_cpu_number) { - cur_cpu_number = number; - } - return 0; -} - -static int booting_done(void *data) -{ - set_freq_limit(); - set_emergency_limit(); - return 0; -} - -static DBusMessage *dbus_cpu_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[2]; - - dbus_error_init(&err); - - if (!dbus_message_get_args(msg, &err, - DBUS_TYPE_STRING, &type_str, - DBUS_TYPE_INT32, &argc, - DBUS_TYPE_STRING, &argv[0], - DBUS_TYPE_STRING, &argv[1], 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, SET_MAX_FREQ, SET_FREQ_LEN)) - ret = set_max_frequency_action(argc, (char **)&argv); - else if (!strncmp(type_str, SET_MIN_FREQ, SET_FREQ_LEN)) - ret = set_min_frequency_action(argc, (char **)&argv); - else if (!strncmp(type_str, RELEASE_MAX_FREQ, RELEASE_FREQ_LEN)) - ret = release_max_frequency_action(argc, (char **)&argv); - else if (!strncmp(type_str, RELEASE_MIN_FREQ, RELEASE_FREQ_LEN)) - ret = release_min_frequency_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 const struct edbus_method edbus_methods[] = { - { SET_MAX_FREQ, "siss", "i", dbus_cpu_handler }, - { SET_MIN_FREQ, "siss", "i", dbus_cpu_handler }, - { RELEASE_MAX_FREQ, "siss", "i", dbus_cpu_handler }, - { RELEASE_MIN_FREQ, "siss", "i", dbus_cpu_handler }, -}; - -static void cpu_init(void *data) -{ - int ret; - - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); - ret = register_edbus_method(DEVICED_PATH_SYSNOTI, edbus_methods, ARRAY_SIZE(edbus_methods)); - if (ret < 0) - _E("fail to init edbus method(%d)", ret); - - vconf_notify_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, (void *)power_saving_cpu_cb, NULL); - vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, (void *)emergency_cpu_cb, NULL); -} - -static const struct device_ops cpu_device_ops = { - .name = "cpu", - .init = cpu_init, -}; - -DEVICE_OPS_REGISTER(&cpu_device_ops) diff --git a/src/display/core.c b/src/display/core.c index 61e9cb2..610a56b 100644 --- a/src/display/core.c +++ b/src/display/core.c @@ -95,7 +95,6 @@ static int (*basic_action) (int); static bool hallic_open = true; static Ecore_Timer *lock_timeout_id; static int lock_screen_timeout = LOCK_SCREEN_INPUT_TIMEOUT; -static int tts_state = false; static struct timeval lcdon_tv; static int lcd_paneloff_mode = false; static int stay_touchscreen_off = false; @@ -262,17 +261,6 @@ void broadcast_lcd_off(void) SIGNAL_LCD_OFF, NULL, NULL); } -void tts_lcd_off(void) -{ - int ret; - - ret = dbus_method_sync(POPUP_BUS_NAME, POPUP_PATH_SERVANT, - POPUP_IFACE_SERVANT, POPUP_METHOD_SCREENOFF_TTS, NULL, NULL); - - if (ret < 0) - _E("Failed to tts(%d)", ret); -} - static unsigned long get_lcd_on_flags(void) { unsigned long flags = NORMAL_MODE; @@ -334,9 +322,6 @@ inline void lcd_off_procedure(void) EINA_LIST_REVERSE_FOREACH(lcdon_ops, l, ops) ops->stop(flags); - - if (tts_state) - tts_lcd_off(); } void set_stay_touchscreen_off(int val) @@ -1943,27 +1928,12 @@ static int update_setting(int key_idx, int val) break; } break; - case SETTING_BOOT_POWER_ON_STATUS: - /* - * Unlock lcd off after booting is done. - * deviced guarantees all booting script is executing. - * Last script of booting unlocks this suspend blocking state. - */ - if (val == VCONFKEY_DEVICED_BOOT_POWER_ON_DONE) { - _I("booting done"); - pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN); - } - break; case SETTING_POWER_CUSTOM_BRIGHTNESS: if (val == VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON) backlight_ops.set_custom_status(true); else backlight_ops.set_custom_status(false); break; - case SETTING_ACCESSIBILITY_TTS: - tts_state = val; - _I("TTS is %s", (val ? "ON" : "OFF")); - break; default: return -1; @@ -2015,12 +1985,6 @@ static void check_seed_status(void) " for lock screen", lock_screen_timeout); } - /* TTS state */ - ret = vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &tts_state); - if (ret < 0) - _E("Failed to get TTS setting! (%d)", ret); - _I("TTS is %s", (tts_state ? "ON" : "OFF")); - return; } diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index fedddda..7f6c442 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -41,8 +41,6 @@ #define SIGNAL_SIM_STATUS "Status" #define SIM_CARD_NOT_PRESENT (0x01) -#define VCONFKEY_LCD_BRIGHTNESS_INIT "db/private/deviced/lcd_brightness_init" - #define SIGNAL_HOMESCREEN "HomeScreen" #define SIGNAL_EXTREME "Extreme" #define SIGNAL_NOTEXTREME "NotExtreme" @@ -998,10 +996,6 @@ static void sim_signal_handler(void *data, DBusMessage *msg) return; } - ret = vconf_get_bool(VCONFKEY_LCD_BRIGHTNESS_INIT, &state); - if (ret < 0 || state) - return; - dbus_error_init(&err); ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, @@ -1014,7 +1008,6 @@ static void sim_signal_handler(void *data, DBusMessage *msg) if (val != SIM_CARD_NOT_PRESENT) { /* change setting : autobrightness on */ state = true; - vconf_set_bool(VCONFKEY_LCD_BRIGHTNESS_INIT, state); vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_ON); vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, diff --git a/src/display/setting.c b/src/display/setting.c index 74b43a0..4fc32b8 100644 --- a/src/display/setting.c +++ b/src/display/setting.c @@ -34,9 +34,7 @@ static const char *setting_keys[SETTING_GET_END] = { [SETTING_TO_NORMAL] = VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, [SETTING_BRT_LEVEL] = VCONFKEY_SETAPPL_LCD_BRIGHTNESS, [SETTING_LOCK_SCREEN] = VCONFKEY_IDLE_LOCK_STATE, - [SETTING_BOOT_POWER_ON_STATUS] = VCONFKEY_DEVICED_BOOT_POWER_ON_STATUS, [SETTING_POWER_CUSTOM_BRIGHTNESS] = VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, - [SETTING_ACCESSIBILITY_TTS] = VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, }; static int lock_screen_state = VCONFKEY_IDLE_UNLOCK; @@ -212,14 +210,7 @@ static int setting_cb(keynode_t *key_nodes, void *data) return -1; } if (update_pm_setting != NULL) { - switch(index) { - case SETTING_ACCESSIBILITY_TTS: - update_pm_setting(index, vconf_keynode_get_bool(tmp)); - break; - default: - update_pm_setting(index, vconf_keynode_get_int(tmp)); - break; - } + update_pm_setting(index, vconf_keynode_get_int(tmp)); } return 0; diff --git a/src/display/setting.h b/src/display/setting.h index 8294f04..dd0133d 100644 --- a/src/display/setting.h +++ b/src/display/setting.h @@ -36,9 +36,7 @@ enum { SETTING_TO_NORMAL = SETTING_BEGIN, SETTING_BRT_LEVEL, SETTING_LOCK_SCREEN, - SETTING_BOOT_POWER_ON_STATUS, SETTING_POWER_CUSTOM_BRIGHTNESS, - SETTING_ACCESSIBILITY_TTS, SETTING_GET_END, SETTING_PM_STATE = SETTING_GET_END, SETTING_LOW_BATT, diff --git a/src/mmc/ext4.c b/src/mmc/ext4.c index 1b3ccc1..c443016 100644 --- a/src/mmc/ext4.c +++ b/src/mmc/ext4.c @@ -114,15 +114,10 @@ static int mmc_check_smack(const char *mount_point) static int check_smack_popup(void) { int ret = -1; - int val = -1; - ret = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &val); - if (val == 1 || ret != 0) { - - ret = manage_notification("MMC", "Check smack"); - if (ret == -1) - return -1; - } + ret = manage_notification("MMC", "Check smack"); + if (ret == -1) + return -1; return 0; } diff --git a/src/mmc/mmc-handler.c b/src/mmc/mmc-handler.c index e7ca722..b3a85d6 100644 --- a/src/mmc/mmc-handler.c +++ b/src/mmc/mmc-handler.c @@ -44,8 +44,6 @@ #include "core/list.h" #include "core/config-parser.h" -#define VCONFKEY_INTERNAL_PRIVATE_MMC_ID "db/private/sysman/mmc_device_id" - #define MMC_PARENT_PATH tzplatform_getenv(TZ_SYS_STORAGE) #define MMC_DEV "/dev/mmcblk" #define MMC_PATH "*/mmcblk[0-9]" @@ -273,23 +271,6 @@ int get_block_number(void) _E("%s read error: %s", buf,strerror(errno)); } close(fd); - pre_mmc_device_id = vconf_get_str(VCONFKEY_INTERNAL_PRIVATE_MMC_ID); - if (pre_mmc_device_id) { - if (strcmp(pre_mmc_device_id, "") == 0) { - vconf_set_str(VCONFKEY_INTERNAL_PRIVATE_MMC_ID, buf); - } else if (strncmp(pre_mmc_device_id,buf,33) == 0) { - if ( vconf_get_int(VCONFKEY_SYSMAN_MMC_DEVICE_CHANGED,&mmc_dev_changed) == 0 - && mmc_dev_changed != VCONFKEY_SYSMAN_MMC_NOT_CHANGED) { - vconf_set_int(VCONFKEY_SYSMAN_MMC_DEVICE_CHANGED, VCONFKEY_SYSMAN_MMC_NOT_CHANGED); - } - } else if (strncmp(pre_mmc_device_id,buf,32) != 0) { - vconf_set_str(VCONFKEY_INTERNAL_PRIVATE_MMC_ID, buf); - vconf_set_int(VCONFKEY_SYSMAN_MMC_DEVICE_CHANGED, VCONFKEY_SYSMAN_MMC_CHANGED); - } - free(pre_mmc_device_id); - } else { - _E("failed to get pre_mmc_device_id"); - } return mmcblk_num; } } diff --git a/src/shared/dbus.h b/src/shared/dbus.h index 2976cb3..6d9c762 100644 --- a/src/shared/dbus.h +++ b/src/shared/dbus.h @@ -188,7 +188,6 @@ #define POPUP_METHOD_LAUNCH "PopupLaunch" #define POPUP_METHOD_TERMINATE "AppTerminateByPid" #define POPUP_KEY_CONTENT "_SYSPOPUP_CONTENT_" -#define POPUP_METHOD_SCREENOFF_TTS "ScreenOffTts" /* * Crash daemon diff --git a/src/storage/storage.c b/src/storage/storage.c index 87060be..2d772e7 100755 --- a/src/storage/storage.c +++ b/src/storage/storage.c @@ -125,7 +125,6 @@ static void memnoti_level_broadcast(enum memnoti_level level) 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) { @@ -139,10 +138,6 @@ static int memnoti_popup(enum memnoti_level level) value = "Critical"; } - ret = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &val); - if (val == 0 || ret != 0) - return 0; - ret = manage_notification("Low memory", value); if (ret == -1) return -1; -- 2.7.4 From 36381a48ea7340f9489d717c8c8b128a88fb99d0 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Tue, 7 Apr 2015 13:43:53 +0900 Subject: [PATCH 05/16] deviced: Remove Eina_list codes Do not use Eina_list anymore. Instead deviced will use glist api in glibc. Change-Id: Ia9a2a8a24baadb14e1b5c6fe02f315c56d9b500c Signed-off-by: Jiyoung Yun --- CMakeLists.txt | 1 - src/core/edbus-handler.c | 2 +- src/core/list.h | 84 +++++++-------------------------------------- src/display/core.c | 42 +++++++++++------------ src/display/lock-detector.c | 54 +++++++++++++++-------------- src/shared/list.h | 50 --------------------------- 6 files changed, 63 insertions(+), 170 deletions(-) delete mode 100644 src/shared/list.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 10e7be6..60528a8 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,7 +115,6 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/deviced) SET(PKG_MODULES ecore edbus - eina vconf dlog device-node diff --git a/src/core/edbus-handler.c b/src/core/edbus-handler.c index f873b96..c4c2e5e 100644 --- a/src/core/edbus-handler.c +++ b/src/core/edbus-handler.c @@ -218,7 +218,7 @@ int register_edbus_signal_handler(const char *path, const char *interface, entry->handler = handler; DD_LIST_PREPEND(edbus_handler_list, entry); if (!edbus_handler_list) { - _E("eina_list_prepend failed"); + _E("dd_list_prepend failed"); free(entry->signal_name); free(entry); return -ENOMEM; diff --git a/src/core/list.h b/src/core/list.h index d3fa641..1d2f684 100644 --- a/src/core/list.h +++ b/src/core/list.h @@ -19,83 +19,17 @@ #ifndef __LIST_H__ #define __LIST_H__ -#include -#include - -#define EINA_LIST_APPEND(a, b) \ - a = eina_list_append(a, b) - -#define EINA_LIST_REMOVE(a, b) \ - a = eina_list_remove(a, b) - -#define EINA_LIST_REMOVE_LIST(a, b) \ - a = eina_list_remove_list(a, b) - -#define EINA_LIST_FREE_LIST(a) \ - a = eina_list_free(a) - -#define EINA_LIST_PROMOTE_LIST(a, b) \ - a = eina_list_promote_list(a, b) - -#ifdef EINA_LIST -typedef Eina_List dd_list; -#define DD_LIST_PREPEND(a, b) \ - a = eina_list_prepend(a, b) -#define DD_LIST_APPEND(a, b) \ - a = eina_list_append(a, b) -#define DD_LIST_REMOVE(a, b) \ - a = eina_list_remove(a, b) -#define DD_LIST_LENGTH(a) \ - eina_list_count(a) -#define DD_LIST_NTH(a, b) \ - eina_list_nth(a, b) -#define DD_LIST_FREE_LIST(a) \ - a = eina_list_free(a) -#define DD_LIST_FOREACH(head, elem, node) \ - EINA_LIST_FOREACH(head, elem, node) -#define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \ - EINA_LIST_FOREACH_SAFE(head, elem, elem_next, node) - -#else #include typedef GList dd_list; -/* - cover crash from corrupted double linked list under the glib 2.36.4 - if glib version upper than 2.36.3, exchange it to g_list_remove -*/ -static inline GList* g_list_check_remove(GList* list, gpointer data) -{ - GList *temp; - temp = list; - if (!temp) - goto out; - while (temp != NULL) { - if (temp->data != data) - temp = temp->next; - else { - if (temp->prev != NULL && temp->prev->next == temp) - temp->prev->next = temp->next; - if (temp->next != NULL && temp->next->prev == temp) - temp->next->prev = temp->prev; - if (temp == list) - list = list->next; - temp->prev = NULL; - temp->next = NULL; - g_list_free(list); - break; - } - } -out: - return list; -} - #define DD_LIST_PREPEND(a, b) \ a = g_list_prepend(a, (gpointer)b) #define DD_LIST_APPEND(a, b) \ a = g_list_append(a, (gpointer)b) #define DD_LIST_REMOVE(a, b) \ a = g_list_remove(a, (gpointer)b) +#define DD_LIST_REMOVE_LIST(a, b) \ + a = g_list_remove_link(a, b) #define DD_LIST_LENGTH(a) \ g_list_length(a) #define DD_LIST_NTH(a, b) \ @@ -103,12 +37,20 @@ out: #define DD_LIST_FREE_LIST(a) \ g_list_free(a) #define DD_LIST_FOREACH(head, elem, node) \ - for (elem = head, node = NULL; elem && ((node = elem->data) != NULL); elem = elem->next, node = NULL) + for (elem = head, node = NULL; \ + elem && ((node = elem->data) != NULL); \ + elem = elem->next, node = NULL) #define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \ for (elem = head, elem_next = g_list_next(elem), node = NULL; \ elem && ((node = elem->data) != NULL); \ elem = elem_next, elem_next = g_list_next(elem), node = NULL) - -#endif +#define DD_LIST_REVERSE_FOREACH(head, elem, node) \ + for (elem = g_list_last(head), node = NULL; \ + elem && ((node = elem->data) != NULL); \ + elem = g_list_previous(elem), node = NULL) +#define DD_LIST_REVERSE_FOREACH_SAFE(head, elem, elem_next, node) \ + for (elem = g_list_last(head), elem_next = g_list_previous(elem), node = NULL; \ + elem && ((node = elem->data) != NULL); \ + elem = elem_next, elem_next = g_list_previous(elem), node = NULL) #endif diff --git a/src/display/core.c b/src/display/core.c index 610a56b..b56a2ff 100644 --- a/src/display/core.c +++ b/src/display/core.c @@ -90,7 +90,7 @@ static int custom_change_pid = -1; static char *custom_change_name; static int standby_mode = false; static int standby_state = false; -static Eina_List *standby_mode_list = NULL; +static dd_list *standby_mode_list; static int (*basic_action) (int); static bool hallic_open = true; static Ecore_Timer *lock_timeout_id; @@ -98,7 +98,7 @@ static int lock_screen_timeout = LOCK_SCREEN_INPUT_TIMEOUT; static struct timeval lcdon_tv; static int lcd_paneloff_mode = false; static int stay_touchscreen_off = false; -static Eina_List *lcdon_ops = NULL; +static dd_list *lcdon_ops; static bool lcdon_broadcast = false; /* default transition, action fuctions */ @@ -276,7 +276,7 @@ static unsigned long get_lcd_on_flags(void) void lcd_on_procedure(int state, enum device_flags flag) { - Eina_List *l = NULL; + dd_list *l = NULL; const struct device_ops *ops = NULL; unsigned long flags = get_lcd_on_flags(); flags |= flag; @@ -295,7 +295,7 @@ void lcd_on_procedure(int state, enum device_flags flag) backlight_ops.update(); } - EINA_LIST_FOREACH(lcdon_ops, l, ops) + DD_LIST_FOREACH(lcdon_ops, l, ops) ops->start(flags); if (CHECK_OPS(keyfilter_ops, backlight_enable)) @@ -304,7 +304,7 @@ void lcd_on_procedure(int state, enum device_flags flag) inline void lcd_off_procedure(void) { - Eina_List *l = NULL; + dd_list *l = NULL; const struct device_ops *ops = NULL; unsigned long flags = NORMAL_MODE; @@ -320,7 +320,7 @@ inline void lcd_off_procedure(void) if (CHECK_OPS(keyfilter_ops, backlight_enable)) keyfilter_ops->backlight_enable(false); - EINA_LIST_REVERSE_FOREACH(lcdon_ops, l, ops) + DD_LIST_REVERSE_FOREACH(lcdon_ops, l, ops) ops->stop(flags); } @@ -877,17 +877,17 @@ static int standby_action(int timeout) static void set_standby_mode(pid_t pid, int enable) { - Eina_List *l = NULL; - Eina_List *l_next = NULL; + dd_list *l = NULL; + dd_list *l_next = NULL; void *data; if (enable) { - EINA_LIST_FOREACH(standby_mode_list, l, data) + DD_LIST_FOREACH(standby_mode_list, l, data) if (pid == (pid_t)((intptr_t)data)) { _E("%d already acquired standby mode", pid); return; } - EINA_LIST_APPEND(standby_mode_list, (void *)((intptr_t)pid)); + DD_LIST_APPEND(standby_mode_list, (void *)((intptr_t)pid)); _I("%d acquire standby mode", pid); if (standby_mode) return; @@ -899,9 +899,9 @@ static void set_standby_mode(pid_t pid, int enable) } else { if (!standby_mode) return; - EINA_LIST_FOREACH_SAFE(standby_mode_list, l, l_next, data) + DD_LIST_FOREACH_SAFE(standby_mode_list, l, l_next, data) if (pid == (pid_t)((intptr_t)data)) { - standby_mode_list = eina_list_remove_list( + standby_mode_list = DD_LIST_REMOVE_LIST( standby_mode_list, l); _I("%d release standby mode", pid); } @@ -1302,7 +1302,7 @@ void print_info(int fd) int s_index = 0; char buf[255]; int i = 1, ret; - Eina_List *l = NULL; + dd_list *l = NULL; void *data; char pname[PATH_MAX]; @@ -1351,7 +1351,7 @@ void print_info(int fd) snprintf(buf, sizeof(buf), "\n\nstandby mode is on\n"); write(fd, buf, strlen(buf)); - EINA_LIST_FOREACH(standby_mode_list, l, data) { + DD_LIST_FOREACH(standby_mode_list, l, data) { get_pname((pid_t)((intptr_t)data), pname); snprintf(buf, sizeof(buf), " standby mode acquired by pid %d" @@ -1994,25 +1994,25 @@ static void init_lcd_operation(void) ops = find_device("display"); if (!check_default(ops)) - EINA_LIST_APPEND(lcdon_ops, ops); + DD_LIST_APPEND(lcdon_ops, ops); ops = find_device("touchscreen"); if (!check_default(ops)) - EINA_LIST_APPEND(lcdon_ops, ops); + DD_LIST_APPEND(lcdon_ops, ops); ops = find_device("touchkey"); if (!check_default(ops)) - EINA_LIST_APPEND(lcdon_ops, ops); + DD_LIST_APPEND(lcdon_ops, ops); } static void exit_lcd_operation(void) { - Eina_List *l = NULL; - Eina_List *l_next = NULL; + dd_list *l = NULL; + dd_list *l_next = NULL; const struct device_ops *ops = NULL; - EINA_LIST_FOREACH_SAFE(lcdon_ops, l, l_next, ops) - EINA_LIST_REMOVE_LIST(lcdon_ops, l); + DD_LIST_FOREACH_SAFE(lcdon_ops, l, l_next, ops) + DD_LIST_REMOVE_LIST(lcdon_ops, l); } enum { diff --git a/src/display/lock-detector.c b/src/display/lock-detector.c index 91c486e..7a79d23 100644 --- a/src/display/lock-detector.c +++ b/src/display/lock-detector.c @@ -30,7 +30,6 @@ #include #include #include -#include #include "util.h" #include "core.h" @@ -48,7 +47,7 @@ struct lock_info { #define LIMIT_COUNT 128 -static Eina_List *lock_info_list; +static dd_list *lock_info_list; static long get_time(void) { @@ -59,18 +58,18 @@ static long get_time(void) static void shrink_lock_info_list(void) { - Eina_List *l, *l_prev; + dd_list *l, *l_prev; struct lock_info *info; unsigned int count; - count = eina_list_count(lock_info_list); + count = DD_LIST_LENGTH(lock_info_list); if (count <= LIMIT_COUNT) return; _D("list is shrink : count %d", count); - EINA_LIST_REVERSE_FOREACH_SAFE(lock_info_list, l, l_prev, info) { + DD_LIST_REVERSE_FOREACH_SAFE(lock_info_list, l, l_prev, info) { if (info->locktime == 0) { - EINA_LIST_REMOVE_LIST(lock_info_list, l); + DD_LIST_REMOVE_LIST(lock_info_list, l); if (info->name) free(info->name); free(info); @@ -84,7 +83,7 @@ static void shrink_lock_info_list(void) int set_lock_time(const char *pname, int state) { struct lock_info *info; - Eina_List *l; + dd_list *l; unsigned long val; if (!pname) @@ -93,16 +92,18 @@ int set_lock_time(const char *pname, int state) if (state < S_NORMAL || state > S_SLEEP) return -EINVAL; - val = eina_hash_superfast(pname, strlen(pname)); + val = g_str_hash(pname); - EINA_LIST_FOREACH(lock_info_list, l, info) - if (info->hash == val && info->state == state) { + DD_LIST_FOREACH(lock_info_list, l, info) + if (info->hash == val && + !strncmp(info->name, pname, strlen(pname)+1) && + info->state == state) { info->count += 1; if (info->locktime == 0) info->locktime = get_time(); info->unlocktime = 0; - EINA_LIST_PROMOTE_LIST(lock_info_list, l); - eina_list_data_set(l, info); + DD_LIST_REMOVE(lock_info_list, info); + DD_LIST_PREPEND(lock_info_list, info); return 0; } @@ -120,7 +121,7 @@ int set_lock_time(const char *pname, int state) info->unlocktime = 0; info->time = 0; - EINA_LIST_APPEND(lock_info_list, info); + DD_LIST_APPEND(lock_info_list, info); return 0; } @@ -130,7 +131,7 @@ int set_unlock_time(const char *pname, int state) bool find = false; long diff; struct lock_info *info; - Eina_List *l; + dd_list *l; unsigned long val; if (!pname) @@ -139,11 +140,14 @@ int set_unlock_time(const char *pname, int state) if (state < S_NORMAL || state > S_SLEEP) return -EINVAL; - val = eina_hash_superfast(pname, strlen(pname)); + val = g_str_hash(pname); - EINA_LIST_FOREACH(lock_info_list, l, info) - if (info->hash == val && info->state == state) { - EINA_LIST_PROMOTE_LIST(lock_info_list, l); + DD_LIST_FOREACH(lock_info_list, l, info) + if (info->hash == val && + !strncmp(info->name, pname, strlen(pname)+1) && + info->state == state) { + DD_LIST_REMOVE(lock_info_list, info); + DD_LIST_PREPEND(lock_info_list, info); find = true; break; } @@ -161,9 +165,7 @@ int set_unlock_time(const char *pname, int state) info->time += diff; info->locktime = 0; - eina_list_data_set(l, info); - - if (eina_list_count(lock_info_list) > LIMIT_COUNT) + if (DD_LIST_LENGTH(lock_info_list) > LIMIT_COUNT) shrink_lock_info_list(); return 0; @@ -171,14 +173,14 @@ int set_unlock_time(const char *pname, int state) void free_lock_info_list(void) { - Eina_List *l, *l_next; + dd_list *l, *l_next; struct lock_info *info; if (!lock_info_list) return; - EINA_LIST_FOREACH_SAFE(lock_info_list, l, l_next, info) { - EINA_LIST_REMOVE(lock_info_list, l); + DD_LIST_FOREACH_SAFE(lock_info_list, l, l_next, info) { + DD_LIST_REMOVE(lock_info_list, info); if (info->name) free(info->name); free(info); @@ -189,7 +191,7 @@ void free_lock_info_list(void) void print_lock_info_list(int fd) { struct lock_info *info; - Eina_List *l; + dd_list *l; char buf[255]; if (!lock_info_list) @@ -204,7 +206,7 @@ void print_lock_info_list(int fd) "count", "locktime", "unlocktime", "time", "process name"); write(fd, buf, strlen(buf)); - EINA_LIST_FOREACH(lock_info_list, l, info) { + DD_LIST_FOREACH(lock_info_list, l, info) { long time = 0; if (info->locktime != 0 && info->unlocktime == 0) time = get_time() - info->locktime; diff --git a/src/shared/list.h b/src/shared/list.h deleted file mode 100644 index b05e35f..0000000 --- a/src/shared/list.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 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 __LIST_H__ -#define __LIST_H__ - -#include - -#define LIST_ADD(head, data) \ - do { \ - head = g_list_append(head, data); \ - } while(0) - -#define LIST_DEL(head, data) \ - do { \ - head = g_list_remove(head, data); \ - } while(0) - -#define LIST_FIND(head, node, t, name, data) \ - do { \ - t *tmp; \ - GList *elem; \ - for (elem = head; elem; elem = elem->next) { \ - tmp = elem->data; \ - if (tmp->##name != data) \ - continue; \ - node = tmp; \ - } \ - } while(0) - -#define LIST_FOREACH(head, item) \ - for (item = head; item; item = item->next) - -#endif -- 2.7.4 From d32f876fdb862f41700a06581cdcc6f67a8cd98a Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Tue, 7 Apr 2015 15:21:41 +0900 Subject: [PATCH 06/16] deviced: Add device idler logic It allows for callbacks to be called when the daemon is idle state. func: int add_idle_request(int (*func)(void *data), void *data); Change-Id: I2d7879874da5bd072b6ed205ff4d33a81e919dc7 Signed-off-by: Jiyoung Yun --- CMakeLists.txt | 1 + src/core/device-idler.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++ src/core/device-idler.h | 29 ++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 src/core/device-idler.c create mode 100644 src/core/device-idler.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 60528a8..1f9b2b2 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ SET(SRCS src/core/common.c src/core/config-parser.c src/control/control.c + src/core/device-idler.c src/core/device-notifier.c src/core/devices.c src/core/edbus-handler.c diff --git a/src/core/device-idler.c b/src/core/device-idler.c new file mode 100644 index 0000000..06e2317 --- /dev/null +++ b/src/core/device-idler.c @@ -0,0 +1,102 @@ +/* + * deviced + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include + +#include "log.h" + +struct device_request { + int (*func)(void *data); + void *data; +}; + +static GQueue req_queue = G_QUEUE_INIT; +static Ecore_Idler *idler; + +static int free_request(struct device_request *req) +{ + if (!req) + return -EINVAL; + + free(req); + return 0; +} + +static Eina_Bool idler_cb(void *data) +{ + struct device_request *req; + + req = g_queue_pop_head(&req_queue); + if (req) { + if (req->func) + req->func(req->data); + free_request(req); + } + + if (g_queue_is_empty(&req_queue)) { + idler = NULL; + return ECORE_CALLBACK_CANCEL; + } + + return ECORE_CALLBACK_RENEW; +} + +static void process_next_request_in_idle(void) +{ + if (g_queue_is_empty(&req_queue)) + return; + + if (idler) + return; + + idler = ecore_idler_add(idler_cb, NULL); + /** + * if idler is null, + * it means whole system might be an abnormal state. + * so it just prints out error log. + */ + if (!idler) + _E("fail to add request to idler"); +} + +int add_idle_request(int (*func)(void *data), void *data) +{ + struct device_request *req; + + if (!func) { + _E("invalid argumet : func(NULL)"); + return -EINVAL; + } + + req = calloc(1, sizeof(struct device_request)); + if (!req) { + _E("fail to allocate request : %s", strerror(errno)); + return -errno; + } + + req->func = func; + req->data = data; + + g_queue_push_tail(&req_queue, req); + process_next_request_in_idle(); + + return 0; +} diff --git a/src/core/device-idler.h b/src/core/device-idler.h new file mode 100644 index 0000000..add2ecf --- /dev/null +++ b/src/core/device-idler.h @@ -0,0 +1,29 @@ +/* + * deviced + * + * Copyright (c) 2015 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 __DEVICE_IDLER_H__ +#define __DEVICE_IDLER_H__ + +/* + * To allow for callbacks to be called when the daemon is idle state. + */ + +int add_idle_request(int (*func)(void *data), void *data); + +#endif /* __DEVICE_IDLER_H__ */ -- 2.7.4 From de374774f959e24b01545b11341542a2e70ae624 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Tue, 7 Apr 2015 19:01:17 +0900 Subject: [PATCH 07/16] power: Do not use vconf key to control poweroff operation Before changing, deviced can be turn off the target by vconf key. Now all poweroff case of the dependent on vconf key are removed. And removed unsupported recovery, fota codes. Change-Id: Ia01a4e1f898ecb3451c81d226521a4864712dd6c Signed-off-by: Jiyoung Yun --- src/battery/lowbat-handler.c | 4 +- src/display/core.c | 9 ++- src/power/power-handler.c | 176 ++++++++++++++----------------------------- src/power/power-handler.h | 17 ++--- src/telephony/telephony.c | 19 ++--- 5 files changed, 75 insertions(+), 150 deletions(-) diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index cd7df77..e95e175 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -151,7 +151,7 @@ static int power_execute(void) FIND_DEVICE_INT(ops, POWER_OPS_NAME); - return ops->execute(INTERNAL_PWROFF); + return ops->execute(POWER_POWEROFF); } static int booting_done(void *data) @@ -244,7 +244,7 @@ static int battery_critical_low_act(void *data) int battery_power_off_act(void *data) { - vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, VCONFKEY_SYSMAN_POWER_OFF_DIRECT); + power_execute(); return 0; } diff --git a/src/display/core.c b/src/display/core.c index b56a2ff..1618e01 100644 --- a/src/display/core.c +++ b/src/display/core.c @@ -51,6 +51,7 @@ #include "core/edbus-handler.h" #include "core/config-parser.h" #include "extcon/extcon.h" +#include "power/power-handler.h" #include "dd-display.h" #define PM_STATE_LOG_FILE "/var/log/pm_state.log" @@ -1918,12 +1919,12 @@ static int update_setting(int key_idx, int val) break; case SETTING_POWEROFF: switch (val) { - case VCONFKEY_SYSMAN_POWER_OFF_NONE: - case VCONFKEY_SYSMAN_POWER_OFF_POPUP: + case POWER_OFF_NONE: + case POWER_OFF_POPUP: pm_status_flag &= ~PWROFF_FLAG; break; - case VCONFKEY_SYSMAN_POWER_OFF_DIRECT: - case VCONFKEY_SYSMAN_POWER_OFF_RESTART: + case POWER_OFF_DIRECT: + case POWER_OFF_RESTART: pm_status_flag |= PWROFF_FLAG; break; } diff --git a/src/power/power-handler.c b/src/power/power-handler.c index a208851..3bda4c9 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -36,6 +36,7 @@ #include "core/log.h" #include "core/launch.h" #include "core/device-notifier.h" +#include "core/device-idler.h" #include "core/common.h" #include "core/devices.h" #include "proc/proc-handler.h" @@ -48,23 +49,20 @@ #define SIGNAL_NAME_POWEROFF_POPUP "poweroffpopup" #define SIGNAL_BOOTING_DONE "BootingDone" -#define POWEROFF_NOTI_NAME "power_off_start" #define POWEROFF_DURATION 2 #define MAX_RETRY 2 -#define SYSTEMD_STOP_POWER_OFF 4 - #define SIGNAL_POWEROFF_STATE "ChangeState" #define UMOUNT_RW_PATH "/opt/usr" -static void poweroff_control_cb(keynode_t *in_key, void *data); - static struct timeval tv_start_poweroff; static int power_off = 0; static const struct device_ops *telephony = NULL; +static int power_execute(void *data); + static void telephony_init(void) { FIND_DEVICE_VOID(telephony, "telephony"); @@ -90,25 +88,6 @@ static int telephony_exit(void *data) return ret; } -static int systemd_manager_object(const char *opt, char **param) -{ - return dbus_method_async("org.freedesktop.systemd1", - "/org/freedesktop/systemd1", - "org.freedesktop.systemd1.Manager", - opt, - "ss", param); -} - -static int systemd_manager_object_start_unit(char **param) -{ - return systemd_manager_object("StartUnit", param); -} - -static int systemd_manager_object_stop_unit(char **param) -{ - return systemd_manager_object("StopUnit", param); -} - static void poweroff_start_animation(void) { char params[128]; @@ -151,7 +130,6 @@ static int poweroff(void) retry_count++; continue; } - vconf_ignore_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, (void*)poweroff_control_cb); return 0; } return -1; @@ -168,7 +146,7 @@ static int pwroff_popup(void) return 0; } -static int power_reboot(int type) +static int power_reboot(void) { int ret; @@ -184,40 +162,14 @@ static int power_reboot(int type) gettimeofday(&tv_start_poweroff, NULL); - if (type == SYSTEMD_STOP_POWER_RESTART_RECOVERY) - ret = telephony_exit(POWER_RECOVERY); - else if (type == SYSTEMD_STOP_POWER_RESTART_FOTA) - ret = telephony_exit(POWER_FOTA); - else - ret = telephony_exit(POWER_REBOOT); - + ret = telephony_exit(POWER_REBOOT); if (ret < 0) { - restart_ap(type); + restart_ap(NULL); return 0; } return ret; } -static int power_execute(void *data) -{ - int ret = 0; - - if (strncmp(POWER_POWEROFF, (char *)data, POWER_POWEROFF_LEN) == 0) - ret = poweroff(); - else if (strncmp(PWROFF_POPUP, (char *)data, PWROFF_POPUP_LEN) == 0) - ret = pwroff_popup(); - else if (strncmp(POWER_REBOOT, (char *)data, POWER_REBOOT_LEN) == 0) - ret = power_reboot(VCONFKEY_SYSMAN_POWER_OFF_RESTART); - else if (strncmp(POWER_RECOVERY, (char *)data, POWER_RECOVERY_LEN) == 0) - ret = power_reboot(SYSTEMD_STOP_POWER_RESTART_RECOVERY); - else if (strncmp(POWER_FOTA, (char *)data, POWER_FOTA_LEN) == 0) - ret = power_reboot(SYSTEMD_STOP_POWER_RESTART_FOTA); - else if (strncmp(INTERNAL_PWROFF, (char *)data, INTERNAL_PWROFF_LEN) == 0) - ret = previous_poweroff(); - - return ret; -} - static void poweroff_popup_edbus_signal_handler(void *data, DBusMessage *msg) { DBusError err; @@ -236,19 +188,7 @@ static void poweroff_popup_edbus_signal_handler(void *data, DBusMessage *msg) return; } - if (!strncmp(str, PWROFF_POPUP, PWROFF_POPUP_LEN)) - val = VCONFKEY_SYSMAN_POWER_OFF_POPUP; - else if (!strncmp(str, POWER_POWEROFF, POWER_POWEROFF_LEN)) - val = SYSTEMD_STOP_POWER_OFF; - else if (!strncmp(str, POWER_REBOOT, POWER_REBOOT_LEN)) - val = SYSTEMD_STOP_POWER_RESTART; - else if (!strncmp(str, POWER_FOTA, POWER_FOTA_LEN)) - val = SYSTEMD_STOP_POWER_RESTART_FOTA; - if (val == 0) { - _E("not supported message : %s", str); - return; - } - vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, val); + power_execute(str); } static int booting_done(void *data) @@ -307,52 +247,71 @@ static void poweroff_stop_systemd_service(void) umount2("/sys/fs/cgroup", MNT_FORCE |MNT_DETACH); } -static void poweroff_control_cb(keynode_t *in_key, void *data) +static int poweroff_idler_cb(void *data) { - int val; + enum poweroff_type val = (int)data; int ret; int recovery; telephony_start(); - if (vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &val) != 0) - return; + pm_lock_internal(INTERNAL_LOCK_POWEROFF, LCD_OFF, STAY_CUR_STATE, 0); + poweroff_stop_systemd_service(); - recovery = val; - - if (val == SYSTEMD_STOP_POWER_OFF || - val == SYSTEMD_STOP_POWER_RESTART || - val == SYSTEMD_STOP_POWER_RESTART_RECOVERY || - val == SYSTEMD_STOP_POWER_RESTART_FOTA) { - pm_lock_internal(INTERNAL_LOCK_POWEROFF, LCD_OFF, STAY_CUR_STATE, 0); - poweroff_stop_systemd_service(); - if (val == SYSTEMD_STOP_POWER_OFF) - val = VCONFKEY_SYSMAN_POWER_OFF_DIRECT; - else - val = VCONFKEY_SYSMAN_POWER_OFF_RESTART; - vconf_ignore_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, (void*)poweroff_control_cb); - vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, val); + if (val == POWER_OFF_DIRECT || val == POWER_OFF_RESTART) { + poweroff_send_broadcast(val); + device_notify(DEVICE_NOTIFIER_POWEROFF, &val); } - if (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT || val == VCONFKEY_SYSMAN_POWER_OFF_RESTART) - poweroff_send_broadcast(val); + /* TODO for notify. will be removed asap. */ + vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, val); switch (val) { - case VCONFKEY_SYSMAN_POWER_OFF_DIRECT: - device_notify(DEVICE_NOTIFIER_POWEROFF, &val); + case POWER_OFF_DIRECT: poweroff(); break; - case VCONFKEY_SYSMAN_POWER_OFF_POPUP: + case POWER_OFF_POPUP: pwroff_popup(); break; - case VCONFKEY_SYSMAN_POWER_OFF_RESTART: - device_notify(DEVICE_NOTIFIER_POWEROFF, &val); - power_reboot(recovery); + case POWER_OFF_RESTART: + power_reboot(); break; } if (update_pm_setting) update_pm_setting(SETTING_POWEROFF, val); + + return 0; +} + +static int power_execute(void *data) +{ + int ret; + int val; + + if (!data) { + _E("Invalid parameter : data(NULL)"); + return -EINVAL; + } + + if (strncmp(POWER_POWEROFF, (char *)data, POWER_POWEROFF_LEN) == 0) + val = POWER_OFF_DIRECT; + else if (strncmp(PWROFF_POPUP, (char *)data, PWROFF_POPUP_LEN) == 0) + val = POWER_OFF_POPUP; + else if (strncmp(POWER_REBOOT, (char *)data, POWER_REBOOT_LEN) == 0) + val = POWER_OFF_RESTART; + else { + _E("Invalid parameter : data(%s)", (char *)data); + return -EINVAL; + } + + ret = add_idle_request(poweroff_idler_cb, (int*)val); + if (ret < 0) { + _E("fail to add poweroff idle request : %d", ret); + return ret; + } + + return 0; } /* umount usr data partition */ @@ -407,7 +366,6 @@ static void powerdown(void) } /* if this fails, that's OK */ telephony_stop(); - vconf_ignore_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, (void*)poweroff_control_cb); power_off = 1; sync(); @@ -434,16 +392,6 @@ static void powerdown(void) #endif } -static void restart_by_mode(int mode) -{ - if (mode == SYSTEMD_STOP_POWER_RESTART_RECOVERY) - launch_evenif_exist("/usr/sbin/reboot", "recovery"); - else if (mode == SYSTEMD_STOP_POWER_RESTART_FOTA) - launch_evenif_exist("/usr/sbin/reboot", "fota"); - else - reboot(RB_AUTOBOOT); -} - static DBusMessage *dbus_power_handler(E_DBus_Object *obj, DBusMessage *msg) { DBusError err; @@ -477,14 +425,7 @@ static DBusMessage *dbus_power_handler(E_DBus_Object *obj, DBusMessage *msg) goto out; } - telephony_start(); - - if(!strncmp(type_str, POWER_REBOOT, POWER_REBOOT_LEN)) - ret = power_reboot(VCONFKEY_SYSMAN_POWER_OFF_RESTART); - else if(!strncmp(type_str, POWER_RECOVERY, POWER_RECOVERY_LEN)) - ret = power_reboot(SYSTEMD_STOP_POWER_RESTART_RECOVERY); - else if(!strncmp(type_str, PWROFF_POPUP, PWROFF_POPUP_LEN)) - ret = pwroff_popup(); + ret = power_execute(type_str); out: reply = dbus_message_new_method_return(msg); @@ -501,16 +442,15 @@ void powerdown_ap(void *data) reboot(RB_POWER_OFF); } -void restart_ap(int data) +void restart_ap(void *data) { - _I("Restart %d", data); + _I("Restart"); powerdown(); - restart_by_mode(data); + reboot(RB_AUTOBOOT); } static const struct edbus_method edbus_methods[] = { { POWER_REBOOT, "si", "i", dbus_power_handler }, - { POWER_RECOVERY, "si", "i", dbus_power_handler }, { PWROFF_POPUP, "si", "i", dbus_power_handler }, /* Add methods here */ }; @@ -525,10 +465,6 @@ static void power_init(void *data) if (ret < 0) _E("fail to init edbus method(%d)", ret); - if (vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, (void *)poweroff_control_cb, NULL) < 0) { - _E("Vconf notify key chaneged failed: KEY(%s)", VCONFKEY_SYSMAN_POWER_OFF_STATUS); - } - register_edbus_signal_handler(DEVICED_OBJECT_PATH, DEVICED_INTERFACE_NAME, SIGNAL_NAME_POWEROFF_POPUP, poweroff_popup_edbus_signal_handler); diff --git a/src/power/power-handler.h b/src/power/power-handler.h index 322c30b..cb7af7a 100644 --- a/src/power/power-handler.h +++ b/src/power/power-handler.h @@ -25,21 +25,18 @@ #define POWER_POWEROFF_LEN 8 #define POWER_REBOOT "reboot" #define POWER_REBOOT_LEN 6 -#define POWER_RECOVERY "reboot-recovery" -#define POWER_RECOVERY_LEN 15 -#define POWER_FOTA "fota" -#define POWER_FOTA_LEN 4 #define PWROFF_POPUP "pwroff-popup" #define PWROFF_POPUP_LEN 12 -#define INTERNAL_PWROFF "internal" -#define INTERNAL_PWROFF_LEN 8 -#define SYSTEMD_STOP_POWER_RESTART 5 -#define SYSTEMD_STOP_POWER_RESTART_RECOVERY 6 -#define SYSTEMD_STOP_POWER_RESTART_FOTA 7 +enum poweroff_type { + POWER_OFF_NONE = 0, + POWER_OFF_POPUP, + POWER_OFF_DIRECT, + POWER_OFF_RESTART, +}; #ifndef SYSTEMD_SHUTDOWN -void restart_ap(int data); +void restart_ap(void *data); void powerdown_ap(void *data); #endif diff --git a/src/telephony/telephony.c b/src/telephony/telephony.c index a01bb72..464fae1 100644 --- a/src/telephony/telephony.c +++ b/src/telephony/telephony.c @@ -43,7 +43,6 @@ static TapiHandle *tapi_handle = NULL; static Ecore_Timer *poweroff_timer_id = NULL; -static int reboot_opt; static Eina_Bool telephony_powerdown_ap_internal(void *data) { @@ -57,7 +56,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(reboot_opt); + restart_ap(data); } static Eina_Bool telephony_restart_ap_by_force(void *data) @@ -152,37 +151,29 @@ static void telephony_exit(void *data) return; } - if (strncmp(data, POWER_REBOOT, POWER_REBOOT_LEN) && - strncmp(data, POWER_RECOVERY, POWER_RECOVERY_LEN) && - strncmp(data, POWER_FOTA, POWER_FOTA_LEN)) { + if (strncmp(data, POWER_REBOOT, POWER_REBOOT_LEN)) { _E("Fail %s", data); return; } _I("Option: %s", data); - if (!strncmp(data, POWER_RECOVERY, POWER_RECOVERY_LEN)) - reboot_opt = SYSTEMD_STOP_POWER_RESTART_RECOVERY; - else if (!strncmp(data, POWER_REBOOT, POWER_REBOOT_LEN)) - reboot_opt = SYSTEMD_STOP_POWER_RESTART; - else if (!strncmp(data, POWER_FOTA, POWER_FOTA_LEN)) - reboot_opt = SYSTEMD_STOP_POWER_RESTART_FOTA; 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((void *)POWER_RESTART); + telephony_restart_ap_by_force(NULL); return; } ret = tel_process_power_command(tapi_handle, TAPI_PHONE_POWER_OFF, powerdown_res_cb, NULL); if (ret != TAPI_API_SUCCESS) { _E("tel_process_power_command() error %d", ret); - telephony_restart_ap_by_force((void *)reboot_opt); + telephony_restart_ap_by_force(NULL); return; } poweroff_timer_id = ecore_timer_add(15,telephony_restart_ap_by_force, - (void *)reboot_opt); + NULL); } static void telephony_flight_mode_on(TapiHandle *handle, int result, void *data, void *user_data) -- 2.7.4 From 7a51d51f5842b57ff545028d77866bc14a545400 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Tue, 14 Apr 2015 10:02:03 +0900 Subject: [PATCH 08/16] deviced: Remove unused device notifier codes Signed-off-by: Jiyoung Yun Change-Id: I475b762fc6f8e44eac73b57b6020179bc2f14788 --- src/core/device-notifier.c | 79 +--------------------------------------------- 1 file changed, 1 insertion(+), 78 deletions(-) diff --git a/src/core/device-notifier.c b/src/core/device-notifier.c index c000f3a..9c266b9 100644 --- a/src/core/device-notifier.c +++ b/src/core/device-notifier.c @@ -18,21 +18,16 @@ #include "log.h" -#include "devices.h" #include "device-notifier.h" #include "list.h" #include "common.h" -#define LATE_INIT_WAIT_TIME 12 -#define DEFAULT_LATE_INIT_VALUE ((Ecore_Timer *)0x0DEF0DEF) - struct device_notifier { enum device_notifier_type status; int (*func)(void *data); }; static dd_list *device_notifier_list; -static Ecore_Timer *late_init_timer = DEFAULT_LATE_INIT_VALUE; #define FIND_NOTIFIER(a, b, d, e, f) \ DD_LIST_FOREACH(a, b, d) \ @@ -103,76 +98,4 @@ void device_notify(enum device_notifier_type status, void *data) } } } -} - -static void late_init_stop(void) -{ - if (late_init_timer == NULL || - late_init_timer == DEFAULT_LATE_INIT_VALUE) - return; - ecore_timer_del(late_init_timer); - late_init_timer = NULL; -} - -static int booting_done(void *data) -{ - static int done = 0; - - if (data == NULL) - goto out; - - done = *(int*)data; - if (late_init_timer == NULL) - return done; - late_init_stop(); -out: - return done; -} - -static Eina_Bool late_init_timer_cb(void *data) -{ - int done; - - late_init_stop(); - done = booting_done(NULL); - if (done) - return EINA_FALSE; - _I("late booting done"); - device_notify(DEVICE_NOTIFIER_BOOTING_DONE, &done); - return EINA_FALSE; -} - -static void device_notifier_init(void *data) -{ - int ret; - - ret = check_systemd_active(); - if (ret == TRUE) { - _I("restart booting done"); - return; - } - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); - late_init_timer = ecore_timer_add(LATE_INIT_WAIT_TIME, - late_init_timer_cb, NULL); - if (!late_init_timer) - late_init_timer = DEFAULT_LATE_INIT_VALUE; -} - -static void device_notifier_exit(void *data) -{ - dd_list *n; - struct device_notifier *notifier; - - DD_LIST_FOREACH(device_notifier_list, n, notifier) - DD_LIST_REMOVE(device_notifier_list, notifier); - free(notifier); -} - -static const struct device_ops notifier_device_ops = { - .priority = DEVICE_PRIORITY_NORMAL, - .name = "notifier", - .init = device_notifier_init, - .exit = device_notifier_exit, -}; - -DEVICE_OPS_REGISTER(¬ifier_device_ops) +} \ No newline at end of file -- 2.7.4 From ac9df0dd712fbf87a5972a8a18b3bc433f457d24 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Mon, 13 Apr 2015 12:51:33 +0900 Subject: [PATCH 09/16] deviced: Add tizen environment to deviced process To control display, deviced needs a DISPLAY enviroment value. So the dependency of tizen-system-env.service is added. Change-Id: I691015d54c12577c7e8b24df609069afaffc5bf7 Signed-off-by: Jiyoung Yun --- systemd/deviced.service | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/systemd/deviced.service b/systemd/deviced.service index 78f3746..38a153a 100644 --- a/systemd/deviced.service +++ b/systemd/deviced.service @@ -1,9 +1,10 @@ [Unit] Description=System device daemon After=deviced-pre.service -Requires=deviced-pre.service +Requires=deviced-pre.service tizen-system-env.service [Service] +EnvironmentFile=-/run/tizen-system-env EnvironmentFile=/run/deviced/deviced_env ExecStart=/usr/bin/deviced Restart=always -- 2.7.4 From 4db47141d1199639cace3a1baaddff742efd0c78 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Tue, 14 Apr 2015 10:07:16 +0900 Subject: [PATCH 10/16] deviced: Fix uninvoked device notifier func problem Device notifier is managed by a list. The list can be changed during other notifier callback function. So do not remove in unregister func. Instead it marks deleted and will be removed on deviced idle time. Change-Id: I7074c2ca99000c10bcfee44047d08de2f15cb7f1 Signed-off-by: Jiyoung Yun --- src/core/device-idler.c | 4 ++-- src/core/device-idler.h | 2 +- src/core/device-notifier.c | 40 +++++++++++++++++++++++++++++----------- src/power/power-handler.c | 4 +--- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/core/device-idler.c b/src/core/device-idler.c index 06e2317..e2af9a0 100644 --- a/src/core/device-idler.c +++ b/src/core/device-idler.c @@ -24,7 +24,7 @@ #include "log.h" struct device_request { - int (*func)(void *data); + void (*func)(void *data); void *data; }; @@ -77,7 +77,7 @@ static void process_next_request_in_idle(void) _E("fail to add request to idler"); } -int add_idle_request(int (*func)(void *data), void *data) +int add_idle_request(void (*func)(void *data), void *data) { struct device_request *req; diff --git a/src/core/device-idler.h b/src/core/device-idler.h index add2ecf..411e4bb 100644 --- a/src/core/device-idler.h +++ b/src/core/device-idler.h @@ -24,6 +24,6 @@ * To allow for callbacks to be called when the daemon is idle state. */ -int add_idle_request(int (*func)(void *data), void *data); +int add_idle_request(void (*func)(void *data), void *data); #endif /* __DEVICE_IDLER_H__ */ diff --git a/src/core/device-notifier.c b/src/core/device-notifier.c index 9c266b9..57610ec 100644 --- a/src/core/device-notifier.c +++ b/src/core/device-notifier.c @@ -23,11 +23,13 @@ #include "common.h" struct device_notifier { + bool deleted; enum device_notifier_type status; int (*func)(void *data); }; static dd_list *device_notifier_list; +static Ecore_Idler *idl; #define FIND_NOTIFIER(a, b, d, e, f) \ DD_LIST_FOREACH(a, b, d) \ @@ -51,7 +53,7 @@ int register_notifier(enum device_notifier_type status, int (*func)(void *data)) return -EINVAL; } - notifier = malloc(sizeof(struct device_notifier)); + notifier = calloc(1, sizeof(struct device_notifier)); if (!notifier) { _E("Fail to malloc for notifier!"); return -ENOMEM; @@ -77,25 +79,41 @@ int unregister_notifier(enum device_notifier_type status, int (*func)(void *data FIND_NOTIFIER(device_notifier_list, n, notifier, status, func) { _I("[%d, %x]", status, func); - DD_LIST_REMOVE(device_notifier_list, notifier); - free(notifier); + notifier->deleted = true; } return 0; } -void device_notify(enum device_notifier_type status, void *data) +static Eina_Bool delete_unused_notifier_cb(void *data) { - dd_list *n, *next; + dd_list *n; + dd_list *next; struct device_notifier *notifier; - int cnt = 0; DD_LIST_FOREACH_SAFE(device_notifier_list, n, next, notifier) { - if (status == notifier->status) { - if (notifier->func) { + if (notifier->deleted) { + DD_LIST_REMOVE_LIST(device_notifier_list, n); + free(notifier); + } + } + + idl = NULL; + return ECORE_CALLBACK_CANCEL; +} + +void device_notify(enum device_notifier_type status, void *data) +{ + dd_list *n; + struct device_notifier *notifier; + + DD_LIST_FOREACH(device_notifier_list, n, notifier) { + if (!notifier->deleted && status == notifier->status) { + if (notifier->func) notifier->func(data); - cnt++; - } } } -} \ No newline at end of file + + if (!idl) + idl = ecore_idler_add(delete_unused_notifier_cb, NULL); +} diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 3bda4c9..388e16e 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -247,7 +247,7 @@ static void poweroff_stop_systemd_service(void) umount2("/sys/fs/cgroup", MNT_FORCE |MNT_DETACH); } -static int poweroff_idler_cb(void *data) +static void poweroff_idler_cb(void *data) { enum poweroff_type val = (int)data; int ret; @@ -280,8 +280,6 @@ static int poweroff_idler_cb(void *data) if (update_pm_setting) update_pm_setting(SETTING_POWEROFF, val); - - return 0; } static int power_execute(void *data) -- 2.7.4 From 9afc91d7e0ff8831d8609181e708b74820d794bf Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Thu, 16 Apr 2015 20:16:41 +0900 Subject: [PATCH 11/16] deviced: Add udev monitoring logic Sometimes uevent from udev has more various information. In this case, deviced can use udev monitoring apis. Change-Id: I6d56620341a0d0ae23b691d4c172377f61672766 Signed-off-by: Jiyoung Yun --- src/core/udev.c | 264 +++++++++++++++++++++++--------------------------------- src/core/udev.h | 8 +- 2 files changed, 112 insertions(+), 160 deletions(-) diff --git a/src/core/udev.c b/src/core/udev.c index 2180d2b..865710a 100644 --- a/src/core/udev.c +++ b/src/core/udev.c @@ -19,6 +19,7 @@ #include #include +#include #include "log.h" #include "device-notifier.h" @@ -27,75 +28,90 @@ #include "list.h" #include "edbus-handler.h" -#define PREDEF_UDEV_CONTROL UDEV +#define KERNEL "kernel" +#define UDEV "udev" + +#define UDEV_MONITOR_SIZE (10*1024) + +struct uevent_info { + struct udev_monitor *mon; + Ecore_Fd_Handler *fdh; + dd_list *event_list; +}; /* Uevent */ static struct udev *udev; -/* Kernel Uevent */ -static struct udev_monitor *mon; -static Ecore_Fd_Handler *ufdh; -static int ufd = -1; -static dd_list *udev_event_list; +static struct uevent_info kevent; /* kernel */ +static struct uevent_info uevent; /* udev */ -static Eina_Bool uevent_kernel_control_cb(void *data, Ecore_Fd_Handler *fd_handler) +static Eina_Bool uevent_control_cb(void *data, Ecore_Fd_Handler *fd_handler) { + struct uevent_info *info = data; struct udev_device *dev; struct uevent_handler *l; dd_list *elem; const char *subsystem; + int len; + + assert(info); - if ((dev = udev_monitor_receive_device(mon)) == NULL) - return EINA_TRUE; + dev = udev_monitor_receive_device(info->mon); + if (!dev) + return ECORE_CALLBACK_RENEW; subsystem = udev_device_get_subsystem(dev); + if (!subsystem) + goto out; - DD_LIST_FOREACH(udev_event_list, elem, l) { - if (!strncmp(subsystem, l->subsystem, strlen(subsystem)) && + len = strlen(subsystem); + DD_LIST_FOREACH(info->event_list, elem, l) { + if (!strncmp(l->subsystem, subsystem, len) && l->uevent_func) l->uevent_func(dev); } +out: udev_device_unref(dev); - return EINA_TRUE; + return ECORE_CALLBACK_RENEW; } -static int uevent_kernel_control_stop(void) +static int uevent_control_stop(struct uevent_info *info) { - struct udev_device *dev = NULL; + struct udev_device *dev; - if (ufdh) { - ecore_main_fd_handler_del(ufdh); - ufdh = NULL; - } - if (ufd >= 0) { - close(ufd); - ufd = -1; + if (!info) + return -EINVAL; + + if (info->fdh) { + ecore_main_fd_handler_del(info->fdh); + info->fdh = NULL; } - if (mon) { - dev = udev_monitor_receive_device(mon); - if (dev) { + if (info->mon) { + dev = udev_monitor_receive_device(info->mon); + if (dev) udev_device_unref(dev); - dev = NULL; - } - udev_monitor_unref(mon); - mon = NULL; - } - if (udev) { - udev_unref(udev); - udev = NULL; + udev_monitor_unref(info->mon); + info->mon = NULL; } + if (udev) + udev = udev_unref(udev); return 0; } -static int uevent_kernel_control_start(void) +static int uevent_control_start(const char *type, + struct uevent_info *info) { struct uevent_handler *l; dd_list *elem; - int i, ret; + int fd; + int ret; + + if (!info) + return -EINVAL; - if (udev && mon) { - _E("uevent control routine is alreay started"); + if (info->mon) { + _E("%s uevent control routine is alreay started", type); return -EINVAL; } @@ -105,21 +121,25 @@ static int uevent_kernel_control_start(void) _E("error create udev"); return -EINVAL; } - } + } else + udev = udev_ref(udev); - mon = udev_monitor_new_from_netlink(udev, UDEV); - if (mon == NULL) { + info->mon = udev_monitor_new_from_netlink(udev, type); + if (info->mon == NULL) { _E("error udev_monitor create"); goto stop; } - if (udev_monitor_set_receive_buffer_size(mon, UDEV_MONITOR_SIZE) != 0) { + ret = udev_monitor_set_receive_buffer_size(info->mon, + UDEV_MONITOR_SIZE); + if (ret != 0) { _E("fail to set receive buffer size"); goto stop; } - DD_LIST_FOREACH(udev_event_list, elem, l) { - ret = udev_monitor_filter_add_match_subsystem_devtype(mon, + DD_LIST_FOREACH(info->event_list, elem, l) { + ret = udev_monitor_filter_add_match_subsystem_devtype( + info->mon, l->subsystem, NULL); if (ret < 0) { _E("error apply subsystem filter"); @@ -127,52 +147,54 @@ static int uevent_kernel_control_start(void) } } - ret = udev_monitor_filter_update(mon); + ret = udev_monitor_filter_update(info->mon); if (ret < 0) _E("error udev_monitor_filter_update"); - ufd = udev_monitor_get_fd(mon); - if (ufd == -1) { + fd = udev_monitor_get_fd(info->mon); + if (fd == -1) { _E("error udev_monitor_get_fd"); goto stop; } - ufdh = ecore_main_fd_handler_add(ufd, ECORE_FD_READ, - uevent_kernel_control_cb, NULL, NULL, NULL); - if (!ufdh) { + info->fdh = ecore_main_fd_handler_add(fd, ECORE_FD_READ, + uevent_control_cb, info, NULL, NULL); + if (!info->fdh) { _E("error ecore_main_fd_handler_add"); goto stop; } - if (udev_monitor_enable_receiving(mon) < 0) { + if (udev_monitor_enable_receiving(info->mon) < 0) { _E("error unable to subscribe to udev events"); goto stop; } return 0; stop: - uevent_kernel_control_stop(); + uevent_control_stop(info); return -EINVAL; - } -int register_kernel_uevent_control(const struct uevent_handler *uh) +static int register_uevent_control(struct uevent_info *info, + const struct uevent_handler *uh) { struct uevent_handler *l; dd_list *elem; int r; bool matched = false; + int len; - if (!uh) + if (!info || !uh || !uh->subsystem) return -EINVAL; /* if udev is not initialized, it just will be added list */ - if (!udev || !mon) + if (!udev || !info->mon) goto add_list; + len = strlen(uh->subsystem); /* check if the same subsystem is already added */ - DD_LIST_FOREACH(udev_event_list, elem, l) { - if (!strncmp(l->subsystem, uh->subsystem, strlen(l->subsystem))) { + DD_LIST_FOREACH(info->event_list, elem, l) { + if (!strncmp(l->subsystem, uh->subsystem, len)) { matched = true; break; } @@ -180,7 +202,7 @@ int register_kernel_uevent_control(const struct uevent_handler *uh) /* the first request to add subsystem */ if (!matched) { - r = udev_monitor_filter_add_match_subsystem_devtype(mon, + r = udev_monitor_filter_add_match_subsystem_devtype(info->mon, uh->subsystem, NULL); if (r < 0) { _E("fail to add %s subsystem : %d", uh->subsystem, r); @@ -188,24 +210,30 @@ int register_kernel_uevent_control(const struct uevent_handler *uh) } } - r = udev_monitor_filter_update(mon); + r = udev_monitor_filter_update(info->mon); if (r < 0) _E("fail to update udev monitor filter : %d", r); add_list: - DD_LIST_APPEND(udev_event_list, uh); + DD_LIST_APPEND(info->event_list, uh); return 0; } -int unregister_kernel_uevent_control(const struct uevent_handler *uh) +static int unregister_uevent_control(struct uevent_info *info, + const struct uevent_handler *uh) { struct uevent_handler *l; dd_list *n, *next; + int len; + + if (!info || !uh || !uh->subsystem) + return -EINVAL; - DD_LIST_FOREACH_SAFE(udev_event_list, n, next, l) { - if (!strncmp(l->subsystem, uh->subsystem, strlen(l->subsystem)) && + len = strlen(uh->subsystem); + DD_LIST_FOREACH_SAFE(info->event_list, n, next, l) { + if (!strncmp(l->subsystem, uh->subsystem, len) && l->uevent_func == uh->uevent_func) { - DD_LIST_REMOVE(udev_event_list, l); + DD_LIST_REMOVE(info->event_list, l); return 0; } } @@ -213,100 +241,30 @@ int unregister_kernel_uevent_control(const struct uevent_handler *uh) return -ENOENT; } -int uevent_udev_get_path(const char *subsystem, dd_list **list) +int register_kernel_uevent_control(const struct uevent_handler *uh) { - struct udev_enumerate *enumerate = NULL; - struct udev_list_entry *devices, *dev_list_entry; - int ret; - - if (!udev) { - udev = udev_new(); - if (!udev) { - _E("error create udev"); - return -EIO; - } - } - - enumerate = udev_enumerate_new(udev); - if (!enumerate) - return -EIO; - - ret = udev_enumerate_add_match_subsystem(enumerate, subsystem); - if (ret < 0) - return -EIO; - - ret = udev_enumerate_scan_devices(enumerate); - if (ret < 0) - return -EIO; - - devices = udev_enumerate_get_list_entry(enumerate); - - udev_list_entry_foreach(dev_list_entry, devices) { - const char *path; - path = udev_list_entry_get_name(dev_list_entry); - _D("subsystem : %s, path : %s", subsystem, path); - DD_LIST_APPEND(*list, (void*)path); - } - - return 0; + return register_uevent_control(&kevent, uh); } -static DBusMessage *dbus_udev_handler(E_DBus_Object *obj, DBusMessage *msg) +int unregister_kernel_uevent_control(const struct uevent_handler *uh) { - 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(argv, "start", strlen("start")) == 0) { - ret = uevent_kernel_control_start(); - } else if (strncmp(argv, "stop", strlen("stop")) == 0) { - ret = uevent_kernel_control_stop(); - } - -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 unregister_uevent_control(&kevent, uh); +} - return reply; +int register_udev_uevent_control(const struct uevent_handler *uh) +{ + return register_uevent_control(&uevent, uh); } -static const struct edbus_method edbus_methods[] = { - { PREDEF_UDEV_CONTROL, "sis","i", dbus_udev_handler }, -}; +int unregister_udev_uevent_control(const struct uevent_handler *uh) +{ + return unregister_uevent_control(&uevent, uh); +} static int device_change_poweroff(void *data) { - uevent_kernel_control_stop(); + uevent_control_stop(&kevent); + uevent_control_stop(&uevent); return 0; } @@ -316,15 +274,11 @@ static void udev_init(void *data) register_notifier(DEVICE_NOTIFIER_POWEROFF, device_change_poweroff); - ret = register_edbus_method(DEVICED_PATH_SYSNOTI, - edbus_methods, ARRAY_SIZE(edbus_methods)); - if (ret < 0) - _E("fail to init edbus method(%d)", ret); + if (uevent_control_start(KERNEL, &kevent) != 0) + _E("fail uevent kernel control init"); - if (uevent_kernel_control_start() != 0) { - _E("fail uevent control init"); - return; - } + if (uevent_control_start(UDEV, &uevent) != 0) + _E("fail uevent udev control init"); } static void udev_exit(void *data) diff --git a/src/core/udev.h b/src/core/udev.h index d8d69a6..49c6854 100644 --- a/src/core/udev.h +++ b/src/core/udev.h @@ -22,8 +22,6 @@ #include -#define UDEV "kernel" - #define UDEV_CHANGE "change" #define UDEV_ADD "add" #define UDEV_REMOVE "remove" @@ -31,9 +29,6 @@ #define UDEV_DEVPATH "DEVPATH" #define UDEV_DEVTYPE "DEVTYPE" -#define UDEV_MONITOR_SIZE (10*1024) -#define UDEV_MONITOR_SIZE_LARGE (128*1024*1024) - /* battery device */ #define POWER_SUBSYSTEM "power_supply" #define POWER_PATH "/sys/class/power_supply/battery" @@ -88,4 +83,7 @@ struct uevent_handler { int register_kernel_uevent_control(const struct uevent_handler *uh); int unregister_kernel_uevent_control(const struct uevent_handler *uh); +int register_udev_uevent_control(const struct uevent_handler *uh); +int unregister_udev_uevent_control(const struct uevent_handler *uh); + #endif /* __UDEV_H__ */ -- 2.7.4 From d51ff6119f8f528da406ba16c899d77d6bf31362 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Wed, 22 Apr 2015 16:34:05 +0900 Subject: [PATCH 12/16] cradle: Register missing exit function Change-Id: I2464cf219d44314b70fc56677de007888ad8bc83 Signed-off-by: Jiyoung Yun --- src/extcon/cradle.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/extcon/cradle.c b/src/extcon/cradle.c index 70614d4..9b83013 100644 --- a/src/extcon/cradle.c +++ b/src/extcon/cradle.c @@ -118,6 +118,7 @@ static void cradle_exit(void *data) static struct extcon_ops cradle_extcon_ops = { .name = EXTCON_CABLE_DOCK, .init = cradle_init, + .exit = cradle_exit, .update = cradle_update, }; -- 2.7.4 From 8bf360156de1b689c69755746da5dcce1195f5a5 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Thu, 23 Apr 2015 17:00:36 +0900 Subject: [PATCH 13/16] block: Seperate the mount/unmount code from mmc logic. There are two type of the supported block device type in deviced. * Scsi - USB HOST STORAGE * MMC - SD The exisiting mmc module has combined block device logic with mmc. To support scsi block devices, block logic is seperated. Block module supports to mount multi partition. The mount point is '/usr/storage/[uuid]'. To show the current mounted file system, deviced provides a below dbus method call. * object path: /Org/Tizen/System/DeviceD/Block * interface name: org.tizen.system.deviced.Block.ShowDeviceList TODO: Should be fixed the thread safety issue. Change-Id: Ie13544f3c2075018c238357167b35018448ff573 Signed-off-by: Jiyoung Yun --- CMakeLists.txt | 10 +- src/block/block.c | 795 +++++++++++++++++++++++++ src/{mmc/mmc-handler.h => block/block.h} | 44 +- src/{mmc => block}/ext4.c | 4 +- src/{mmc => block}/vfat.c | 4 +- src/core/udev.h | 2 + src/mmc/config.c | 104 ---- src/mmc/config.h | 31 - src/mmc/mmc-handler.c | 973 ------------------------------- src/mmc/mmc.conf | 3 - src/shared/dbus.h | 3 + 11 files changed, 836 insertions(+), 1137 deletions(-) create mode 100644 src/block/block.c rename src/{mmc/mmc-handler.h => block/block.h} (65%) rename src/{mmc => block}/ext4.c (97%) rename src/{mmc => block}/vfat.c (97%) delete mode 100644 src/mmc/config.c delete mode 100644 src/mmc/config.h delete mode 100644 src/mmc/mmc-handler.c delete mode 100644 src/mmc/mmc.conf diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f9b2b2..ba1e3e6 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,9 @@ SET(CONFDIR "/etc/${PROJECT_NAME}") SET(VERSION 0.1.0) SET(SRCS + src/block/block.c + src/block/ext4.c + src/block/vfat.c src/core/common.c src/core/config-parser.c src/control/control.c @@ -68,13 +71,6 @@ SET(SRCS ${SRCS} src/gpio/hall.c) ENDIF(TIZEN_HALL) -SET(SRCS ${SRCS} - src/mmc/config.c - src/mmc/mmc-handler.c - src/mmc/vfat.c - src/mmc/ext4.c - ) - IF(TIZEN_SIM) SET(SRCS ${SRCS} src/gpio/sim.c) diff --git a/src/block/block.c b/src/block/block.c new file mode 100644 index 0000000..a2911e8 --- /dev/null +++ b/src/block/block.c @@ -0,0 +1,795 @@ +/* + * deviced + * + * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "core/log.h" +#include "core/device-notifier.h" +#include "core/devices.h" +#include "core/udev.h" +#include "core/edbus-handler.h" +#include "core/list.h" +#include "block.h" + +/** + * TODO Assume root device is always mmcblk0*. + */ +#define MMC_PATH "*/mmcblk[1-9]*" +#define MMC_PARTITION_PATH "mmcblk[1-9]p[0-9]" +#define SCSI_PATH "*/sd[a-z]*" +#define SCSI_PARTITION_PATH "sd[a-z][0-9]" + +#define FILESYSTEM "filesystem" + +#define UNMOUNT_RETRY 5 + +struct block_device { + int deleted; + pthread_mutex_t mutex; + struct block_data *data; +}; + +enum unmount_operation { + UNMOUNT_NORMAL, + UNMOUNT_FORCE, +}; + +static dd_list *fs_head; +static dd_list *block_dev_list; +static bool smack; + +static void __CONSTRUCTOR__ smack_check(void) +{ + FILE *fp; + char buf[128]; + + fp = fopen("/proc/filesystems", "r"); + if (!fp) + return; + + while (fgets(buf, sizeof(buf), fp) != NULL) { + if (strstr(buf, "smackfs")) { + smack = true; + break; + } + } + + fclose(fp); +} + +void add_fs(const struct mmc_fs_ops *fs) +{ + DD_LIST_APPEND(fs_head, (void *)fs); +} + +void remove_fs(const struct mmc_fs_ops *fs) +{ + DD_LIST_REMOVE(fs_head, (void *)fs); +} + +const struct mmc_fs_ops *find_fs(enum mmc_fs_type type) +{ + struct mmc_fs_ops *fs; + dd_list *elem; + + DD_LIST_FOREACH(fs_head, elem, fs) { + if (fs->type == type) + return fs; + } + return NULL; +} + +/* Whole data in struct block_data should be freed. */ +static struct block_data *make_block_data(const char *devnode, + const char *fs_usage, + const char *fs_type, + const char *fs_version, + const char *fs_uuid_enc, + const char *readonly) +{ + struct block_data *data; + const char *str; + + data = calloc(1, sizeof(struct block_data)); + if (!data) + return NULL; + + if (devnode) + data->devnode = strdup(devnode); + if (fs_usage) + data->fs_usage = strdup(fs_usage); + if (fs_type) + data->fs_type = strdup(fs_type); + if (fs_version) + data->fs_version = strdup(fs_version); + if (fs_uuid_enc) { + data->fs_uuid_enc = strdup(fs_uuid_enc); + str = tzplatform_mkpath(TZ_SYS_STORAGE, fs_uuid_enc); + if (str) + data->mount_point = strdup(str); + } + if (readonly) + data->readonly = atoi(readonly); + + /* TODO should we know block dev type? */ + if (!fnmatch(MMC_PATH, devnode, 0)) + data->block_type = BLOCK_MMC_DEV; + else if (!fnmatch(SCSI_PATH, devnode, 0)) + data->block_type = BLOCK_SCSI_DEV; + else + data->block_type = -1; + + return data; +} + +static void free_block_data(struct block_data *data) +{ + if (!data) + return; + free(data->devnode); + free(data->fs_usage); + free(data->fs_type); + free(data->fs_version); + free(data->fs_uuid_enc); + free(data->mount_point); + free(data); +} + +static struct block_device *make_block_device(struct block_data *data) +{ + struct block_device *bdev; + + bdev = calloc(1, sizeof(struct block_device)); + if (!bdev) + return NULL; + + pthread_mutex_init(&bdev->mutex, NULL); + bdev->data = data; + return bdev; +} + +static struct block_device *find_block_device(const char *devnode) +{ + struct block_device *bdev; + dd_list *elem; + int len; + + len = strlen(devnode) + 1; + DD_LIST_FOREACH(block_dev_list, elem, bdev) { + if (!bdev->deleted && + bdev->data && + !strncmp(bdev->data->devnode, devnode, len)) + return bdev; + } + + return NULL; +} + +static int mmc_check_and_unmount(const char *path) +{ + int ret = 0; + int retry = 0; + + while (mount_check(path)) { + ret = umount(path); + if (ret < 0) { + retry++; + if (retry > UNMOUNT_RETRY) + return -errno; + } + } + return ret; +} + +static bool check_rw_mount(const char *szPath) +{ + struct statvfs mount_stat; + + if (!statvfs(szPath, &mount_stat)) { + if ((mount_stat.f_flag & ST_RDONLY) == ST_RDONLY) + return false; + } + return true; +} + +static int block_mount(struct block_data *data) +{ + struct mmc_fs_ops *fs; + dd_list *elem; + int r; + int len; + + if (!data || !data->devnode || !data->mount_point) + return -EINVAL; + + /* check existing mounted */ + if (mount_check(data->mount_point)) + return -EEXIST; + + /* create mount point */ + if (access(data->mount_point, R_OK) != 0) { + if (mkdir(data->mount_point, 0755) < 0) + return -errno; + } + + /* check matched file system */ + if (!data->fs_usage || + strncmp(data->fs_usage, FILESYSTEM, + sizeof(FILESYSTEM)) != 0) { + r = -ENODEV; + goto out; + } + + fs = NULL; + if (data->fs_type) { + len = strlen(data->fs_type) + 1; + DD_LIST_FOREACH(fs_head, elem, fs) { + if (!strncmp(fs->name, data->fs_type, len)) + break; + } + } + + if (!fs) { + r = -ENODEV; + goto out; + } + + r = fs->mount(smack, data->devnode, data->mount_point); + if (r < 0) + goto out; + + r = check_rw_mount(data->mount_point); + if (!r) + return -EROFS; + + return 0; + +out: + rmdir(data->mount_point); + return r; +} + +/* runs in thread */ +static void *mount_start(void *arg) +{ + struct block_device *bdev = (struct block_device *)arg; + struct block_data *data; + struct storage_info *info; + int r; + + assert(bdev); + assert(bdev->data); + + data = bdev->data; + _I("Mount Start : (%s -> %s)", + data->devnode, data->mount_point); + + pthread_mutex_lock(&bdev->mutex); + + /* mount operation */ + r = block_mount(data); + if (r != -EROFS && r < 0) { + _E("fail to mount %s device : %d", data->devnode, r); + goto out; + } + + if (r == -EROFS) + data->readonly = true; + + data->state = BLOCK_MOUNT; + +out: + _I("%s result : %s, %d", __func__, data->devnode, r); + pthread_mutex_unlock(&bdev->mutex); + + return NULL; +} + +static int mount_block_device(struct block_device *bdev) +{ + struct block_data *data; + pthread_t th; + int r; + + if (!bdev && !bdev->data) { + _E("invalid parameter"); + return -EINVAL; + } + + data = bdev->data; + if (data->state == BLOCK_MOUNT) { + _I("%s is already mounted", data->devnode); + return 0; + } + + r = pthread_create(&th, NULL, mount_start, bdev); + if (r != 0) { + _E("fail to create thread for %s", data->devnode); + return -EPERM; + } + + pthread_detach(th); + return 0; +} + +static int block_unmount(struct block_data *data, + enum unmount_operation option) +{ + int r, retry = 0; + + if (!data || !data->mount_point) + return -EINVAL; + + /* it must called before unmounting mmc */ + r = mmc_check_and_unmount(data->mount_point); + if (!r) + goto out; + if (option == UNMOUNT_NORMAL) { + _I("Failed to unmount with normal option : %d", r); + return r; + } + + _I("Execute force unmount!"); + /* Force Unmount Scenario */ + while (1) { + switch (retry++) { + case 0: + /* At first, notify to other app + * who already access sdcard */ + _I("Notify to other app who already access sdcard"); + break; + case 1: + /* Second, kill app with SIGTERM */ + _I("Kill app with SIGTERM"); + terminate_process(data->mount_point, false); + break; + case 2: + /* Last time, kill app with SIGKILL */ + _I("Kill app with SIGKILL"); + terminate_process(data->mount_point, true); + break; + default: + if (umount2(data->mount_point, MNT_DETACH) != 0) { + _I("Failed to unmount with lazy option : %d", + errno); + return -errno; + } + goto out; + } + + /* it takes some seconds til other app completely clean up */ + usleep(500*1000); + + r = mmc_check_and_unmount(data->mount_point); + if (!r) + break; + } + +out: + if (rmdir(data->mount_point) < 0) + _E("fail to remove %s directory", data->mount_point); + + return r; +} + +static int unmount_block_device(struct block_device *bdev, + enum unmount_operation option) +{ + struct block_data *data; + int r; + + if (!bdev && !bdev->data) { + _E("invalid argument"); + return -EINVAL; + } + + data = bdev->data; + if (data->state == BLOCK_UNMOUNT) { + _I("%s is already unmounted", data->devnode); + return 0; + } + + _I("Unmount Start : (%s -> %s)", + data->devnode, data->mount_point); + + pthread_mutex_lock(&bdev->mutex); + + r = block_unmount(data, option); + if (r < 0) { + _E("fail to unmount %s device : %d", data->devnode, r); + goto out; + } + + data->state = BLOCK_UNMOUNT; + +out: + _I("%s result : %s, %d", __func__, data->devnode, r); + pthread_mutex_unlock(&bdev->mutex); + + return r; +} + +static bool disk_is_partitioned_by_kernel(struct udev_device *dev) +{ + DIR *dp; + struct dirent *dir; + const char *syspath; + bool ret = false; + + syspath = udev_device_get_syspath(dev); + if (!syspath) + goto out; + + dp = opendir(syspath); + if (!dp) { + _E("fail to open %s", syspath); + goto out; + } + + /* TODO compare devname and d_name */ + while ((dir = readdir(dp)) != NULL) { + if (!fnmatch(MMC_PARTITION_PATH, dir->d_name, 0) || + !fnmatch(SCSI_PARTITION_PATH, dir->d_name, 0)) { + ret = true; + break; + } + } + + closedir(dp); + +out: + return ret; +} + +static bool check_partition(struct udev_device *dev) +{ + static const char *fs = "filesystem"; + const char *devtype; + const char *part_table_type; + const char *fs_usage; + bool ret = false; + + /* only consider disk type, never partitions */ + devtype = udev_device_get_devtype(dev); + if (!devtype) + goto out; + + if (strncmp(devtype, BLOCK_DEVTYPE_DISK, + sizeof(BLOCK_DEVTYPE_DISK)) != 0) + goto out; + + part_table_type = udev_device_get_property_value(dev, + "ID_PART_TABLE_TYPE"); + if (part_table_type) { + fs_usage = udev_device_get_property_value(dev, + "ID_FS_USAGE"); + if (fs_usage && strncmp(fs_usage, fs, strlen(fs) + 1) == 0) { + if (!disk_is_partitioned_by_kernel(dev)) + goto out; + } + ret = true; + goto out; + } + + if (disk_is_partitioned_by_kernel(dev)) { + ret = true; + goto out; + } + +out: + return ret; +} + +static int add_block_device(struct udev_device *dev, const char *devnode) +{ + struct block_data *data; + struct block_device *bdev; + bool partition; + int ret; + + partition = check_partition(dev); + if (partition) { + /* if there is a partition, skip this request */ + _I("%s device has partitions, skip this time", devnode); + return 0; + } + + data = make_block_data(devnode, + udev_device_get_property_value(dev, "ID_FS_USAGE"), + udev_device_get_property_value(dev, "ID_FS_TYPE"), + udev_device_get_property_value(dev, "ID_FS_VERSION"), + udev_device_get_property_value(dev, "ID_FS_UUID_ENC"), + udev_device_get_sysattr_value(dev, "ro")); + if (!data) { + _E("fail to make block data for %s", devnode); + return -EPERM; + } + + bdev = make_block_device(data); + if (!bdev) { + _E("fail to make block device for %s", devnode); + free_block_data(data); + return -EPERM; + } + + /** + * Add the data into list. + * The block data keep until the devnode is removed. + */ + DD_LIST_APPEND(block_dev_list, bdev); + + ret = mount_block_device(bdev); + if (ret < 0) { + _E("fail to mount block device for %s", devnode); + return ret; + } + + return 0; +} + +static int remove_block_device(struct udev_device *dev, const char *devnode) +{ + struct block_device *bdev; + int r; + + bdev = find_block_device(devnode); + if (!bdev) { + _E("fail to find block data for %s", devnode); + return -ENODEV; + } + + r = unmount_block_device(bdev, UNMOUNT_NORMAL); + if (r < 0) + _E("fail to unmount block device for %s", devnode); + + /* check deleted */ + bdev->deleted = true; + + return 0; +} + +static int block_init_from_udev_enumerate(void) +{ + struct udev *udev; + struct udev_enumerate *enumerate; + struct udev_list_entry *list_entry; + struct udev_device *dev; + const char *syspath; + const char *devnode; + int ret; + + udev = udev_new(); + if (!udev) { + _E("fail to create udev library context"); + return -EPERM; + } + + /* create a list of the devices in the 'usb' subsystem */ + enumerate = udev_enumerate_new(udev); + if (!enumerate) { + _E("fail to create an enumeration context"); + return -EPERM; + } + + udev_enumerate_add_match_subsystem(enumerate, BLOCK_SUBSYSTEM); + udev_enumerate_add_match_property(enumerate, + UDEV_DEVTYPE, BLOCK_DEVTYPE_DISK); + udev_enumerate_add_match_property(enumerate, + UDEV_DEVTYPE, BLOCK_DEVTYPE_PARTITION); + udev_enumerate_scan_devices(enumerate); + + udev_list_entry_foreach(list_entry, + udev_enumerate_get_list_entry(enumerate)) { + syspath = udev_list_entry_get_name(list_entry); + if (!syspath) + continue; + + dev = udev_device_new_from_syspath( + udev_enumerate_get_udev(enumerate), + syspath); + if (!dev) + continue; + + if (fnmatch(MMC_PATH, syspath, 0) && + fnmatch(SCSI_PATH, syspath, 0)) + continue; + + devnode = udev_device_get_devnode(dev); + if (!devnode) + continue; + + _D("%s device add", devnode); + add_block_device(dev, devnode); + + udev_device_unref(dev); + } + + udev_enumerate_unref(enumerate); + udev_unref(udev); + return 0; +} + +static int booting_done(void *data) +{ + /* if there is the attached device, try to mount */ + block_init_from_udev_enumerate(); + return 0; +} + +static void show_block_device_list(void) +{ + struct block_device *bdev; + struct block_data *data; + dd_list *elem; + + DD_LIST_FOREACH(block_dev_list, elem, bdev) { + data = bdev->data; + if (!data) + continue; + _D("%s:", data->devnode); + _D("\tBlock type: %s", + (data->block_type == BLOCK_MMC_DEV ? + "mmc" : "scsi")); + _D("\tFs type: %s", data->fs_type); + _D("\tFs usage: %s", data->fs_usage); + _D("\tFs version: %s", data->fs_version); + _D("\tFs uuid enc: %s", data->fs_uuid_enc); + _D("\tReadonly: %s", + (data->readonly ? "true" : "false")); + _D("\tMount point: %s", data->mount_point); + _D("\tMount state: %s", + (data->state == BLOCK_MOUNT ? + "mount" : "unmount")); + _D("\tRemove: %s", (bdev->deleted ? "true" : "false")); + } +} + +static void remove_whole_block_device(void) +{ + struct block_device *bdev; + dd_list *elem; + dd_list *next; + + DD_LIST_FOREACH_SAFE(block_dev_list, elem, next, bdev) { + unmount_block_device(bdev, UNMOUNT_NORMAL); + DD_LIST_REMOVE_LIST(block_dev_list, elem); + free_block_data(bdev->data); + free(bdev); + } +} + +static int remove_unmountable_blocks(void *user_data) +{ + struct block_device *bdev; + dd_list *elem; + dd_list *next; + + DD_LIST_FOREACH_SAFE(block_dev_list, elem, next, bdev) { + if (bdev->deleted) { + DD_LIST_REMOVE_LIST(block_dev_list, elem); + pthread_mutex_lock(&bdev->mutex); + free_block_data(bdev->data); + pthread_mutex_unlock(&bdev->mutex); + free(bdev); + } + } + return 0; +} + +static void uevent_block_handler(struct udev_device *dev) +{ + const char *devnode; + const char *action; + + devnode = udev_device_get_devnode(dev); + if (!devnode) + return; + + if (fnmatch(MMC_PATH, devnode, 0) && + fnmatch(SCSI_PATH, devnode, 0)) + return; + + action = udev_device_get_action(dev); + if (!action) + return; + + _D("%s device %s", devnode, action); + if (!strncmp(action, UDEV_ADD, sizeof(UDEV_ADD))) + add_block_device(dev, devnode); + else if (!strncmp(action, UDEV_REMOVE, sizeof(UDEV_REMOVE))) + remove_block_device(dev, devnode); + + /* add idler queue to remove unmountable block datas */ + add_idle_request(remove_unmountable_blocks, NULL); +} + +static DBusMessage *request_show_device_list(E_DBus_Object *obj, + DBusMessage *msg) +{ + show_block_device_list(); + return dbus_message_new_method_return(msg); +} + +static struct uevent_handler uh = { + .subsystem = BLOCK_SUBSYSTEM, + .uevent_func = uevent_block_handler, +}; + +static const struct edbus_method edbus_methods[] = { + { "ShowDeviceList", NULL, NULL, request_show_device_list }, +}; + +static void block_init(void *data) +{ + struct block_dev_ops *dev; + dd_list *elem; + int ret; + + ret = register_edbus_interface_and_method(DEVICED_PATH_BLOCK, + DEVICED_INTERFACE_BLOCK, + edbus_methods, ARRAY_SIZE(edbus_methods)); + if (ret < 0) + _E("fail to init edbus interface and method(%d)", ret); + + /* register mmc uevent control routine */ + ret = register_udev_uevent_control(&uh); + if (ret < 0) + _E("fail to register extcon uevent : %d", ret); + + /* register notifier */ + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); +} + +static void block_exit(void *data) +{ + int ret; + + /* unregister notifier */ + unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + + /* unregister mmc uevent control routine */ + ret = unregister_udev_uevent_control(&uh); + if (ret < 0) + _E("fail to unregister extcon uevent : %d", ret); + + /* remove remaining blocks */ + remove_whole_block_device(); +} + +const struct device_ops block_device_ops = { + .name = "block", + .init = block_init, + .exit = block_exit, +}; + +DEVICE_OPS_REGISTER(&block_device_ops) diff --git a/src/mmc/mmc-handler.h b/src/block/block.h similarity index 65% rename from src/mmc/mmc-handler.h rename to src/block/block.h index 4406c88..c60a650 100644 --- a/src/mmc/mmc-handler.h +++ b/src/block/block.h @@ -1,7 +1,7 @@ /* * deviced * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. + * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -17,17 +17,11 @@ */ -#ifndef __MMC_HANDLER_H__ -#define __MMC_HANDLER_H__ +#ifndef __BLOCK_H__ +#define __BLOCK_H__ #include -#include - -#define SMACKFS_MOUNT_OPT "smackfsroot=*,smackfsdef=*" -#define MMC_MOUNT_POINT tzplatform_mkpath(TZ_SYS_STORAGE,"sdcard") - -#define BUF_LEN 20 -#define RETRY_COUNT 10 +#include "core/common.h" enum mmc_fs_type { FS_TYPE_VFAT = 0, @@ -53,10 +47,30 @@ struct fs_check { void add_fs(const struct mmc_fs_ops *fs); void remove_fs(const struct mmc_fs_ops *fs); -int get_mmc_devpath(char devpath[]); -bool mmc_check_mounted(const char *mount_point); -int get_block_number(void); +enum block_device_type { + BLOCK_SCSI_DEV, + BLOCK_MMC_DEV, +}; + +enum mount_state { + BLOCK_UNMOUNT, + BLOCK_MOUNT, +}; + +struct block_data { + enum block_device_type block_type; + char *devnode; + char *fs_usage; + char *fs_type; + char *fs_version; + char *fs_uuid_enc; + bool readonly; + char *mount_point; + enum mount_state state; +}; + +#define SMACKFS_MOUNT_OPT "smackfsroot=*,smackfsdef=*" +#define RETRY_COUNT 10 -void mmc_mount_done(void); -#endif /* __MMC_HANDLER_H__ */ +#endif /* __BLOCK_H__ */ diff --git a/src/mmc/ext4.c b/src/block/ext4.c similarity index 97% rename from src/mmc/ext4.c rename to src/block/ext4.c index c443016..df452f4 100644 --- a/src/mmc/ext4.c +++ b/src/block/ext4.c @@ -1,7 +1,7 @@ /* * deviced * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. + * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -29,7 +29,7 @@ #include "core/common.h" #include "core/devices.h" #include "core/log.h" -#include "mmc-handler.h" +#include "block.h" #define FS_EXT4_NAME "ext4" diff --git a/src/mmc/vfat.c b/src/block/vfat.c similarity index 97% rename from src/mmc/vfat.c rename to src/block/vfat.c index 75ddeca..5934b0b 100644 --- a/src/mmc/vfat.c +++ b/src/block/vfat.c @@ -1,7 +1,7 @@ /* * deviced * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. + * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ #include "core/common.h" #include "core/log.h" -#include "mmc-handler.h" +#include "block.h" #define FS_VFAT_NAME "mkdosfs" diff --git a/src/core/udev.h b/src/core/udev.h index 49c6854..5a090ca 100644 --- a/src/core/udev.h +++ b/src/core/udev.h @@ -51,6 +51,8 @@ /* block */ #define BLOCK_SUBSYSTEM "block" +#define BLOCK_DEVTYPE_DISK "disk" +#define BLOCK_DEVTYPE_PARTITION "partition" /* power supply status */ enum { diff --git a/src/mmc/config.c b/src/mmc/config.c deleted file mode 100644 index 7202f16..0000000 --- a/src/mmc/config.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include -#include - -#include "core/log.h" -#include "core/common.h" -#include "core/config-parser.h" -#include "mmc-handler.h" -#include "config.h" - -#define MAX_RATIO_CONF_FILE "/etc/deviced/mmc.conf" -#define MAX_RATIO_PATH "/sys/class/block/mmcblk%d/bdi/max_ratio" -#define MAX_RATIO_CONFIG_RETRY 5 -#define MAX_RATIO_DURATION 100 - -static struct mmc_policy_type { - int max_ratio; -} mmc_policy = { - .max_ratio = MAX_RATIO_DURATION, -}; - -static void mmc_max_ratio(void) -{ - char buf[PATH_MAX]; - FILE *fp; - int ret; - int num; - int retry; - - num = get_block_number(); - snprintf(buf, PATH_MAX, MAX_RATIO_PATH, num); - - for (retry = MAX_RATIO_CONFIG_RETRY; retry > 0 ; retry--) { - ret = sys_set_int(buf, mmc_policy.max_ratio); - if (ret == 0) - break; - } - if (ret < 0) - _E("fail path : %s max_ratio: %d ret %d", buf, mmc_policy.max_ratio, ret); - else - _D("mmc bdi max : %d", mmc_policy.max_ratio); -} - -static int load_config(struct parse_result *result, void *user_data) -{ - struct mmc_policy_type *policy = user_data; - char *name; - char *value; - - _D("%s,%s,%s", result->section, result->name, result->value); - - if (!policy) - return -EINVAL; - - if (!MATCH(result->section, "MMC")) - return -EINVAL; - - name = result->name; - value = result->value; - if (MATCH(name, "MaxRatio")) - policy->max_ratio = atoi(value); - - return 0; -} - -void mmc_load_config(void) -{ - int ret; - ret = config_parse(MAX_RATIO_CONF_FILE, load_config, &mmc_policy); - if (ret < 0) - _E("Failed to load %s, %d Use default value!", MAX_RATIO_CONF_FILE, ret); -} - -void mmc_set_config(enum mmc_config_type type) -{ - switch(type) { - case MAX_RATIO: - mmc_max_ratio(); - break; - } -} diff --git a/src/mmc/config.h b/src/mmc/config.h deleted file mode 100644 index 0397910..0000000 --- a/src/mmc/config.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 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 __MMC_CONFIG_H__ -#define __MMC_CONFIG_H__ - -#include - -enum mmc_config_type { - MAX_RATIO = 0, -}; - -void mmc_set_config(enum mmc_config_type type); -void mmc_load_config(void); -#endif /* __MMC_CONFIG_H__ */ diff --git a/src/mmc/mmc-handler.c b/src/mmc/mmc-handler.c deleted file mode 100644 index b3a85d6..0000000 --- a/src/mmc/mmc-handler.c +++ /dev/null @@ -1,973 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "core/log.h" -#include "core/device-notifier.h" -#include "core/common.h" -#include "core/devices.h" -#include "core/udev.h" -#include "mmc-handler.h" -#include "config.h" -#include "core/edbus-handler.h" -#include "core/list.h" -#include "core/config-parser.h" - -#define MMC_PARENT_PATH tzplatform_getenv(TZ_SYS_STORAGE) -#define MMC_DEV "/dev/mmcblk" -#define MMC_PATH "*/mmcblk[0-9]" - -#define SMACKFS_MAGIC 0x43415d53 -#define SMACKFS_MNT "/smack" - -#ifndef ST_RDONLY -#define ST_RDONLY 0x0001 -#endif - -#define MMC_32GB_SIZE 61315072 -#define FORMAT_RETRY 3 -#define UNMOUNT_RETRY 5 - -#define SMACK_LABELING_TIME (0.5) - -enum unmount_operation { - UNMOUNT_NORMAL = 0, - UNMOUNT_FORCE, -}; - -enum mmc_operation { - MMC_MOUNT = 0, - MMC_UNMOUNT, - MMC_FORMAT, - MMC_END, -}; - -static void *mount_start(void *arg); -static void *unmount_start(void *arg); -static void *format_start(void *arg); - -static const struct mmc_thread_func { - enum mmc_operation type; - void *(*func) (void*); -} mmc_func[MMC_END] = { - [MMC_MOUNT] = {.type = MMC_MOUNT, .func = mount_start}, - [MMC_UNMOUNT] = {.type = MMC_UNMOUNT, .func = unmount_start}, - [MMC_FORMAT] = {.type = MMC_FORMAT, .func = format_start}, -}; - -struct mmc_data { - int option; - char *devpath; -}; - -static dd_list *fs_head; -static char *mmc_curpath; -static bool smack = false; -static bool mmc_disabled = false; -static Ecore_Timer *smack_timer = NULL; - -static void __CONSTRUCTOR__ smack_check(void) -{ - struct statfs sfs; - int ret; - - do { - ret = statfs(SMACKFS_MNT, &sfs); - } while (ret < 0 && errno == EINTR); - - if (ret == 0 && sfs.f_type == SMACKFS_MAGIC) - smack = true; - _I("smackfs check %d", smack); -} - -void add_fs(const struct mmc_fs_ops *fs) -{ - DD_LIST_APPEND(fs_head, (void*)fs); -} - -void remove_fs(const struct mmc_fs_ops *fs) -{ - DD_LIST_REMOVE(fs_head, (void*)fs); -} - -const struct mmc_fs_ops *find_fs(enum mmc_fs_type type) -{ - struct mmc_fs_ops *fs; - dd_list *elem; - - DD_LIST_FOREACH(fs_head, elem, fs) { - if (fs->type == type) - return fs; - } - return NULL; -} - -bool mmc_check_mounted(const char *mount_point) -{ - struct stat parent_stat, mount_stat; - char parent_path[PATH_MAX]; - - snprintf(parent_path, sizeof(parent_path), "%s", MMC_PARENT_PATH); - - if (stat(mount_point, &mount_stat) != 0 || stat(parent_path, &parent_stat) != 0) - return false; - - if (mount_stat.st_dev == parent_stat.st_dev) - return false; - - return true; -} - -static void launch_syspopup(char *str) -{ - manage_notification("MMC", str); -} - -static int get_partition(const char *devpath, char *subpath) -{ - char path[NAME_MAX]; - int i; - - for (i = 1; i < 5; ++i) { - snprintf(path, sizeof(path), "%sp%d", devpath, i); - if (!access(path, R_OK)) { - strncpy(subpath, path, strlen(path)); - return 0; - } - } - return -ENODEV; -} - -static int create_partition(const char *devpath) -{ - int r; - char data[NAME_MAX]; - - snprintf(data, sizeof(data), "\"n\\n\\n\\n\\n\\nw\" | fdisk %s", devpath); - - r = launch_evenif_exist("/usr/bin/printf", data); - if (WIFSIGNALED(r) && (WTERMSIG(r) == SIGINT || WTERMSIG(r) == SIGQUIT || WEXITSTATUS(r))) - return -1; - - return 0; -} - -static int mmc_check_and_unmount(const char *path) -{ - int ret = 0, retry = 0; - while (mount_check(path)) { - ret = umount(path); - if (ret < 0) { - retry++; - if (retry > UNMOUNT_RETRY) - return -errno; - } - } - return ret; -} - -int get_block_number(void) -{ - DIR *dp; - struct dirent *dir; - struct stat stat; - char buf[255]; - int fd; - int r; - int mmcblk_num; - char *pre_mmc_device_id = NULL; - int mmc_dev_changed = 0; - - if ((dp = opendir("/sys/block")) == NULL) { - _E("Can not open directory.."); - return -1; - } - - r = chdir("/sys/block"); - if (r < 0) { - _E("Fail to change the directory.."); - closedir(dp); - return r; - } - - while ((dir = readdir(dp)) != NULL) { - memset(&stat, 0, sizeof(struct stat)); - if(lstat(dir->d_name, &stat) < 0) {continue;} - if (S_ISDIR(stat.st_mode) || S_ISLNK(stat.st_mode)) { - if (strncmp(".", dir->d_name, 1) == 0 - || strncmp("..", dir->d_name, 2) == 0) - continue; - if (strncmp("mmcblk", dir->d_name, 6) == 0) { - snprintf(buf, 255, "/sys/block/%s/device/type", - dir->d_name); - - fd = open(buf, O_RDONLY); - if (fd == -1) { - continue; - } - r = read(fd, buf, 10); - if ((r >= 0) && (r < 10)) - buf[r] = '\0'; - else - _E("%s read error: %s", buf, - strerror(errno)); - close(fd); - if (strncmp("SD", buf, 2) == 0) { - char *str_mmcblk_num = strndup((dir->d_name) + 6, 1); - if (str_mmcblk_num == NULL) { - _E("Memory Allocation Failed"); - closedir(dp); - return -1; - } - mmcblk_num = - atoi(str_mmcblk_num); - - free(str_mmcblk_num); - closedir(dp); - _I("%d", mmcblk_num); - - snprintf(buf, 255, "/sys/block/%s/device/cid", dir->d_name); - - fd = open(buf, O_RDONLY); - if (fd == -1) { - _E("%s open error", buf, strerror(errno)); - return mmcblk_num; - } - r = read(fd, buf, 255); - if ((r >=0) && (r < 255)) { - buf[r] = '\0'; - } else { - _E("%s read error: %s", buf,strerror(errno)); - } - close(fd); - return mmcblk_num; - } - } - - } - } - closedir(dp); - _E("failed to find mmc block number"); - return -1; -} - -static int find_mmc_node(char devpath[]) -{ - int num; - - num = get_block_number(); - if (num < 0) - return -ENODEV; - - snprintf(devpath, NAME_MAX, "%s%d", MMC_DEV, num); - return 0; -} - -static int get_mmc_size(const char *devpath) -{ - int fd, r; - unsigned long long ullbytes; - unsigned int nbytes; - - fd = open(devpath, O_RDONLY); - if (fd < 0) { - _E("open error"); - return -EINVAL; - } - - r = ioctl(fd, BLKGETSIZE64, &ullbytes); - close(fd); - - if (r < 0) { - _E("ioctl BLKGETSIZE64 error"); - return -EINVAL; - } - - nbytes = ullbytes/512; - _I("block size(64) : %d", nbytes); - return nbytes; -} - -static int rw_mount(const char *szPath) -{ - struct statvfs mount_stat; - if (!statvfs(szPath, &mount_stat)) { - if ((mount_stat.f_flag & ST_RDONLY) == ST_RDONLY) - return -1; - } - return 0; -} - -static Eina_Bool smack_timer_cb(void *data) -{ - if (smack_timer) { - ecore_timer_del(smack_timer); - smack_timer = NULL; - } - vconf_set_int(VCONFKEY_SYSMAN_MMC_STATUS, VCONFKEY_SYSMAN_MMC_MOUNTED); - vconf_set_int(VCONFKEY_SYSMAN_MMC_MOUNT, VCONFKEY_SYSMAN_MMC_MOUNT_COMPLETED); - return EINA_FALSE; -} - -void mmc_mount_done(void) -{ - smack_timer = ecore_timer_add(SMACK_LABELING_TIME, - smack_timer_cb, NULL); - if (smack_timer) { - _I("Wait to check"); - return; - } - _E("Fail to add abnormal check timer"); - smack_timer_cb(NULL); -} - -static int mmc_mount(const char *devpath, const char *mount_point) -{ - struct mmc_fs_ops *fs; - dd_list *elem; - char path[NAME_MAX] = {0,}; - int r; - - /* mmc_disabled set by start/stop func. */ - if (mmc_disabled) - return -EWOULDBLOCK; - - if (!devpath) - return -ENODEV; - - /* check partition */ - r = get_partition(devpath, path); - if (!r) - devpath = path; - - DD_LIST_FOREACH(fs_head, elem, fs) { - if (fs->match(devpath)) - break; - } - - if (!fs) - return -EINVAL; - - _I("devpath : %s", devpath); - r = fs->check(devpath); - if (r < 0) - _E("failt to check devpath : %s", devpath); - - r = fs->mount(smack, devpath, mount_point); - if (r < 0) - return r; - - r = rw_mount(mount_point); - if (r < 0) - return -EROFS; - - return 0; -} - -static void *mount_start(void *arg) -{ - struct mmc_data *data = (struct mmc_data*)arg; - char *devpath; - int r; - - devpath = data->devpath; - if (!devpath) { - r = -EINVAL; - goto error; - } - - /* clear previous filesystem */ - mmc_check_and_unmount(MMC_MOUNT_POINT); - - /* check mount point */ - if (access(MMC_MOUNT_POINT, R_OK) != 0) { - if (mkdir(MMC_MOUNT_POINT, 0755) < 0) { - r = -errno; - goto error; - } - } - - /* mount operation */ - r = mmc_mount(devpath, MMC_MOUNT_POINT); - if (r == -EROFS) - launch_syspopup("mountrdonly"); - /* Do not need to show error popup, if mmc is disabled */ - else if (r == -EWOULDBLOCK) - goto error_without_popup; - else if (r < 0) - goto error; - - mmc_set_config(MAX_RATIO); - - free(devpath); - free(data); - - /* give a transmutable attribute to mount_point */ - r = setxattr(MMC_MOUNT_POINT, "security.SMACK64TRANSMUTE", "TRUE", strlen("TRUE"), 0); - if (r < 0) - _E("setxattr error : %s", strerror(errno)); - - vconf_set_int(VCONFKEY_SYSMAN_MMC_STATUS, VCONFKEY_SYSMAN_MMC_MOUNTED); - vconf_set_int(VCONFKEY_SYSMAN_MMC_MOUNT, VCONFKEY_SYSMAN_MMC_MOUNT_COMPLETED); - return 0; - -error: - launch_syspopup("mounterr"); - -error_without_popup: - vconf_set_int(VCONFKEY_SYSMAN_MMC_MOUNT, VCONFKEY_SYSMAN_MMC_MOUNT_FAILED); - vconf_set_int(VCONFKEY_SYSMAN_MMC_STATUS, VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED); - - free(devpath); - free(data); - _E("failed to mount device : %s", strerror(-r)); - return (void *)r; -} - -static int mmc_unmount(int option, const char *mount_point) -{ - int r, retry = 0; - int kill_op; - - /* it must called before unmounting mmc */ - r = mmc_check_and_unmount(mount_point); - if (!r) - return r; - if (option == UNMOUNT_NORMAL) { - _I("Failed to unmount with normal option : %s", strerror(-r)); - return r; - } - - _I("Execute force unmount!"); - /* Force Unmount Scenario */ - while (1) { - switch (retry++) { - case 0: - /* At first, notify to other app who already access sdcard */ - _I("Notify to other app who already access sdcard"); - vconf_set_int(VCONFKEY_SYSMAN_MMC_STATUS, VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED); - break; - case 1: - /* Second, kill app with SIGTERM */ - _I("Kill app with SIGTERM"); - terminate_process(MMC_MOUNT_POINT, false); - break; - case 2: - /* Last time, kill app with SIGKILL */ - _I("Kill app with SIGKILL"); - terminate_process(MMC_MOUNT_POINT, true); - break; - default: - if (umount2(mount_point, MNT_DETACH) != 0) { - _I("Failed to unmount with lazy option : %s", strerror(errno)); - return -errno; - } - return 0; - } - - /* it takes some seconds til other app completely clean up */ - usleep(500*1000); - - r = mmc_check_and_unmount(mount_point); - if (!r) - break; - } - - return r; -} - -static void *unmount_start(void *arg) -{ - struct mmc_data *data = (struct mmc_data*)arg; - int option, r; - - option = data->option; - - assert(option == UNMOUNT_NORMAL || option == UNMOUNT_FORCE); - - r = mmc_unmount(option, MMC_MOUNT_POINT); - if (r < 0) - goto error; - - free(data); - vconf_set_int(VCONFKEY_SYSMAN_MMC_STATUS, VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED); - return 0; - -error: - free(data); - _E("Failed to unmount device : %s", strerror(-r)); - vconf_set_int(VCONFKEY_SYSMAN_MMC_STATUS, VCONFKEY_SYSMAN_MMC_MOUNTED); - return (void *)r; -} - -static int format(const char *devpath) -{ - const struct mmc_fs_ops *fs = NULL; - dd_list *elem; - char path[NAME_MAX] = {0,}; - int r, size, retry; - - if (!devpath) - return -ENODEV; - - /* check partition */ - r = get_partition(devpath, path); - if (!r) { - /* if there is partition, find partition file system */ - DD_LIST_FOREACH(fs_head, elem, fs) { - if (fs->match(path)) - break; - } - } else { - /* if there isn't partition, create partition */ - create_partition(devpath); - r = get_partition(devpath, path); - if (r < 0) - memcpy(path, devpath, strlen(devpath)); - } - - _I("format partition : %s", path); - - if (!fs) { - /* find root file system */ - DD_LIST_FOREACH(fs_head, elem, fs) { - if (fs->match(devpath)) - break; - } - } - - if (!fs) { - /* cannot find root and partition file system, - find suitable file system */ - size = get_mmc_size(path); - fs = find_fs(FS_TYPE_VFAT); - } - - if (!fs) - return -EINVAL; - - for (retry = FORMAT_RETRY; retry > 0; --retry) { - fs->check(devpath); - _I("format path : %s", path); - r = fs->format(path); - if (!r) - break; - } - return r; -} - -static void *format_start(void *arg) -{ - struct mmc_data *data = (struct mmc_data*)arg; - char *devpath; - int option, r, key = VCONFKEY_SYSMAN_MMC_MOUNTED; - bool format_ret = true; - - option = data->option; - devpath = data->devpath; - - assert(devpath); - assert(option == UNMOUNT_NORMAL || option == UNMOUNT_FORCE); - - _I("Format Start (option:%d)", option); - r = mmc_unmount(option, MMC_MOUNT_POINT); - if (r < 0) - goto release_memory; - - vconf_set_int(VCONFKEY_SYSMAN_MMC_FORMAT_PROGRESS, VCONFKEY_SYSMAN_MMC_FORMAT_PROGRESS_NOW); - r = format(devpath); - vconf_set_int(VCONFKEY_SYSMAN_MMC_FORMAT_PROGRESS, VCONFKEY_SYSMAN_MMC_FORMAT_PROGRESS_NONE); - if (r != 0) - format_ret = false; - - mount_start(arg); - if (!format_ret) - goto error; - _I("Format Successful"); - vconf_set_int(VCONFKEY_SYSMAN_MMC_FORMAT, VCONFKEY_SYSMAN_MMC_FORMAT_COMPLETED); - return 0; - -release_memory: - free(devpath); - free(data); -error: - _E("Format Failed : %s", strerror(-r)); - vconf_set_int(VCONFKEY_SYSMAN_MMC_FORMAT, VCONFKEY_SYSMAN_MMC_FORMAT_FAILED); - return (void*)r; -} - -static int mmc_make_thread(int type, int option, const char *devpath) -{ - pthread_t th; - struct mmc_data *pdata; - int r; - - if (type < 0 || type >= MMC_END) - return -EINVAL; - - pdata = malloc(sizeof(struct mmc_data)); - if (!pdata) { - _E("malloc failed"); - return -errno; - } - - if (option >= 0) - pdata->option = option; - if (devpath) - pdata->devpath = strdup(devpath); - r = pthread_create(&th, NULL, mmc_func[type].func, pdata); - if (r != 0) { - _E("pthread create failed"); - free(pdata->devpath); - free(pdata); - return -EPERM; - } - - pthread_detach(th); - return 0; -} - -static int mmc_inserted(const char *devpath) -{ - int r; - _I("MMC inserted : %s", devpath); - mmc_curpath = strdup(devpath); - r = mmc_make_thread(MMC_MOUNT, -1, devpath); - if (r < 0) - return r; - return 0; -} - -static int mmc_removed(void) -{ - _I("MMC removed"); - /* unmount */ - mmc_check_and_unmount((const char *)MMC_MOUNT_POINT); - vconf_set_int(VCONFKEY_SYSMAN_MMC_STATUS, VCONFKEY_SYSMAN_MMC_REMOVED); - free(mmc_curpath); - mmc_curpath = NULL; - return 0; -} - -static int mmc_booting_done(void* data) -{ - char devpath[NAME_MAX] = {0,}; - int r; - - /* check mmc exists */ - r = find_mmc_node(devpath); - if (r < 0) - return 0; - - /* if MMC exists */ - return mmc_inserted(devpath); -} - -static void uevent_block_handler(struct udev_device *dev) -{ - const char *devpath; - const char *action; - const char *devnode; - - devpath = udev_device_get_devpath(dev); - if (fnmatch(MMC_PATH, devpath, 0)) - return; - - action = udev_device_get_action(dev); - devnode = udev_device_get_devnode(dev); - if (!action || !devnode) - return; - - _D("mmc action : %s", action); - if (!strncmp(action, UDEV_ADD, sizeof(UDEV_ADD))) - mmc_inserted(devnode); - else if (!strncmp(action, UDEV_REMOVE, sizeof(UDEV_REMOVE))) - mmc_removed(); -} - -static DBusMessage *edbus_request_mount(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - struct mmc_data *pdata; - int ret; - - if (!mmc_curpath) { - ret = -ENODEV; - goto error; - } - - pdata = malloc(sizeof(struct mmc_data)); - if (!pdata) { - _E("malloc failed"); - ret = -errno; - goto error; - } - - pdata->devpath = strdup(mmc_curpath); - if (!pdata->devpath) { - free(pdata); - ret = -errno; - goto error; - } - - ret = (int)mount_start(pdata); - -error: - 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 *edbus_request_unmount(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - int opt, ret; - char params[NAME_MAX]; - struct mmc_data *pdata; - - ret = dbus_message_get_args(msg, NULL, - DBUS_TYPE_INT32, &opt, DBUS_TYPE_INVALID); - if (!ret) { - _I("there is no message"); - ret = -EBADMSG; - goto error; - } - - pdata = malloc(sizeof(struct mmc_data)); - if (!pdata) { - _E("malloc failed"); - ret = -errno; - goto error; - } - - pdata->option = opt; - ret = (int)unmount_start(pdata); - -error: - 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 *edbus_request_format(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - int opt, ret; - struct mmc_data *pdata; - - ret = dbus_message_get_args(msg, NULL, - DBUS_TYPE_INT32, &opt, DBUS_TYPE_INVALID); - if (!ret) { - _I("there is no message"); - ret = -EBADMSG; - goto error; - } - - if (!mmc_curpath) { - ret = -ENODEV; - goto error; - } - - pdata = malloc(sizeof(struct mmc_data)); - if (!pdata) { - _E("malloc failed"); - ret = -errno; - goto error; - } - - pdata->option = opt; - pdata->devpath = strdup(mmc_curpath); - if (!pdata->devpath) { - free(pdata); - ret = -errno; - goto error; - } - - ret = (int)format_start(pdata); - -error: - 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 *edbus_request_insert(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - char *devpath; - int ret; - - ret = dbus_message_get_args(msg, NULL, - DBUS_TYPE_STRING, &devpath, DBUS_TYPE_INVALID); - if (!ret) { - _I("there is no message"); - ret = -EBADMSG; - goto error; - } - - ret = mmc_inserted(devpath); - -error: - 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 *edbus_request_remove(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - int ret; - - ret = mmc_removed(); - - 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 *edbus_change_status(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - int opt, ret; - char params[NAME_MAX]; - struct mmc_data *pdata; - - ret = dbus_message_get_args(msg, NULL, - DBUS_TYPE_INT32, &opt, DBUS_TYPE_INVALID); - if (!ret) { - _I("there is no message"); - ret = -EBADMSG; - goto error; - } - if (opt == VCONFKEY_SYSMAN_MMC_MOUNTED) - mmc_mount_done(); -error: - 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; -} - -int get_mmc_devpath(char devpath[]) -{ - if (mmc_disabled) - return -EWOULDBLOCK; - if (!mmc_curpath) - return -ENODEV; - snprintf(devpath, NAME_MAX, "%s", mmc_curpath); - return 0; -} - -static struct uevent_handler uh = { - .subsystem = BLOCK_SUBSYSTEM, - .uevent_func = uevent_block_handler, -}; - -static const struct edbus_method edbus_methods[] = { - { "RequestMount", NULL, "i", edbus_request_mount }, - { "RequestUnmount", "i", "i", edbus_request_unmount }, - { "RequestFormat", "i", "i", edbus_request_format }, - { "RequestInsert", "s", "i", edbus_request_insert }, - { "RequestRemove", NULL, "i", edbus_request_remove }, - { "ChangeStatus", "i", "i", edbus_change_status }, -}; - -static void mmc_init(void *data) -{ - int ret; - - mmc_load_config(); - ret = register_edbus_interface_and_method(DEVICED_PATH_MMC, - DEVICED_INTERFACE_MMC, - edbus_methods, ARRAY_SIZE(edbus_methods)); - if (ret < 0) - _E("fail to init edbus interface and method(%d)", ret); - - /* register mmc uevent control routine */ - ret = register_kernel_uevent_control(&uh); - if (ret < 0) - _E("fail to register extcon uevent : %d", ret); - - /* register notifier if mmc exist or not */ - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, mmc_booting_done); -} - -static void mmc_exit(void *data) -{ - int ret; - - /* unregister notifier */ - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, mmc_booting_done); - - /* unregister mmc uevent control routine */ - ret = unregister_kernel_uevent_control(&uh); - if (ret < 0) - _E("fail to unregister extcon uevent : %d", ret); -} - -static int mmc_start(enum device_flags flags) -{ - mmc_disabled = false; - _I("start"); - return 0; -} - -static int mmc_stop(enum device_flags flags) -{ - mmc_disabled = true; - vconf_set_int(VCONFKEY_SYSMAN_MMC_STATUS, VCONFKEY_SYSMAN_MMC_REMOVED); - _I("stop"); - return 0; -} - -const struct device_ops mmc_device_ops = { - .name = "mmc", - .init = mmc_init, - .exit = mmc_exit, - .start = mmc_start, - .stop = mmc_stop, -}; - -DEVICE_OPS_REGISTER(&mmc_device_ops) diff --git a/src/mmc/mmc.conf b/src/mmc/mmc.conf deleted file mode 100644 index 55539b9..0000000 --- a/src/mmc/mmc.conf +++ /dev/null @@ -1,3 +0,0 @@ -[MMC] -#mmc bdi max ratio -MaxRatio=10 diff --git a/src/shared/dbus.h b/src/shared/dbus.h index 6d9c762..dd0f536 100644 --- a/src/shared/dbus.h +++ b/src/shared/dbus.h @@ -73,6 +73,9 @@ /* Led service: play/stop led operations about led */ #define DEVICED_PATH_LED DEVICED_OBJECT_PATH"/Led" #define DEVICED_INTERFACE_LED DEVICED_INTERFACE_NAME".Led" +/* Block service: manage block device */ +#define DEVICED_PATH_BLOCK DEVICED_OBJECT_PATH"/Block" +#define DEVICED_INTERFACE_BLOCK DEVICED_INTERFACE_NAME".Block" /* MMC service: mount/unmount/format mmc operations about mmc */ #define DEVICED_PATH_MMC DEVICED_OBJECT_PATH"/Mmc" #define DEVICED_INTERFACE_MMC DEVICED_INTERFACE_NAME".Mmc" -- 2.7.4 From 17a3982add26254ffc8bd1a4431e9ee0c2435228 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Wed, 15 Apr 2015 16:59:11 +0900 Subject: [PATCH 14/16] deviced: Update the dbus watch logic. Deviced will invoke the registered function to the sender whenever the name owner of sender is changed. Change-Id: Iffd7474cc53531cb8433aaf9c0ea9035d1c5cd3e Signed-off-by: Jiyoung Yun --- src/core/edbus-handler.c | 350 ++++++++++++++++++++++++++++-------------- src/core/edbus-handler.h | 19 +-- src/display/auto-brightness.c | 14 +- src/display/core.c | 16 +- src/display/core.h | 4 +- src/display/display-dbus.c | 8 +- 6 files changed, 262 insertions(+), 149 deletions(-) diff --git a/src/core/edbus-handler.c b/src/core/edbus-handler.c index c4c2e5e..c9f3630 100644 --- a/src/core/edbus-handler.c +++ b/src/core/edbus-handler.c @@ -60,6 +60,18 @@ static struct edbus_object { /* Add new object & interface here*/ }; +struct watch_func_info { + bool deleted; + void (*func)(const char *sender, void *data); + void *data; +}; + +struct watch_info { + bool deleted; + char *sender; + dd_list *func_list; +}; + static dd_list *edbus_object_list; static dd_list *edbus_owner_list; static dd_list *edbus_handler_list; @@ -258,14 +270,56 @@ int broadcast_edbus_signal(const char *path, const char *interface, return 0; } +static void print_watch_item(void) +{ + struct watch_info *watch; + struct watch_func_info *finfo; + dd_list *n; + dd_list *e; + + DD_LIST_FOREACH(edbus_watch_list, n, watch) { + _D("watch sender : %s, deleted : %d", + watch->sender, watch->deleted); + DD_LIST_FOREACH(watch->func_list, e, finfo) + _D("\tfunc : %x, deleted : %d", + finfo->func, finfo->deleted); + } +} + +static void watch_idler_cb(void *data) +{ + struct watch_info *watch; + struct watch_func_info *finfo; + dd_list *n; + dd_list *next; + dd_list *elem; + dd_list *enext; + + DD_LIST_FOREACH_SAFE(edbus_watch_list, n, next, watch) { + if (!watch->deleted) + continue; + + /* remove watch func list */ + DD_LIST_FOREACH_SAFE(watch->func_list, elem, enext, finfo) + free(finfo); + DD_LIST_FREE_LIST(watch->func_list); + DD_LIST_REMOVE_LIST(edbus_watch_list, n); + free(watch->sender); + free(watch); + } +} + +static int remove_watch_item(struct watch_info *watch); static DBusHandlerResult message_filter(DBusConnection *connection, DBusMessage *message, void *data) { - char match[256]; int ret; - const char *iface, *member, *arg = NULL; - struct watch *watch; - dd_list *n, *next; + const char *iface, *member; + const char *sender; + struct watch_info *watch; + struct watch_func_info *finfo; + dd_list *n; + int len; if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; @@ -273,103 +327,117 @@ static DBusHandlerResult message_filter(DBusConnection *connection, iface = dbus_message_get_interface(message); member = dbus_message_get_member(message); - if (strcmp(iface, DBUS_INTERFACE_DBUS)) + if (strncmp(iface, DBUS_INTERFACE_DBUS, + sizeof(DBUS_INTERFACE_DBUS))) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - if (strcmp(member, NAME_OWNER_CHANGED)) + if (strncmp(member, NAME_OWNER_CHANGED, + sizeof(NAME_OWNER_CHANGED))) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - ret = dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg, - DBUS_TYPE_INVALID); + ret = dbus_message_get_args(message, NULL, + DBUS_TYPE_STRING, &sender, + DBUS_TYPE_INVALID); if (!ret) { _E("no message"); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } - _D("Argument : %s", arg); - - DD_LIST_FOREACH_SAFE(edbus_watch_list, n, next, watch) { - if (strcmp(arg, watch->name)) continue; - - if (watch->func) - watch->func(watch->name, watch->id); - - DD_LIST_REMOVE(edbus_watch_list, watch); - free(watch->name); - free(watch); + len = strlen(sender) + 1; + DD_LIST_FOREACH(edbus_watch_list, n, watch) { + if (!watch->deleted && + !strncmp(watch->sender, sender, len)) + break; } - /* remove registered sender */ - snprintf(match, sizeof(match), NAME_OWNER_MATCH, arg); - dbus_bus_remove_match(conn, match, NULL); - + if (!watch) + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - if (DD_LIST_LENGTH(edbus_watch_list) == 0) { - dbus_connection_remove_filter(conn, message_filter, NULL); - _I("remove message filter, no watcher!"); + DD_LIST_FOREACH(watch->func_list, n, finfo) { + if (!finfo->deleted && + finfo->func) + finfo->func(watch->sender, finfo->data); } + /* no interest in this item anymore */ + remove_watch_item(watch); + + print_watch_item(); + add_idle_request(watch_idler_cb, NULL); return DBUS_HANDLER_RESULT_HANDLED; } -int register_edbus_watch(DBusMessage *msg, enum watch_id id, int (*func)(char *name, enum watch_id id)) +static struct watch_info *get_matched_watch_item(const char *sender) { - char match[256]; - const char *sender; - struct watch *watch; + int len; dd_list *n; - int ret; - bool matched = false; + struct watch_info *watch; - if (!msg) { - _E("invalid argument!"); - return -EINVAL; - } + if (!sender) + return NULL; - sender = dbus_message_get_sender(msg); - if (!sender) { - _E("invalid sender!"); - return -EINVAL; + len = strlen(sender) + 1; + /* check the sender&type is already registered */ + DD_LIST_FOREACH(edbus_watch_list, n, watch) { + if (!watch->deleted && + !strncmp(watch->sender, sender, len)) + return watch; } - /* check the sender&id is already registered */ - DD_LIST_FOREACH(edbus_watch_list, n, watch) { - if (strcmp(sender, watch->name)) - continue; - if (id != watch->id) { - matched = true; - continue; - } + return NULL; +} - _I("%s(%d) is already watched!", watch->name, watch->id); +static bool get_valid_watch_item(void) +{ + struct watch_info *watch; + dd_list *elem; - return 0; + DD_LIST_FOREACH(edbus_watch_list, elem, watch) { + if (!watch->deleted) + return true; } - watch = malloc(sizeof(struct watch)); - if (!watch) { - _E("Fail to malloc for watch!"); - return -ENOMEM; - } + return false; +} + +static struct watch_info *add_watch_item(const char *sender) +{ + DBusError err; + struct watch_info *watch; + char match[256]; + int ret; - watch->id = id; - watch->func = func; - watch->name = strndup(sender, strlen(sender)); + if (!sender) + return NULL; - if (!watch->name) { - _E("Fail to malloc for watch name"); - free(watch); - return -ENOMEM; + watch = calloc(1, sizeof(struct watch_info)); + if (!watch) + return NULL; + + watch->sender = strdup(sender); + if (!watch->sender) + goto out; + + dbus_error_init(&err); + /* add name owner changed match string */ + snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch->sender); + dbus_bus_add_match(conn, match, &err); + + if (dbus_error_is_set(&err)) { + _E("fail to add match for %s [%s:%s]", + sender, err.name, err.message); + dbus_error_free(&err); + goto out; } - /* Add message filter */ - if (DD_LIST_LENGTH(edbus_watch_list) == 0) { - ret = dbus_connection_add_filter(conn, message_filter, NULL, NULL); + /* if the first request, add message filter */ + if (!get_valid_watch_item()) { + ret = dbus_connection_add_filter(conn, + message_filter, NULL, NULL); if (!ret) { _E("fail to add message filter!"); - free(watch->name); - free(watch); - return -ENOMEM; + dbus_bus_remove_match(conn, match, NULL); + goto out; } _I("success to add message filter!"); } @@ -377,58 +445,124 @@ int register_edbus_watch(DBusMessage *msg, enum watch_id id, int (*func)(char *n /* Add watch to watch list */ DD_LIST_APPEND(edbus_watch_list, watch); - if (!matched) { - snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch->name); - dbus_bus_add_match(conn, match, NULL); - } + return watch; - _I("%s(%d) is watched by dbus!", watch->name, watch->id); +out: + if (watch) { + free(watch->sender); + free(watch); + } - return 0; + return NULL; } -int unregister_edbus_watch(DBusMessage *msg, enum watch_id id) +static int remove_watch_item(struct watch_info *watch) { char match[256]; - const char *sender; - struct watch *watch; - dd_list *n, *next; - bool matched = false; - if (!msg) { - _E("invalid argument!"); + if (!watch) return -EINVAL; - } - sender = dbus_message_get_sender(msg); - if (!sender) { - _E("invalid sender!"); + snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch->sender); + dbus_bus_remove_match(conn, match, NULL); + + watch->deleted = true; + + /* if the last request, remove message filter */ + if (!get_valid_watch_item()) + dbus_connection_remove_filter(conn, message_filter, NULL); + + return 0; +} + +int register_edbus_watch(const char *sender, + void (*func)(const char *sender, void *data), void *data) +{ + struct watch_info *watch; + struct watch_func_info *finfo; + dd_list *elem; + bool isnew = false; + int ret; + + if (!sender || !func) { + _E("invalid argument : sender(NULL) || func(NULL)"); return -EINVAL; } - DD_LIST_FOREACH_SAFE(edbus_watch_list, n, next, watch) { - if (strcmp(sender, watch->name)) - continue; + watch = get_matched_watch_item(sender); + if (!watch) { + /* create new watch item */ + watch = add_watch_item(sender); + if (!watch) { + _E("fail to add watch item"); + return -EPERM; + } + isnew = true; + } - if (id != watch->id) { - matched = true; - continue; + /* find the same callback */ + DD_LIST_FOREACH(watch->func_list, elem, finfo) { + if (finfo->func == func) { + _E("there is already the same callback"); + goto out; } - DD_LIST_REMOVE(edbus_watch_list, watch); - free(watch->name); - free(watch); } - /* remove match */ - if (!matched) { - snprintf(match, sizeof(match), NAME_OWNER_MATCH, sender); - dbus_bus_remove_match(conn, match, NULL); + finfo = calloc(1, sizeof(struct watch_func_info)); + if (!finfo) { + _E("fail to allocate watch func info"); + goto out; + } + + finfo->func = func; + finfo->data = data; + + /* add callback function to the watch list */ + DD_LIST_APPEND(watch->func_list, finfo); + + print_watch_item(); + _I("%s is watched by dbus!", sender); + return 0; +out: + if (isnew) + remove_watch_item(watch); + + return -EPERM; +} - if (DD_LIST_LENGTH(edbus_watch_list) == 0) - dbus_connection_remove_filter(conn, message_filter, - NULL); +int unregister_edbus_watch(const char *sender, + void (*func)(const char *sender, void *data)) +{ + struct watch_info *watch; + struct watch_func_info *finfo; + dd_list *elem; + bool matched = false; + + if (!sender || !func) { + _E("invalid argument : sender(NULL) || func(NULL)"); + return -EINVAL; + } + + watch = get_matched_watch_item(sender); + if (!watch) { + _E("fail to get matched watch item"); + return -ENODEV; } + /* check the no interest function */ + DD_LIST_FOREACH(watch->func_list, elem, finfo) { + if (finfo->func == func) + finfo->deleted = true; + if (!finfo->deleted) + matched = true; + } + + /* if it is the last item */ + if (!matched) + remove_watch_item(watch); + + print_watch_item(); + _I("%s is not watched by dbus!", sender); return 0; } @@ -436,18 +570,12 @@ static void unregister_edbus_watch_all(void) { char match[256]; dd_list *n, *next; - struct watch *watch; + struct watch_info *watch; - if (DD_LIST_LENGTH(edbus_watch_list) > 0) - dbus_connection_remove_filter(conn, message_filter, NULL); + DD_LIST_FOREACH_SAFE(edbus_watch_list, n, next, watch) + remove_watch_item(watch); - DD_LIST_FOREACH_SAFE(edbus_watch_list, n, next, watch) { - snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch->name); - dbus_bus_remove_match(conn, match, NULL); - DD_LIST_REMOVE(edbus_watch_list, watch); - free(watch->name); - free(watch); - } + add_idle_request(watch_idler_cb, NULL); } static int register_method(E_DBus_Interface *iface, diff --git a/src/core/edbus-handler.h b/src/core/edbus-handler.h index 6aee7d5..df0950c 100644 --- a/src/core/edbus-handler.h +++ b/src/core/edbus-handler.h @@ -30,19 +30,6 @@ struct edbus_method { E_DBus_Method_Cb func; }; -enum watch_id { - WATCH_DISPLAY_AUTOBRIGHTNESS_MIN, - WATCH_DISPLAY_LCD_TIMEOUT, - WATCH_DISPLAY_LOCK_STATE, - WATCH_DISPLAY_HOLD_BRIGHTNESS, -}; - -struct watch { - enum watch_id id; - char *name; - int (*func)(char *name, enum watch_id id); -}; - static inline DBusMessage *make_reply_message(DBusMessage *msg, int ret) { DBusMessageIter iter; @@ -63,8 +50,10 @@ E_DBus_Interface *get_edbus_interface(const char *path); pid_t get_edbus_sender_pid(DBusMessage *msg); int broadcast_edbus_signal(const char *path, const char *interface, const char *name, const char *sig, char *param[]); -int register_edbus_watch(DBusMessage *msg, enum watch_id id, int (*func)(char *name, enum watch_id id)); -int unregister_edbus_watch(DBusMessage *msg, enum watch_id id); +int register_edbus_watch(const char *sender, + void (*func)(const char *sender, void *data), void *data); +int unregister_edbus_watch(const char *sender, + void (*func)(const char *sender, void *data)); void edbus_init(void *data); void edbus_exit(void *data); diff --git a/src/display/auto-brightness.c b/src/display/auto-brightness.c index 6611d06..69a9569 100644 --- a/src/display/auto-brightness.c +++ b/src/display/auto-brightness.c @@ -632,16 +632,16 @@ static int set_autobrightness_min(int val, char *name) return 0; } -static int reset_autobrightness_min(char *name, enum watch_id id) +static void reset_autobrightness_min(const char *sender, void *data) { - if (!name) - return -EINVAL; + if (!sender) + return; if (!min_brightness_name) - return -EINVAL; + return; - if (strcmp(name, min_brightness_name)) - return -EINVAL; + if (strcmp(sender, min_brightness_name)) + return; _I("change to default %d -> %d, %s", min_brightness, PM_MIN_BRIGHTNESS, min_brightness_name); @@ -652,8 +652,6 @@ static int reset_autobrightness_min(char *name, enum watch_id id) } update_brightness_direct(); - - return 0; } static int lcd_changed_cb(void *data) diff --git a/src/display/core.c b/src/display/core.c index 1618e01..6212f32 100644 --- a/src/display/core.c +++ b/src/display/core.c @@ -2080,18 +2080,18 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, char *name) return 0; } -int reset_lcd_timeout(char *name, enum watch_id id) +void reset_lcd_timeout(const char *sender, void *data) { - if (!name) - return -EINVAL; + if (!sender) + return; if (!custom_change_name) - return -EINVAL; + return; - if (strcmp(name, custom_change_name)) - return -EINVAL; + if (strcmp(sender, custom_change_name)) + return; - _I("reset lcd timeout %s: set default timeout", name); + _I("reset lcd timeout %s: set default timeout", sender); free(custom_change_name); custom_change_name = 0; @@ -2102,8 +2102,6 @@ int reset_lcd_timeout(char *name, enum watch_id id) if (pm_cur_state == S_NORMAL) { states[pm_cur_state].trans(EVENT_INPUT); } - - return 0; } static int hall_ic_open(void *data) diff --git a/src/display/core.h b/src/display/core.h index 2629d6e..2fe42f4 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -136,7 +136,7 @@ extern struct display_config display_conf; struct display_function_info { void (*update_auto_brightness)(bool); int (*set_autobrightness_min)(int, char *); - int (*reset_autobrightness_min)(char *, enum watch_id); + void (*reset_autobrightness_min)(const char *, void *data); int (*face_detection)(int, int, int); }; @@ -159,7 +159,7 @@ int trans_condition; pid_t idle_pid; int check_processes(enum state_t prohibit_state); extern struct state state[S_END]; -int reset_lcd_timeout(char *name, enum watch_id id); +void reset_lcd_timeout(const char *sender, void *data); int check_lcdoff_lock_state(void); /** * @} diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 7f6c442..180acb5 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -671,8 +671,8 @@ static DBusMessage *edbus_setautobrightnessmin(E_DBus_Object *obj, DBusMessage * goto error; } if (display_info.reset_autobrightness_min) { - register_edbus_watch(msg, WATCH_DISPLAY_AUTOBRIGHTNESS_MIN, - display_info.reset_autobrightness_min); + register_edbus_watch(sender, + display_info.reset_autobrightness_min, NULL); _I("set autobrightness min %d by %d", val, pid); } error: @@ -707,8 +707,8 @@ static DBusMessage *edbus_setlcdtimeout(E_DBus_Object *obj, DBusMessage *msg) if (ret) { _W("fail to set lcd timeout %d by %d", ret, pid); } else { - register_edbus_watch(msg, WATCH_DISPLAY_LCD_TIMEOUT, - reset_lcd_timeout); + register_edbus_watch(sender, + reset_lcd_timeout, NULL); _I("set lcd timeout on %d, dim %d, holdblock %d by %d", on, dim, holdkey_block, pid); } -- 2.7.4 From b1ad68f3e3f726353e127520d170fa5a9ac4fbfc Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Fri, 17 Apr 2015 17:23:53 +0900 Subject: [PATCH 15/16] haptic: Add exception handling of unexpectedly killed process. When some process is killed unexpectedly, it should control to stop, close and collect the related resources. Change-Id: I4dd9a226304b7d755ac6d0d5a9ad1ba9bb79ed40 Signed-off-by: Jiyoung Yun --- src/core/edbus-handler.c | 80 ++++++++++++------------- src/haptic/haptic.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 185 insertions(+), 46 deletions(-) diff --git a/src/core/edbus-handler.c b/src/core/edbus-handler.c index c9f3630..13a41ba 100644 --- a/src/core/edbus-handler.c +++ b/src/core/edbus-handler.c @@ -81,6 +81,9 @@ static DBusConnection *conn; static E_DBus_Connection *edbus_conn; static DBusPendingCall *edbus_request_name; +static DBusHandlerResult message_filter(DBusConnection *connection, + DBusMessage *message, void *data); + static int register_edbus_interface(struct edbus_object *object) { if (!object) { @@ -281,11 +284,24 @@ static void print_watch_item(void) _D("watch sender : %s, deleted : %d", watch->sender, watch->deleted); DD_LIST_FOREACH(watch->func_list, e, finfo) - _D("\tfunc : %x, deleted : %d", + _D("\tfunc : %p, deleted : %d", finfo->func, finfo->deleted); } } +static bool get_valid_watch_item(void) +{ + struct watch_info *watch; + dd_list *elem; + + DD_LIST_FOREACH(edbus_watch_list, elem, watch) { + if (!watch->deleted) + return true; + } + + return false; +} + static void watch_idler_cb(void *data) { struct watch_info *watch; @@ -294,22 +310,34 @@ static void watch_idler_cb(void *data) dd_list *next; dd_list *elem; dd_list *enext; + char match[256]; DD_LIST_FOREACH_SAFE(edbus_watch_list, n, next, watch) { if (!watch->deleted) continue; + /* remove dbus match */ + snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch->sender); + dbus_bus_remove_match(conn, match, NULL); + + _I("%s is not watched by dbus!", watch->sender); + /* remove watch func list */ DD_LIST_FOREACH_SAFE(watch->func_list, elem, enext, finfo) free(finfo); + + /* remove watch item */ DD_LIST_FREE_LIST(watch->func_list); DD_LIST_REMOVE_LIST(edbus_watch_list, n); free(watch->sender); free(watch); } + + /* if the last request, remove message filter */ + if (!get_valid_watch_item()) + dbus_connection_remove_filter(conn, message_filter, NULL); } -static int remove_watch_item(struct watch_info *watch); static DBusHandlerResult message_filter(DBusConnection *connection, DBusMessage *message, void *data) { @@ -360,7 +388,7 @@ static DBusHandlerResult message_filter(DBusConnection *connection, } /* no interest in this item anymore */ - remove_watch_item(watch); + watch->deleted = true; print_watch_item(); add_idle_request(watch_idler_cb, NULL); @@ -387,19 +415,6 @@ static struct watch_info *get_matched_watch_item(const char *sender) return NULL; } -static bool get_valid_watch_item(void) -{ - struct watch_info *watch; - dd_list *elem; - - DD_LIST_FOREACH(edbus_watch_list, elem, watch) { - if (!watch->deleted) - return true; - } - - return false; -} - static struct watch_info *add_watch_item(const char *sender) { DBusError err; @@ -444,7 +459,7 @@ static struct watch_info *add_watch_item(const char *sender) /* Add watch to watch list */ DD_LIST_APPEND(edbus_watch_list, watch); - + _I("%s is watched by dbus!", sender); return watch; out: @@ -456,25 +471,6 @@ out: return NULL; } -static int remove_watch_item(struct watch_info *watch) -{ - char match[256]; - - if (!watch) - return -EINVAL; - - snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch->sender); - dbus_bus_remove_match(conn, match, NULL); - - watch->deleted = true; - - /* if the last request, remove message filter */ - if (!get_valid_watch_item()) - dbus_connection_remove_filter(conn, message_filter, NULL); - - return 0; -} - int register_edbus_watch(const char *sender, void (*func)(const char *sender, void *data), void *data) { @@ -520,12 +516,11 @@ int register_edbus_watch(const char *sender, /* add callback function to the watch list */ DD_LIST_APPEND(watch->func_list, finfo); - print_watch_item(); - _I("%s is watched by dbus!", sender); + _I("register watch func(%p) of %s", func, sender); return 0; out: if (isnew) - remove_watch_item(watch); + watch->deleted = true; return -EPERM; } @@ -559,10 +554,9 @@ int unregister_edbus_watch(const char *sender, /* if it is the last item */ if (!matched) - remove_watch_item(watch); + watch->deleted = true; - print_watch_item(); - _I("%s is not watched by dbus!", sender); + _I("unregister watch func(%p) of %s", func, sender); return 0; } @@ -573,7 +567,7 @@ static void unregister_edbus_watch_all(void) struct watch_info *watch; DD_LIST_FOREACH_SAFE(edbus_watch_list, n, next, watch) - remove_watch_item(watch); + watch->deleted = true; add_idle_request(watch_idler_cb, NULL); } diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c index 61ccc91..b55bdbb 100644 --- a/src/haptic/haptic.c +++ b/src/haptic/haptic.c @@ -44,6 +44,7 @@ #define HARDKEY_VIB_PRIORITY 2 #define HARDKEY_VIB_DURATION 300 #define HAPTIC_FEEDBACK_STEP 20 +#define DEFAULT_FEEDBACK_LEVEL 3 /* power on, power off vibration variable */ #define POWER_ON_VIB_DURATION 300 @@ -59,11 +60,17 @@ #define CHECK_VALID_OPS(ops, r) ((ops) ? true : !(r = -ENODEV)) +struct haptic_info { + char *sender; + dd_list *handle_list; +}; + /* for playing */ static int g_handle; /* haptic operation variable */ static dd_list *h_head; +static dd_list *haptic_handle_list; static const struct haptic_plugin_ops *h_ops; static enum haptic_type h_type; static bool haptic_disabled; @@ -78,6 +85,7 @@ static struct haptic_config haptic_conf; static int haptic_start(void); static int haptic_stop(void); static int haptic_internal_init(void); +static int remove_haptic_info(struct haptic_info *info); void add_haptic(const struct haptic_ops *ops) { @@ -134,7 +142,8 @@ static int convert_magnitude_by_conf(int level) } } - return -EINVAL; + _D("play default level"); + return DEFAULT_FEEDBACK_LEVEL * HAPTIC_FEEDBACK_STEP; } static DBusMessage *edbus_get_count(E_DBus_Object *obj, DBusMessage *msg) @@ -157,11 +166,85 @@ exit: return reply; } +static void haptic_name_owner_changed(const char *sender, void *data) +{ + dd_list *n; + struct haptic_info *info = data; + int handle; + + _I("%s (sender:%s)", __func__, sender); + + if (!info) + return; + + for (n = info->handle_list; n; n = n->next) { + handle = n->data; + h_ops->stop_device(handle); + h_ops->close_device(handle); + } + + remove_haptic_info(info); +} + +static struct haptic_info *add_haptic_info(const char *sender) +{ + struct haptic_info *info; + + assert(sender); + + info = calloc(1, sizeof(struct haptic_info)); + if (!info) + return NULL; + + info->sender = strdup(sender); + DD_LIST_APPEND(haptic_handle_list, info); + + register_edbus_watch(sender, haptic_name_owner_changed, info); + + return info; +} + +static int remove_haptic_info(struct haptic_info *info) +{ + dd_list *n; + dd_list *next; + + assert(info); + + unregister_edbus_watch(info->sender, haptic_name_owner_changed); + + DD_LIST_REMOVE(haptic_handle_list, info); + DD_LIST_FREE_LIST(info->handle_list); + free(info->sender); + free(info); + + return 0; +} + +static struct haptic_info *get_matched_haptic_info(const char *sender) +{ + dd_list *n; + struct haptic_info *info; + int len; + + assert(sender); + + len = strlen(sender) + 1; + DD_LIST_FOREACH(haptic_handle_list, n, info) { + if (!strncmp(info->sender, sender, len)) + return info; + } + + return NULL; +} + static DBusMessage *edbus_open_device(E_DBus_Object *obj, DBusMessage *msg) { DBusMessageIter iter; DBusMessage *reply; int index, handle, ret; + struct haptic_info *info; + const char *sender; /* Load haptic module before booting done */ if (!CHECK_VALID_OPS(h_ops, ret)) { @@ -176,8 +259,30 @@ static DBusMessage *edbus_open_device(E_DBus_Object *obj, DBusMessage *msg) } ret = h_ops->open_device(index, &handle); - if (ret >= 0) - ret = handle; + if (ret < 0) + goto exit; + + sender = dbus_message_get_sender(msg); + if (!sender) { + ret = -EPERM; + h_ops->close_device(handle); + goto exit; + } + + info = get_matched_haptic_info(sender); + if (!info) { + info = add_haptic_info(sender); + if (!info) { + _E("fail to create haptic information"); + ret = -EPERM; + h_ops->close_device(handle); + goto exit; + } + } + + DD_LIST_APPEND(info->handle_list, handle); + + ret = handle; exit: reply = dbus_message_new_method_return(msg); @@ -192,6 +297,9 @@ static DBusMessage *edbus_close_device(E_DBus_Object *obj, DBusMessage *msg) DBusMessage *reply; unsigned int handle; int ret; + struct haptic_info *info; + const char *sender; + int cnt; if (!CHECK_VALID_OPS(h_ops, ret)) goto exit; @@ -201,7 +309,27 @@ static DBusMessage *edbus_close_device(E_DBus_Object *obj, DBusMessage *msg) goto exit; } + sender = dbus_message_get_sender(msg); + if (!sender) { + _E("fail to get sender from dbus message"); + ret = -EPERM; + goto exit; + } + ret = h_ops->close_device(handle); + if (ret < 0) + goto exit; + + info = get_matched_haptic_info(sender); + if (!info) { + _E("fail to find the matched haptic info."); + goto exit; + } + + DD_LIST_REMOVE(info->handle_list, handle); + cnt = DD_LIST_LENGTH(info->handle_list); + if (cnt == 0) + remove_haptic_info(info); exit: reply = dbus_message_new_method_return(msg); @@ -440,6 +568,22 @@ exit: return reply; } +static DBusMessage *edbus_show_handle_list(E_DBus_Object *obj, DBusMessage *msg) +{ + dd_list *n; + dd_list *elem; + struct haptic_info *info; + int cnt = 0; + + _D(" sender\thandle"); + DD_LIST_FOREACH(haptic_handle_list, n, info) { + for (elem = info->handle_list; elem; elem = elem->next) + _D("[%2d]%s\t%d", cnt++, info->sender, (int)elem->data); + } + + return dbus_message_new_method_return(msg); +} + static unsigned char* convert_file_to_buffer(const char *file_name, int *size) { FILE *pf; @@ -657,6 +801,7 @@ static const struct edbus_method edbus_methods[] = { { "GetDuration", "uay", "i", edbus_get_duration }, { "CreateEffect", "iayi", "ayi", edbus_create_effect }, { "SaveBinary", "ays", "i", edbus_save_binary }, + { "ShowHandleList", NULL, NULL, edbus_show_handle_list }, /* Add methods here */ }; -- 2.7.4 From 901f49671304c989751173d8e0d6529f8e4c221c Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Mon, 4 May 2015 16:37:14 +0900 Subject: [PATCH 16/16] display: Change the default lcd timeout time to 30s (30000s->30s) Only mobile profile will need this operation. We should redesign how to manage other profile by one code. Change-Id: Ib6ab0256ed0692e3ea0f0e949fffd12fd4247315 Signed-off-by: Jiyoung Yun --- scripts/deviced-pre.sh | 2 -- src/display/core.c | 19 ++++--------------- src/display/core.h | 4 +--- src/display/setting.c | 16 +++++----------- src/display/setting.h | 6 ++---- 5 files changed, 12 insertions(+), 35 deletions(-) diff --git a/scripts/deviced-pre.sh b/scripts/deviced-pre.sh index 0238c05..cc75b70 100755 --- a/scripts/deviced-pre.sh +++ b/scripts/deviced-pre.sh @@ -31,7 +31,5 @@ done echo "PM_TOUCHSCREEN=$DEV_TOUCHSCREEN" >> $DEVICED_ENV_F echo "PM_TOUCHKEY=$DEV_TOUCHKEY" >> $DEVICED_ENV_F -echo "PM_TO_NORMAL=30000" >> $DEVICED_ENV_F -echo "PM_TO_LCDDIM=5000" >> $DEVICED_ENV_F echo "PM_SYS_DIMBRT=0" >> $DEVICED_ENV_F diff --git a/src/display/core.c b/src/display/core.c index 6212f32..2aa8260 100644 --- a/src/display/core.c +++ b/src/display/core.c @@ -595,17 +595,11 @@ static int get_lcd_timeout_from_settings(void) { int i; int val = 0; - int ret = -1; - char *buf; for (i = 0; i < S_END; i++) { switch (states[i].state) { case S_NORMAL: - ret = get_run_timeout(&val); - if (ret != 0) { - buf = getenv("PM_TO_NORMAL"); - val = (buf ? atoi(buf) : DEFAULT_NORMAL_TIMEOUT); - } + get_run_timeout(&val); break; case S_LCDDIM: get_dim_timeout(&val); @@ -667,12 +661,7 @@ static void update_display_time(void) } /* default setting */ - ret = get_run_timeout(&run_timeout); - if (ret < 0 || run_timeout < 0) { - _E("Can not get run timeout. set default %d ms", - DEFAULT_NORMAL_TIMEOUT); - run_timeout = DEFAULT_NORMAL_TIMEOUT; - } + get_run_timeout(&run_timeout); /* for sdk * if the run_timeout is zero, it regards AlwaysOn state @@ -2269,8 +2258,8 @@ static void display_init(void *data) timeout = states[S_NORMAL].timeout; /* check minimun lcd on time */ - if (timeout < DEFAULT_NORMAL_TIMEOUT) - timeout = DEFAULT_NORMAL_TIMEOUT; + if (timeout < SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT)) + timeout = SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT); reset_timeout(timeout); status = DEVICE_OPS_STATUS_START; diff --git a/src/display/core.h b/src/display/core.h index 2fe42f4..ed12c77 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -43,9 +43,7 @@ #define PWROFF_FLAG 0x00004000 #define DIMSTAY_FLAG 0x00008000 -#define DEFAULT_NORMAL_TIMEOUT 30000 -#define DEFAULT_DIM_TIMEOUT 5000 -#define DEFAULT_OFF_TIMEOUT 1000 +#define DEFAULT_NORMAL_TIMEOUT 30 #define MASK32 0xffffffff diff --git a/src/display/setting.c b/src/display/setting.c index 4fc32b8..731a2a0 100644 --- a/src/display/setting.c +++ b/src/display/setting.c @@ -109,13 +109,13 @@ int get_setting_brightness(int *level) return vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, level); } -int get_dim_timeout(int *dim_timeout) +void get_dim_timeout(int *dim_timeout) { int vconf_timeout, on_timeout, val, ret; if (custom_dim_timeout > 0) { *dim_timeout = custom_dim_timeout; - return 0; + return; } ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout); @@ -134,11 +134,9 @@ int get_dim_timeout(int *dim_timeout) val = LCD_MAX_DIM_TIMEOUT; *dim_timeout = val; - - return 0; } -int get_run_timeout(int *timeout) +void get_run_timeout(int *timeout) { int dim_timeout = -1; int vconf_timeout = -1; @@ -147,7 +145,7 @@ int get_run_timeout(int *timeout) if (custom_normal_timeout > 0) { *timeout = custom_normal_timeout; - return 0; + return; } ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout); @@ -161,17 +159,13 @@ int get_run_timeout(int *timeout) else on_timeout = SEC_TO_MSEC(vconf_timeout); - if (on_timeout < 0) - return -ERANGE; - if (on_timeout == 0) { *timeout = on_timeout; - return 0; + return; } get_dim_timeout(&dim_timeout); *timeout = on_timeout - dim_timeout; - return 0; } int set_custom_lcdon_timeout(int timeout) diff --git a/src/display/setting.h b/src/display/setting.h index dd0133d..93795be 100644 --- a/src/display/setting.h +++ b/src/display/setting.h @@ -70,18 +70,16 @@ extern int exit_setting(); * * @internal * @param[out] timeout timeout variable pointer - * @return 0 : success, -1 : error */ -extern int get_run_timeout(int *timeout); +void get_run_timeout(int *timeout); /* * get LCD dim state timeout from environment variable. * * @internal * @param[out] dim_timeout timeout variable pointer - * @return 0 : success, negative value : error */ -extern int get_dim_timeout(int *dim_timeout); +void get_dim_timeout(int *dim_timeout); /* * get USB connection status from SLP-setting SLP_SETTING_USB_STATUS * -- 2.7.4