From 3f9e37d4c1d9a6f5c2c8f11580f1fa0364f88373 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Wed, 23 Nov 2016 18:17:19 +0900 Subject: [PATCH 01/16] thermal: launch overhead popup and noti According to the thermal status, overheat popup and notification are launched. Change-Id: I2513fdd931460cb1a15b7f8338dd9b0f56f66d16 Signed-off-by: taeyoung --- src/apps/apps.c | 1 + src/apps/apps.h | 1 + src/shared/dbus.h | 3 +++ src/thermal/thermal.c | 38 ++++++++++++++++++++++++++++++++++---- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/apps/apps.c b/src/apps/apps.c index be8f3e8..4b7cec6 100755 --- a/src/apps/apps.c +++ b/src/apps/apps.c @@ -33,6 +33,7 @@ static const struct app_dbus_match { } app_match[] = { { APP_DEFAULT , POPUP_BUS_NAME, POPUP_PATH_SYSTEM , POPUP_INTERFACE_SYSTEM , POPUP_METHOD }, { APP_POWERKEY, POPUP_BUS_NAME, POPUP_PATH_POWERKEY, POPUP_INTERFACE_POWERKEY, POPUP_METHOD }, + { APP_OVERHEAT, POPUP_BUS_NAME, POPUP_PATH_OVERHEAT, POPUP_INTERFACE_OVERHEAT, POPUP_METHOD }, }; int launch_system_app(char *type, int num, ...) diff --git a/src/apps/apps.h b/src/apps/apps.h index 37d4ff3..cfcea7a 100755 --- a/src/apps/apps.h +++ b/src/apps/apps.h @@ -25,6 +25,7 @@ #include "display/poll.h" #define APP_POWERKEY "powerkey" +#define APP_OVERHEAT "overheat" #define APP_DEFAULT "system" #define APP_KEY_TYPE "_SYSPOPUP_CONTENT_" diff --git a/src/shared/dbus.h b/src/shared/dbus.h index a9816d5..eed12cb 100644 --- a/src/shared/dbus.h +++ b/src/shared/dbus.h @@ -198,6 +198,9 @@ /* System */ #define POPUP_PATH_SYSTEM POPUP_OBJECT_PATH"/System" #define POPUP_INTERFACE_SYSTEM POPUP_INTERFACE_NAME".System" +/* Overheat */ +#define POPUP_PATH_OVERHEAT POPUP_OBJECT_PATH"/Overheat" +#define POPUP_INTERFACE_OVERHEAT POPUP_INTERFACE_NAME".Overheat" /* Crash */ #define POPUP_PATH_CRASH POPUP_OBJECT_PATH"/Crash" #define POPUP_INTERFACE_CRASH POPUP_INTERFACE_NAME".Crash" diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c index 2ebc546..603eda4 100644 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -22,12 +22,35 @@ #include #include +#include "apps/apps.h" #include "core/devices.h" #include "core/log.h" #include "core/device-notifier.h" static struct thermal_device *thermal_dev; +static int noti; + +static void thermal_remove_noti(void) +{ + if (noti) { + remove_notification("TempCooldownNotiOff", noti); + noti = 0; + } +} + +static void thermal_add_noti(void) +{ + if (!noti) + noti = add_notification("TempCooldownNotiOn"); +} + +static void thermal_add_popup(void) +{ + launch_system_app(APP_OVERHEAT, 2, + APP_KEY_TYPE, "overheat"); +} + static void thermal_action(struct thermal_info *info, void *data) { if (!info) @@ -36,18 +59,25 @@ static void thermal_action(struct thermal_info *info, void *data) switch (info->state) { case THERMAL_STATE_LOW: _E("THERMAL: temparature LOW"); + thermal_remove_noti(); break; case THERMAL_STATE_NORMAL: _I("THERMAL: temparature normal"); + thermal_remove_noti(); break; case THERMAL_STATE_HIGH: - if (info->level == THERMAL_LEVEL_WARNING) + if (info->level == THERMAL_LEVEL_WARNING) { _E("THERMAL: temparature HIGH (warning)"); - else if (info->level == THERMAL_LEVEL_CRITICAL) + thermal_add_noti(); + } else if (info->level == THERMAL_LEVEL_CRITICAL) { _E("THERMAL: temparature HIGH (critical)"); - else if (info->level == THERMAL_LEVEL_POWEROFF) + thermal_remove_noti(); + thermal_add_popup(); + } else if (info->level == THERMAL_LEVEL_POWEROFF) { _E("THERMAL: temparature HIGH (poweroff)"); - else + thermal_remove_noti(); + thermal_add_popup(); + } else _E("THERMAL: temparature HIGH"); break; default: -- 2.7.4 From 888b4c24908d3440a9faf03e539133bfb96e4a58 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Tue, 22 Nov 2016 18:07:12 +0900 Subject: [PATCH 02/16] display: remove dependency related with X X is not used anymore. Change-Id: Ibf3b7c5267ee0158cb848b349af01cc6b1206412 Signed-off-by: taeyoung --- packaging/deviced.spec | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index b9ed6e1..d273492 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -78,10 +78,6 @@ BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(hwcommon) BuildRequires: pkgconfig(capi-system-info) %if %{?display_module} == on -%if %{with x} -BuildRequires: pkgconfig(x11) -BuildRequires: pkgconfig(xext) -%endif BuildRequires: pkgconfig(libinput) BuildRequires: pkgconfig(capi-system-sensor) %endif -- 2.7.4 From ff258538283b936f5d422a7b05b0fc52f0656467 Mon Sep 17 00:00:00 2001 From: Jeong Donghwan Date: Wed, 23 Nov 2016 19:21:26 +0900 Subject: [PATCH 03/16] display: remove unnecessary vconf setting This value was set long ago. Now it is not used. Change-Id: I7522d0a4ec6a0ca49a1edd3cee46c2682d061e0b Signed-off-by: Jeong Donghwan --- src/display/device-interface.c | 8 -------- src/display/display-dbus.c | 12 +----------- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/src/display/device-interface.c b/src/display/device-interface.c index 874d696..7e33762 100644 --- a/src/display/device-interface.c +++ b/src/display/device-interface.c @@ -118,7 +118,6 @@ static int bl_onoff(int on) static int bl_brt(int brightness, int delay) { int ret = -1; - int prev; if (delay > 0) usleep(delay); @@ -129,13 +128,6 @@ static int bl_brt(int brightness, int delay) brightness = force_brightness; } - ret = backlight_ops.get_brightness(&prev); - - /* Update new brightness to vconf */ - if (!ret && (brightness != prev)) { - vconf_set_int(VCONFKEY_PM_CURRENT_BRIGHTNESS, brightness); - } - /* Update device brightness */ ret = backlight_ops.set_brightness(brightness); diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index a94b8bd..d733655 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -418,9 +418,6 @@ static DBusMessage *edbus_setbrightness(E_DBus_Object *obj, DBusMessage *msg) if (vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt) != 0) _E("Failed to set VCONFKEY_SETAPPL_LCD_BRIGHTNESS value"); - if (vconf_set_int(VCONFKEY_PM_CURRENT_BRIGHTNESS, brt) != 0) - _E("Failed to set VCONFKEY_PM_CURRENT_BRIGHTNESS value"); - _I("set brightness %d, %d", brt, ret); error: @@ -469,9 +466,6 @@ static DBusMessage *edbus_holdbrightness(E_DBus_Object *obj, DBusMessage *msg) vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_PAUSE); } - if (vconf_set_int(VCONFKEY_PM_CURRENT_BRIGHTNESS, brt) != 0) - _E("Failed to set VCONFKEY_PM_CURRENT_BRIGHTNESS value"); - _I("hold brightness %d, %d", brt, ret); error: @@ -535,12 +529,8 @@ static DBusMessage *edbus_releasebrightness(E_DBus_Object *obj, DBusMessage *msg } if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_OFF) { - if (brt != setting) { + if (brt != setting) backlight_ops.set_brightness(setting); - if (vconf_set_int(VCONFKEY_PM_CURRENT_BRIGHTNESS, setting) != 0) { - _E("Failed to set VCONFKEY_PM_CURRENT_BRIGHTNESS value"); - } - } } else if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) { _D("Auto brightness will be enable"); vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_ON); -- 2.7.4 From a85c924f1bc605864ee67af2d21f7b3c7bf1b786 Mon Sep 17 00:00:00 2001 From: Kunhoon Baik Date: Wed, 23 Nov 2016 17:42:32 +0900 Subject: [PATCH 04/16] Potential Bug Fix : Checking NULL Change-Id: Id9c6bbdfe2d64933495a6d8a91080270543a916c --- src/block/block.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/block/block.c b/src/block/block.c index d88bad3..fd399aa 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -1664,8 +1664,15 @@ static void trigger_operation(struct block_device *bdev, dd_list *queue, struct block_send_dbus_reply(op->msg, ret); queue = bdev->op_queue; - queue = DD_LIST_NEXT(queue); - op = DD_LIST_NTH(queue, 0); + if(queue != NULL) { + queue = DD_LIST_NEXT(queue); + if(queue != NULL) + op = DD_LIST_NTH(queue, 0); + else + op = NULL; + }else + op = NULL; + remove_operation(bdev); pthread_mutex_unlock(&(th_manager[thread_id].mutex)); -- 2.7.4 From bda0c5f8acec312a633f717f94e40a6aae6a679d Mon Sep 17 00:00:00 2001 From: Kunhoon Baik Date: Sat, 19 Nov 2016 01:08:46 +0900 Subject: [PATCH 05/16] Remove Eventsystem BOOT_COMPLETED Event In Tizen 3.0, the meaning of event system SYS_EVENT_BOOT_COMPLETED is different. (It should be aware Session Switching. For the detail, contact to Mr.Ko JoungMyeong for the event system) Thus, BOOT_COMPLETED event is removed because deviced does not aware session switching in Tizen 3.0 Change-Id: Ia8323fd8e52b48b663579680904094b9e4759487 --- src/power/boot.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/power/boot.c b/src/power/boot.c index 623add9..34fa541 100644 --- a/src/power/boot.c +++ b/src/power/boot.c @@ -65,19 +65,6 @@ int booting_finished(void) return ret; } - -static void boot_complete_send_system_event(void) -{ - bundle *b; - const char *str = EVT_VAL_BOOT_COMPLETED_TRUE; - - b = bundle_create(); - bundle_add_str(b, EVT_KEY_BOOT_COMPLETED, str); - eventsystem_send_system_event(SYS_EVENT_BOOT_COMPLETED, b); - bundle_free(b); -} - - void remove_booting_done_handler(void *data) { unregister_edbus_signal_handler(SYSTEMD_DBUS_PATH, @@ -128,8 +115,6 @@ static void booting_done_received(void *data, DBusMessage *msg) DEVICED_INTERFACE_CORE, SIGNAL_BOOTING_DONE, NULL, NULL); - - boot_complete_send_system_event(); } void add_booting_done_handler(void *data) -- 2.7.4 From 6d47a5f1c76f3724b6dccaf71b672f57308f5012 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Mon, 28 Nov 2016 11:14:00 +0900 Subject: [PATCH 06/16] usb: do not start/stop operations with emulator environtment - Emulator does not support mtp, rndis, and so on. And sdbd should not be stopped in emulator. Thus all operation start/stop routine need to be skipped with emulator environtment. Change-Id: Ia23842a880f7c4e2ca529929b28040780ce48b8d Signed-off-by: taeyoung --- src/usb/usb-operation.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/usb/usb-operation.c b/src/usb/usb-operation.c index 403de8b..1bc8efc 100644 --- a/src/usb/usb-operation.c +++ b/src/usb/usb-operation.c @@ -101,10 +101,14 @@ static int usb_execute_operation(unsigned int mode, operation_e type) int usb_operation_start(unsigned int mode) { + if (is_emulator()) + return 0; return usb_execute_operation(mode, OPERATION_START); } int usb_operation_stop(unsigned int mode) { + if (is_emulator()) + return 0; return usb_execute_operation(mode, OPERATION_STOP); } -- 2.7.4 From 7041903f978f4511b9673d9aeb0b000b879e9cfe Mon Sep 17 00:00:00 2001 From: Jeong Donghwan Date: Mon, 28 Nov 2016 10:31:59 +0900 Subject: [PATCH 07/16] display: change async method from sync about dpms control If dpms control is sync method, when dpms is controlling, dbus method does blocking from another request until end dpms control. Change-Id: I4ccf525f4127a334989e5e63d47b6e44d6c68057 Signed-off-by: Jeong Donghwan --- src/display/dpms-wayland-none.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/display/dpms-wayland-none.c b/src/display/dpms-wayland-none.c index 52b0ea6..f5d8e72 100644 --- a/src/display/dpms-wayland-none.c +++ b/src/display/dpms-wayland-none.c @@ -20,11 +20,36 @@ #include "core/edbus-handler.h" #include "device-interface.h" +#include "util.h" #define ENLIGHTENMENT_BUS_NAME "org.enlightenment.wm" #define ENLIGHTENMENT_OBJECT_PATH "/org/enlightenment/wm" #define ENLIGHTENMENT_INTERFACE_NAME ENLIGHTENMENT_BUS_NAME".dpms" +static void dpms_set_cb(void *data, DBusMessage *msg, DBusError *r_err) +{ + DBusError err; + int state, ret; + + if (!msg) { + _E("no message [%s:%s], Cannot get pmlock check", + r_err->name, r_err->message); + return; + } + + dbus_error_init(&err); + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &state, + DBUS_TYPE_INVALID); + + if (!ret) { + _E("no message [%s:%s]", err.name, err.message); + dbus_error_free(&err); + return; + } + + _D("DPMS was set %d", state); +} + int dpms_set_power(enum dpms_state state) { char *arr[1]; @@ -33,10 +58,10 @@ int dpms_set_power(enum dpms_state state) snprintf(str, sizeof(str), "%d", state); arr[0] = str; - ret = dbus_method_sync(ENLIGHTENMENT_BUS_NAME, + ret = dbus_method_async_with_reply(ENLIGHTENMENT_BUS_NAME, ENLIGHTENMENT_OBJECT_PATH, ENLIGHTENMENT_INTERFACE_NAME, - "set", "u", arr); + "set", "u", arr, dpms_set_cb, -1, NULL); if (ret < 0) return ret; -- 2.7.4 From fe7b8f8161dc11b299dd867052a7ad26a5344181 Mon Sep 17 00:00:00 2001 From: Jeong Donghwan Date: Wed, 23 Nov 2016 21:53:00 +0900 Subject: [PATCH 08/16] display: fix initialized broadcast value First booting time, power-manager does not broadcast lcd off signal. So it should be modified initialize value. Change-Id: I2e2a3ebb686cff4819798d8656f954c1da6ee72c Signed-off-by: Jeong Donghwan --- src/display/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/display/core.c b/src/display/core.c index 8a1d1c4..348ae83 100644 --- a/src/display/core.c +++ b/src/display/core.c @@ -99,7 +99,7 @@ static struct timeval lcdon_tv; static int lcd_paneloff_mode = false; static int stay_touchscreen_off = false; static dd_list *lcdon_ops; -static bool lcdon_broadcast = false; +static bool lcdon_broadcast = true; static bool touch_blocked = false; -- 2.7.4 From 4b87a6363e9e1b19a6d7a7849b90d73e4608c2c4 Mon Sep 17 00:00:00 2001 From: Jeong Donghwan Date: Mon, 28 Nov 2016 10:37:58 +0900 Subject: [PATCH 09/16] common: add CMAKE option about verbose value cmake verbose option change to false value Change-Id: I193b57aefaaf8300732dee8fc8c60b15dd44c93b Signed-off-by: Jeong Donghwan --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 517bdfc..7abebe4 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ PROJECT(deviced C) ######################################################## # Build options: ######################################################## +SET(CMAKE_VERBOSE_MAKEFILE OFF) IF("${ARCH}" STREQUAL "emulator") OPTION(USE_EMULATOR "Use Emulator" ON) ELSEIF("${ARCH}" STREQUAL "arm") -- 2.7.4 From 688981646d171c6b6eedbefd7406f4bb381e6716 Mon Sep 17 00:00:00 2001 From: Jeong Donghwan Date: Wed, 23 Nov 2016 21:25:49 +0900 Subject: [PATCH 10/16] poll: missing pmlock timeout_id after be requested again Under scenario, power-manager will be released pmlock. Because, previous sequence, when pmlock node was existed with restriced timer, if pmlock is requested with infinity lock, 'node->timeout_id' is null already. So old timeout_id(restricted timer) can not be removed. Problem scenamrio : 1. 'A' process was requested pmlock with infinity lock. 2. Same process was requested pmlock with 5 second. 3. Same process was requested pmlock with infinity lock before release previious lock 4. This requested pmlock will be released despite infinity option. Change-Id: Icd5a3460b275508056b7e777653a05b5aad8fb90 Signed-off-by: Jeong Donghwan --- src/display/core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/display/core.c b/src/display/core.c index 348ae83..b2d61b3 100644 --- a/src/display/core.c +++ b/src/display/core.c @@ -895,10 +895,9 @@ static void update_lock_timer(PMMsg *data, node->time = now; } - if (node->timeout_id) { + if (node->timeout_id) ecore_timer_del(node->timeout_id); - node->timeout_id = timeout_id; - } + node->timeout_id = timeout_id; } static void proc_condition_lock(PMMsg *data) -- 2.7.4 From eb89b8c41f1048e4a0febf2f804b72ac6c8f10ee Mon Sep 17 00:00:00 2001 From: Jeong Donghwan Date: Wed, 23 Nov 2016 21:01:54 +0900 Subject: [PATCH 11/16] poll: modify pmlock manager data structure PMLockNode structure used custom list. So it is modified to data structure providing from the library. Change-Id: I657e0be9224f4d5e4f18a52641cb9b716df11ae2 Signed-off-by: Jeong Donghwan --- src/display/core.c | 103 ++++++++++++++++++++++------------------------------- 1 file changed, 42 insertions(+), 61 deletions(-) diff --git a/src/display/core.c b/src/display/core.c index b2d61b3..9ffbcb5 100644 --- a/src/display/core.c +++ b/src/display/core.c @@ -212,11 +212,10 @@ typedef struct _pm_lock_node { Ecore_Timer *timeout_id; time_t time; bool holdkey_block; - struct _pm_lock_node *next; bool background; } PmLockNode; -static PmLockNode *cond_head[S_END]; +static dd_list *cond_head[S_END]; static void set_process_active(bool flag, pid_t pid) { @@ -241,12 +240,12 @@ static void set_process_active(bool flag, pid_t pid) bool check_lock_state(int state) { - PmLockNode *t = cond_head[state]; + dd_list *elem; + PmLockNode *t; - while (t) { + DD_LIST_FOREACH(cond_head[state], elem, t) { if (t->background == false) return true; - t = t->next; } return false; @@ -471,14 +470,15 @@ static void makeup_trans_condition(void) static PmLockNode *find_node(enum state_t s_index, pid_t pid) { - PmLockNode *t = cond_head[s_index]; + dd_list *elem; + PmLockNode *t; - while (t != NULL) { + DD_LIST_FOREACH(cond_head[s_index], elem, t) { if (t->pid == pid) - break; - t = t->next; + return t; } - return t; + + return NULL; } static PmLockNode *add_node(enum state_t s_index, pid_t pid, Ecore_Timer *timeout_id, @@ -498,9 +498,8 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, Ecore_Timer *timeou n->timeout_id = timeout_id; n->time = now; n->holdkey_block = holdkey_block; - n->next = cond_head[s_index]; n->background = false; - cond_head[s_index] = n; + DD_LIST_APPEND(cond_head[s_index], n); refresh_app_cond(); return n; @@ -508,35 +507,24 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, Ecore_Timer *timeou static int del_node(enum state_t s_index, PmLockNode *n) { - PmLockNode *t; - PmLockNode *prev; - if (n == NULL) return 0; - t = cond_head[s_index]; - prev = NULL; - while (t != NULL) { - if (t == n) { - if (prev != NULL) - prev->next = t->next; - else - cond_head[s_index] = cond_head[s_index]->next; - /* delete timer */ - if (t->timeout_id) - ecore_timer_del(t->timeout_id); - free(t); - break; - } - prev = t; - t = t->next; + DD_LIST_REMOVE(cond_head[s_index], n); + + /* delete timer */ + if (n->timeout_id) { + ecore_timer_del(n->timeout_id); + n->timeout_id = NULL; } + free(n); refresh_app_cond(); return 0; } static void print_node(int next) { + dd_list *elem; PmLockNode *n; char buf[30]; time_t now; @@ -546,8 +534,7 @@ static void print_node(int next) return; time(&now); - n = cond_head[next]; - while (n != NULL) { + DD_LIST_FOREACH(cond_head[next], elem, n) { diff = difftime(now, n->time); ctime_r(&n->time, buf); @@ -555,8 +542,6 @@ static void print_node(int next) _W("over %.0f s, pid: %5d, lock time: %s", diff, n->pid, buf); else _I("pid: %5d, lock time: %s", n->pid, buf); - - n = n->next; } } @@ -1014,11 +999,11 @@ static int proc_condition(PMMsg *data) /* If some changed, return 1 */ int check_processes(enum state_t prohibit_state) { - PmLockNode *t = cond_head[prohibit_state]; - PmLockNode *tmp = NULL; + dd_list *elem, *next; + PmLockNode *t; int ret = 0; - while (t != NULL) { + DD_LIST_FOREACH_SAFE(cond_head[prohibit_state], elem, next, t) { if (t->pid < INTERNAL_LOCK_BASE && kill(t->pid, 0) == -1) { _E("%d process does not exist, delete the REQ" " - prohibit state %d ", @@ -1028,14 +1013,8 @@ int check_processes(enum state_t prohibit_state) custom_normal_timeout = custom_dim_timeout = 0; custom_change_pid = -1; } - tmp = t; ret = 1; - } - t = t->next; - - if (tmp != NULL) { - del_node(prohibit_state, tmp); - tmp = NULL; + del_node(prohibit_state, t); } } @@ -1044,7 +1023,8 @@ int check_processes(enum state_t prohibit_state) int check_holdkey_block(enum state_t state) { - PmLockNode *t = cond_head[state]; + dd_list *elem; + PmLockNode *t; int ret = 0; _I("check holdkey block : state of %s", states[state].name); @@ -1055,13 +1035,12 @@ int check_holdkey_block(enum state_t state) return 1; } - while (t != NULL) { + DD_LIST_FOREACH(cond_head[state], elem, t) { if (t->holdkey_block == true) { ret = 1; _I("Hold key blocked by pid(%d)!", t->pid); break; } - t = t->next; } return ret; @@ -1069,29 +1048,33 @@ int check_holdkey_block(enum state_t state) int delete_condition(enum state_t state) { - PmLockNode *t = cond_head[state]; - PmLockNode *tmp = NULL; + dd_list *elem, *next; + PmLockNode *t; pid_t pid; char pname[PATH_MAX]; _I("delete condition : state of %s", states[state].name); - while (t != NULL) { + if (!cond_head[state]) + return 0; + + DD_LIST_FOREACH_SAFE(cond_head[state], elem, next, t) { if (t->timeout_id > 0) { ecore_timer_del(t->timeout_id); t->timeout_id = NULL; } - tmp = t; - t = t->next; - pid = tmp->pid; + pid = t->pid; if (state == S_LCDOFF) set_process_active(EINA_FALSE, pid); _I("delete node of pid(%d)", pid); - del_node(state, tmp); + del_node(state, t); get_pname(pid, pname); set_unlock_time(pname, state-1); } + DD_LIST_FREE_LIST(cond_head[state]); + cond_head[state] = NULL; + return 0; } @@ -1190,6 +1173,9 @@ void print_info(int fd) int i = 1; int ret; char pname[PATH_MAX]; + PmLockNode *t; + dd_list *elem; + char time_buf[30]; if (fd < 0) return; @@ -1227,11 +1213,7 @@ void print_info(int fd) _E("write() failed (%d)", errno); for (s_index = S_NORMAL; s_index < S_END; s_index++) { - PmLockNode *t; - char time_buf[30]; - t = cond_head[s_index]; - - while (t != NULL) { + DD_LIST_FOREACH(cond_head[s_index], elem, t) { get_pname((pid_t)t->pid, pname); ctime_r(&t->time, time_buf); snprintf(buf, sizeof(buf), @@ -1240,7 +1222,6 @@ void print_info(int fd) ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("write() failed (%d)", errno); - t = t->next; } } -- 2.7.4 From da55762da365d979857ac62ee70b6c37bcd2969c Mon Sep 17 00:00:00 2001 From: taeyoung Date: Thu, 24 Nov 2016 10:46:24 +0900 Subject: [PATCH 12/16] usb host: turn on display when usb otg devices are inserted Turning on display according to the state change of usb otg is added like Tizen 2.4 Change-Id: I03bd1c4fb4b31e60d7dff2914f539204464d4daf Signed-off-by: taeyoung --- src/usbhost/usb-host.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index 2679cac..02b03b5 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -266,6 +266,8 @@ static int add_usbhost_list(struct udev_device *dev, const char *devpath) broadcast_usbhost_signal(USB_HOST_ADDED, usbhost); + pm_change_internal(INTERNAL_LOCK_USB, LCD_NORMAL); + /* for debugging */ _I("USB HOST Added"); print_usbhost(usbhost); @@ -292,6 +294,8 @@ static int remove_usbhost_list(const char *devpath) broadcast_usbhost_signal(USB_HOST_REMOVED, usbhost); + pm_change_internal(INTERNAL_LOCK_USB, LCD_NORMAL); + /* for debugging */ _I("USB HOST Removed"); _I("devpath : %s", usbhost->devpath); -- 2.7.4 From 95327b5b94f373cc01499f92c0826e000c52f5ec Mon Sep 17 00:00:00 2001 From: taeyoung Date: Mon, 28 Nov 2016 22:47:25 +0900 Subject: [PATCH 13/16] usb host: lock cpu when usb otg connector is connected usb otg connector can be notified by the extcon event. If usb otg connector is connected, CPU needs to be locked Change-Id: Ic5569bf97f5716d1a99d84e720ed8936a0875458 Signed-off-by: taeyoung --- src/extcon/extcon.h | 15 ++++++++------- src/usbhost/usb-host.c | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/extcon/extcon.h b/src/extcon/extcon.h index df42bbc..5a53454 100755 --- a/src/extcon/extcon.h +++ b/src/extcon/extcon.h @@ -21,18 +21,19 @@ #define __EXTCON_H__ #include "core/common.h" +#include /** * Extcon cable name is shared with kernel extcon class. * So do not change below strings. */ -#define EXTCON_CABLE_USB "USB" -#define EXTCON_CABLE_USB_HOST "USB-Host" -#define EXTCON_CABLE_TA "TA" -#define EXTCON_CABLE_HDMI "HDMI" -#define EXTCON_CABLE_DOCK "Dock" -#define EXTCON_CABLE_MIC_IN "Microphone" -#define EXTCON_CABLE_HEADPHONE_OUT "Headphone" +#define EXTCON_CABLE_USB EXTERNAL_CONNECTION_USB +#define EXTCON_CABLE_USB_HOST EXTERNAL_CONNECTION_USB_HOST +#define EXTCON_CABLE_TA EXTERNAL_CONNECTION_TA +#define EXTCON_CABLE_HDMI EXTERNAL_CONNECTION_HDMI +#define EXTCON_CABLE_DOCK EXTERNAL_CONNECTION_DOCK +#define EXTCON_CABLE_MIC_IN EXTERNAL_CONNECTION_MIC +#define EXTCON_CABLE_HEADPHONE_OUT EXTERNAL_CONNECTION_HEADPHONE struct extcon_ops { const char *name; diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index 02b03b5..c44fa5f 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -31,6 +31,7 @@ #include "core/list.h" #include "core/device-idler.h" #include "apps/apps.h" +#include "extcon/extcon.h" #define USB_INTERFACE_CLASS "bInterfaceClass" #define USB_INTERFACE_SUBCLASS "bInterfaceSubClass" @@ -1323,3 +1324,22 @@ static const struct device_ops usbhost_device_ops = { }; DEVICE_OPS_REGISTER(&usbhost_device_ops) + +static int extcon_usbhost_state_changed(int status) +{ + if (status == 0) { + _I("USB host connector disconnected"); + pm_unlock_internal(INTERNAL_LOCK_USB, LCD_OFF, STAY_CUR_STATE); + } else { + _I("USB host connector connected"); + pm_lock_internal(INTERNAL_LOCK_USB, LCD_OFF, STAY_CUR_STATE, 0); + } + return 0; +} + +struct extcon_ops extcon_usbhost_ops = { + .name = EXTCON_CABLE_USB_HOST, + .update = extcon_usbhost_state_changed, +}; + +EXTCON_OPS_REGISTER(extcon_usbhost_ops) -- 2.7.4 From 9508fef888c74fd579a065a1d6346614c84bb83f Mon Sep 17 00:00:00 2001 From: taeyoung Date: Fri, 25 Nov 2016 11:04:37 +0900 Subject: [PATCH 14/16] event handler: change value type from real value to the address of the value - If an integer value is delivered by casting to (void *), size issue occurs in 64 bit ebvironment. Thus the address of the value is used for delivering. Change-Id: Ic8dc10c82a57631ba5b46d71705fae20dd9fdb27 Signed-off-by: taeyoung --- src/battery/power-supply.c | 9 ++++++--- src/core/event-handler.c | 4 ++-- src/core/udev.c | 6 +++--- src/extcon/extcon.c | 8 +++++--- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index ef5f5b7..4117e05 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -1285,7 +1285,7 @@ static void remove_power_supply_handler(void) static int event_handler_state_changed(void *data) { static device_notifier_state_e old = DEVICE_NOTIFIER_STATE_STOP; - device_notifier_state_e state = (device_notifier_state_e)data; + device_notifier_state_e state = *(device_notifier_state_e *)data; if (old == state) return 0; @@ -1303,10 +1303,11 @@ static int event_handler_state_changed(void *data) static void power_supply_init(void *data) { int ret; + device_notifier_state_e state = DEVICE_NOTIFIER_STATE_START; battery.capacity = -1; - event_handler_state_changed((void *)DEVICE_NOTIFIER_STATE_START); + event_handler_state_changed((void *)&state); /* process check battery timer until booting done */ power_supply_timer_start(); @@ -1330,11 +1331,13 @@ static void power_supply_init(void *data) static void power_supply_exit(void *data) { + device_notifier_state_e state = DEVICE_NOTIFIER_STATE_STOP; + unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); unregister_notifier(DEVICE_NOTIFIER_LCD, display_changed); unregister_notifier(DEVICE_NOTIFIER_EVENT_HANDLER, event_handler_state_changed); - event_handler_state_changed((void *)DEVICE_NOTIFIER_STATE_STOP); + event_handler_state_changed((void *)&state); } static const struct device_ops power_supply_ops = { diff --git a/src/core/event-handler.c b/src/core/event-handler.c index b704c99..7a4fe85 100644 --- a/src/core/event-handler.c +++ b/src/core/event-handler.c @@ -33,7 +33,7 @@ static DBusMessage *dbus_start_event_handler(E_DBus_Object *obj, DBusMessage *ms if (state != DEVICE_NOTIFIER_STATE_START) { _D("START event-handler"); state = DEVICE_NOTIFIER_STATE_START; - device_notify(DEVICE_NOTIFIER_EVENT_HANDLER, (void *)state); + device_notify(DEVICE_NOTIFIER_EVENT_HANDLER, (void *)&state); } return make_reply_message(msg, 0); } @@ -43,7 +43,7 @@ static DBusMessage *dbus_stop_event_handler(E_DBus_Object *obj, DBusMessage *msg if (state != DEVICE_NOTIFIER_STATE_STOP) { _D("STOP event-handler"); state = DEVICE_NOTIFIER_STATE_STOP; - device_notify(DEVICE_NOTIFIER_EVENT_HANDLER, (void *)state); + device_notify(DEVICE_NOTIFIER_EVENT_HANDLER, (void *)&state); } return make_reply_message(msg, 0); } diff --git a/src/core/udev.c b/src/core/udev.c index dff0c5d..45ebb47 100644 --- a/src/core/udev.c +++ b/src/core/udev.c @@ -262,12 +262,12 @@ int unregister_udev_uevent_control(const struct uevent_handler *uh) static int device_event_handler(void *data) { - int state = (int)data; + device_notifier_state_e state = *(device_notifier_state_e *)data; - if (state > 0) { + if (state == DEVICE_NOTIFIER_STATE_START) { uevent_control_start(KERNEL, &kevent); uevent_control_start(UDEV, &uevent); - } else { + } else if (state == DEVICE_NOTIFIER_STATE_STOP) { uevent_control_stop(&kevent); uevent_control_stop(&uevent); } diff --git a/src/extcon/extcon.c b/src/extcon/extcon.c index 9cfe026..7719748 100755 --- a/src/extcon/extcon.c +++ b/src/extcon/extcon.c @@ -369,7 +369,7 @@ static void remove_extcon_event_handler(void) static int event_handler_state_changed(void *data) { static device_notifier_state_e old = DEVICE_NOTIFIER_STATE_STOP; - device_notifier_state_e state = (device_notifier_state_e)data; + device_notifier_state_e state = *(device_notifier_state_e *)data; if (old == state) return 0; @@ -389,6 +389,7 @@ static void extcon_init(void *data) int ret; dd_list *l; struct extcon_ops *dev; + device_notifier_state_e state = DEVICE_NOTIFIER_STATE_START; if (!extcon_list) return; @@ -400,7 +401,7 @@ static void extcon_init(void *data) dev->init(data); } - event_handler_state_changed((void *)DEVICE_NOTIFIER_STATE_START); + event_handler_state_changed((void *)&state); /* register extcon object first */ ret = register_edbus_interface_and_method(DEVICED_PATH_EXTCON, @@ -416,10 +417,11 @@ static void extcon_exit(void *data) { dd_list *l; struct extcon_ops *dev; + device_notifier_state_e state = DEVICE_NOTIFIER_STATE_STOP; unregister_notifier(DEVICE_NOTIFIER_EVENT_HANDLER, event_handler_state_changed); - event_handler_state_changed((void *)DEVICE_NOTIFIER_STATE_STOP); + event_handler_state_changed((void *)&state); /* deinitialize extcon devices */ DD_LIST_FOREACH(extcon_list, l, dev) { -- 2.7.4 From 1f48c5def1bf3f8420609b2036464103311e3aff Mon Sep 17 00:00:00 2001 From: taeyoung Date: Fri, 25 Nov 2016 17:01:07 +0900 Subject: [PATCH 15/16] led: add led notification (rgb) - LED notification is related with the front led which can shows RGB colors. The led notification is added for the led apis of capi-system-device. Change-Id: I8793433fbe843d29852416464c93ee12aa4d01a8 Signed-off-by: taeyoung --- src/led/rgb.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 src/led/rgb.c diff --git a/src/led/rgb.c b/src/led/rgb.c new file mode 100644 index 0000000..47afc9d --- /dev/null +++ b/src/led/rgb.c @@ -0,0 +1,167 @@ +/* + * deviced + * + * Copyright (c) 2012 - 2016 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/edbus-handler.h" +#include "core/devices.h" +#include "core/device-notifier.h" + +/* enum values defined in capi-system-device */ +typedef enum { + LED_CUSTOM_DUTY_ON = 1 << 0, /**< blink LED */ + LED_CUSTOM_DEFAULT = (LED_CUSTOM_DUTY_ON), /**< Default flag */ +} led_custom_flags; + +struct led_device *rgb_dev; + +static int rgb_play(struct led_state *state) +{ + if (!rgb_dev) { + _E("There is NO HAL"); + return -ENODEV; + } + + if (!rgb_dev->set_state) { + _E("LED HAL does not support set_state()"); + return -ENOTSUP; + } + + return rgb_dev->set_state(state); +} + +static DBusMessage *edbus_playcustom(E_DBus_Object *obj, DBusMessage *msg) +{ + int ret; + int on, off; + unsigned int color, flags; + struct led_state state; + pid_t pid; + + ret = dbus_message_get_args(msg, NULL, + DBUS_TYPE_INT32, &on, + DBUS_TYPE_INT32, &off, + DBUS_TYPE_UINT32, &color, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID); + if (!ret) { + _I("there is no message"); + ret = -EINVAL; + goto out; + } + + pid = get_edbus_sender_pid(msg); + + _I("pid %d led play custom %d, %d, %x", pid, on, off, color); + + state.color = color; + state.duty_on = on; + state.duty_off = off; + if (flags & LED_CUSTOM_DUTY_ON) + state.type = LED_TYPE_BLINK; + else + state.type = LED_TYPE_MANUAL; + + ret = rgb_play(&state); + if (ret < 0) + _E("Failed to play LED notification (%d)", ret); + +out: + return make_reply_message(msg, ret); +} + +static DBusMessage *edbus_stopcustom(E_DBus_Object *obj, DBusMessage *msg) +{ + struct led_state state = { 0, }; + int ret; + pid_t pid; + + pid = get_edbus_sender_pid(msg); + + _I("pid %d led stop custom", pid); + + ret = rgb_play(&state); + if (ret < 0) + _E("Failed to play LED notification (%d)", ret); + + return make_reply_message(msg, ret); +} + +static const struct edbus_method edbus_methods[] = { + { "playcustom", "iiuu", "i", edbus_playcustom }, + { "stopcustom", NULL, "i", edbus_stopcustom }, + /* Add methods here */ +}; + +static void rgb_init(void *data) +{ + int ret; + + /* init dbus interface */ + ret = register_edbus_interface_and_method(DEVICED_PATH_LED, + DEVICED_INTERFACE_LED, + edbus_methods, ARRAY_SIZE(edbus_methods)); + if (ret < 0) + _E("fail to init edbus interface and method(%d)", ret); +} + +static int rgb_probe(void *data) +{ + struct hw_info *info; + int ret; + + if (rgb_dev) + return 0; + + ret = hw_get_info(LED_HARDWARE_DEVICE_ID, + (const struct hw_info **)&info); + if (ret < 0) { + _E("There is no LED HAL"); + return -ENOTSUP; + } + + if (!info->open) { + _E("Failed to open led device; open(NULL)"); + return -ENODEV; + } + + ret = info->open(info, LED_ID_NOTIFICATION, (struct hw_common **)&rgb_dev); + if (ret < 0) { + _E("Failed to get LED NOTIFICATION device structure (%d)", ret); + return ret; + } + + _I("LED NOTIFICATION device structure load success"); + return 0; +} + +static const struct device_ops rgbled_device_ops = { + .name = "rgbled", + .probe = rgb_probe, + .init = rgb_init, +}; + +DEVICE_OPS_REGISTER(&rgbled_device_ops) -- 2.7.4 From 1e20603ff54f9bdfbaeca1249eaa0a2c0ea7ff7d Mon Sep 17 00:00:00 2001 From: taeyoung Date: Wed, 30 Nov 2016 12:42:07 +0900 Subject: [PATCH 16/16] power: turn off modem during power off - CP modem needs to be turned off during power off Change-Id: I28c287c091e7028d2018f93da5447f7ce6971f78 Signed-off-by: taeyoung --- CMakeLists.txt | 8 +++ packaging/deviced.spec | 6 ++ src/power/power-handler.c | 55 ++++++++----------- src/power/power-handler.h | 3 + src/telephony/telephony.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 176 insertions(+), 33 deletions(-) create mode 100644 src/telephony/telephony.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 7abebe4..94e6c49 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,6 +154,11 @@ IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on) DESTINATION /etc/deviced/usb-host-test/) ENDIF() +IF(TIZEN_FEATURE_TELEPHONY_MODULE STREQUAL on) + ADD_SOURCE(src/telephony TELEPHONY_SRCS) + SET(SRCS ${SRCS} ${TELEPHONY_SRCS}) +ENDIF() + INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/deviced) @@ -188,6 +193,9 @@ ENDIF() IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on) SET(PKG_MODULES ${PKG_MODULES} libkmod libusbg) ENDIF() +IF(TIZEN_FEATURE_TELEPHONY_MODULE STREQUAL on) + SET(PKG_MODULES ${PKG_MODULES} tapi) +ENDIF() INCLUDE(FindPkgConfig) pkg_check_modules(pkgs REQUIRED ${PKG_MODULES}) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index d273492..b6a9c13 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -17,6 +17,7 @@ %define usb_module on %define usbhost_module off %define TIZEN_FEATURE_USBHOST_TEST off +%define TIZEN_FEATURE_TELEPHONY_MODULE off %define TIZEN_FEATURE_THERMAL_MODULE off #Just For debugging @@ -34,6 +35,7 @@ %define tzip_module on %define usbhost_module on %define TIZEN_FEATURE_USBHOST_TEST on +%define TIZEN_FEATURE_TELEPHONY_MODULE on %define TIZEN_FEATURE_THERMAL_MODULE on %endif %if "%{?profile}" == "wearable" @@ -93,6 +95,9 @@ BuildRequires: pkgconfig(minizip) BuildRequires: pkgconfig(libkmod) BuildRequires: pkgconfig(libusbg) %endif +%if %{?TIZEN_FEATURE_TELEPHONY_MODULE} == on +BuildRequires: pkgconfig(tapi) +%endif Requires: %{name}-tools = %{version}-%{release} %{?systemd_requires} @@ -183,6 +188,7 @@ Deviced library for device control (devel) -DUSB_MODULE=%{usb_module} \ -DUSBHOST_MODULE=%{usbhost_module} \ -DTIZEN_FEATURE_USBHOST_TEST=%{TIZEN_FEATURE_USBHOST_TEST} \ + -DTIZEN_FEATURE_TELEPHONY_MODULE=%{TIZEN_FEATURE_TELEPHONY_MODULE} \ -DTHERMAL_MODULE=%{TIZEN_FEATURE_THERMAL_MODULE} \ #eol diff --git a/src/power/power-handler.c b/src/power/power-handler.c index d6ba1b8..785fc06 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -62,31 +62,15 @@ static struct timeval tv_start_poweroff; -static const struct device_ops *telephony = NULL; - -static void telephony_init(void) +static int telephony_off(enum poweroff_type type) { - FIND_DEVICE_VOID(telephony, "telephony"); - _I("telephony (%d)", telephony); -} + const struct device_ops *tele; -static void telephony_start(void) -{ - telephony_init(); - device_start(telephony); -} + tele = find_device("telephony"); + if (check_default(tele)) + return -ENODEV; -static void telephony_stop(void) -{ - device_stop(telephony); -} - -static int telephony_exit(void *data) -{ - int ret; - - ret = device_exit(telephony, data); - return ret; + return device_execute(tele, &type); } static int app_privileged(pid_t pid) @@ -198,7 +182,6 @@ static void powerdown(void) /* if this fails, that's OK */ power_off = 1; - telephony_stop(); sync(); buf = getenv("PWROFF_DUR"); @@ -227,15 +210,27 @@ static void powerdown(void) #endif } -static void powerdown_ap(void *data) +void powerdown_ap(void *data) { + static int off = 0; + + if (off) + return; + off = 1; + _I("Power off"); powerdown(); reboot(RB_POWER_OFF); } -static void restart_ap(void *data) +void restart_ap(void *data) { + static int off = 0; + + if (off) + return; + off = 1; + _I("Restart"); powerdown(); reboot(RB_AUTOBOOT); @@ -269,7 +264,6 @@ static int poweroff(void) static const struct device_ops *display_device_ops = NULL; poweroff_start_animation(); - telephony_start(); FIND_DEVICE_INT(display_device_ops, "display"); @@ -277,8 +271,7 @@ static int poweroff(void) display_device_ops->exit(NULL); sync(); - ret = telephony_exit(POWER_POWEROFF); - + ret = telephony_off(POWER_OFF_DIRECT); if (ret < 0) { powerdown_ap(NULL); return 0; @@ -298,7 +291,6 @@ static int power_reboot(void) const struct device_ops *display_device_ops = NULL; poweroff_start_animation(); - telephony_start(); FIND_DEVICE_INT(display_device_ops, "display"); @@ -306,7 +298,7 @@ static int power_reboot(void) display_device_ops->exit(NULL); sync(); - ret = telephony_exit(POWER_REBOOT); + ret = telephony_off(POWER_OFF_RESTART); if (ret < 0) { restart_ap(NULL); return 0; @@ -322,7 +314,6 @@ static int booting_done(void *data) goto out; done = *(int*)data; - telephony_init(); out: return done; } @@ -351,8 +342,6 @@ static void poweroff_idler_cb(void *data) { enum poweroff_type val = (long)data; - telephony_start(); - pm_lock_internal(INTERNAL_LOCK_POWEROFF, LCD_OFF, STAY_CUR_STATE, 0); if (val == POWER_OFF_DIRECT || val == POWER_OFF_RESTART) { diff --git a/src/power/power-handler.h b/src/power/power-handler.h index b7d7c28..8040d6d 100644 --- a/src/power/power-handler.h +++ b/src/power/power-handler.h @@ -35,4 +35,7 @@ enum poweroff_type { POWER_OFF_RESTART, }; +void powerdown_ap(void *data); +void restart_ap(void *data); + #endif /* __POWER_HANDLE_H__ */ diff --git a/src/telephony/telephony.c b/src/telephony/telephony.c new file mode 100644 index 0000000..b1452ea --- /dev/null +++ b/src/telephony/telephony.c @@ -0,0 +1,137 @@ +/* + * deviced + * + * Copyright (c) 2012 - 2016 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 "core/log.h" +#include "core/common.h" +#include "core/devices.h" +#include "core/device-notifier.h" +#include "core/edbus-handler.h" +#include "power/power-handler.h" + +#define TELEPHONY_NOTI_TIMEOUT 15000 /* milliseconds */ + +static TapiHandle *tapi_handle; +static enum poweroff_type type; + +static void telephony_off(void) +{ + static int already = 0; + + if (already) + return; + + already = 1; + + switch (type) { + case POWER_OFF_RESTART: + restart_ap(NULL); + break; + case POWER_OFF_DIRECT: + default: + powerdown_ap(NULL); + break; + } +} + +static void telephony_noti_cb(TapiHandle *handle, const char *noti_id, void *data, void *user_data) +{ + int ret; + + _I("Modem Power Off"); + + if (handle) { + ret = tel_deregister_noti_event(handle, TAPI_NOTI_MODEM_POWER); + if (ret != TAPI_API_SUCCESS) + _E("Failed to unregister tapi noti event (%d)", ret); + + ret = tel_deinit(tapi_handle); + if (ret != TAPI_API_SUCCESS) + _E("Failed to deinit tapi handle (%d)", ret); + } + + telephony_off(); +} + +static void telephony_resp_cb(TapiHandle *handle, int result, void *data, void *user_data) +{ + _D("poweroff command request : %d", result); +} + +static gboolean telephony_request_timeout(gpointer data) +{ + _E("No response from Telephony"); + telephony_off(); + return G_SOURCE_REMOVE; +} + +static int telephony_poweroff(void *data) +{ + int ret; + guint id; + + type = *(enum poweroff_type *)data; + + if (!tapi_handle) { + tapi_handle = tel_init(NULL); + if (!tapi_handle) { + _E("Failed to init telephony"); + return -ENOMEM; + } + } + + ret = tel_register_noti_event(tapi_handle, + TAPI_NOTI_MODEM_POWER, telephony_noti_cb, NULL); + if (ret != TAPI_API_SUCCESS) { + _E("Failed to register tapi noti event (%d)", ret); + return (ret < 0 ? ret : -ret); + } + + ret = tel_process_power_command(tapi_handle, + TAPI_PHONE_POWER_OFF, telephony_resp_cb, NULL); + if (ret != TAPI_API_SUCCESS) { + _E("Failed to notify tapi power command response(%d)", ret); + return (ret < 0 ? ret : -ret); + } + + id = g_timeout_add(TELEPHONY_NOTI_TIMEOUT, telephony_request_timeout, NULL); + if (id == 0) { + _E("Failed to add timer for force poweroff"); + return -ENOMEM; + } + + return 0; +} + +static int telephony_execute(void *data) +{ + return telephony_poweroff(data); +} + +static const struct device_ops tel_device_ops = { + .name = "telephony", + .execute = telephony_execute, +}; + +DEVICE_OPS_REGISTER(&tel_device_ops) -- 2.7.4