From 41a137a4b4ef1d18fc518c480ddce65869229205 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 14 May 2019 14:15:15 +0900 Subject: [PATCH 01/16] Fix signature mis-match in expired_deliver_result Expected signature is 'i', but returned value is 'si'. So, fix it. Change-Id: I9e476983a7bef55dcc94fd8bd1fc83b98563bbcd Signed-off-by: lokilee73 --- plugins/iot/display/display-dbus.c | 2 +- plugins/mobile/display/display-dbus.c | 2 +- plugins/tv/display/display-dbus.c | 2 +- plugins/wearable/display/display-dbus.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/iot/display/display-dbus.c b/plugins/iot/display/display-dbus.c index 69ef153..308d665 100644 --- a/plugins/iot/display/display-dbus.c +++ b/plugins/iot/display/display-dbus.c @@ -1014,7 +1014,7 @@ static void expired_deliver_result(void *data) _E("item->invocation is null"); goto out; } - g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(si)", id, value)); + g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(i)", 0)); if (value == 2) { kill(item->pid, SIGTERM); diff --git a/plugins/mobile/display/display-dbus.c b/plugins/mobile/display/display-dbus.c index 69ef153..308d665 100644 --- a/plugins/mobile/display/display-dbus.c +++ b/plugins/mobile/display/display-dbus.c @@ -1014,7 +1014,7 @@ static void expired_deliver_result(void *data) _E("item->invocation is null"); goto out; } - g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(si)", id, value)); + g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(i)", 0)); if (value == 2) { kill(item->pid, SIGTERM); diff --git a/plugins/tv/display/display-dbus.c b/plugins/tv/display/display-dbus.c index 69ef153..308d665 100644 --- a/plugins/tv/display/display-dbus.c +++ b/plugins/tv/display/display-dbus.c @@ -1014,7 +1014,7 @@ static void expired_deliver_result(void *data) _E("item->invocation is null"); goto out; } - g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(si)", id, value)); + g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(i)", 0)); if (value == 2) { kill(item->pid, SIGTERM); diff --git a/plugins/wearable/display/display-dbus.c b/plugins/wearable/display/display-dbus.c index 69ef153..308d665 100644 --- a/plugins/wearable/display/display-dbus.c +++ b/plugins/wearable/display/display-dbus.c @@ -1014,7 +1014,7 @@ static void expired_deliver_result(void *data) _E("item->invocation is null"); goto out; } - g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(si)", id, value)); + g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(i)", 0)); if (value == 2) { kill(item->pid, SIGTERM); -- 2.7.4 From d6a3b3fe3b088edf094711e4eb1e34f82609720f Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 14 May 2019 21:29:07 +0900 Subject: [PATCH 02/16] Fix segment fault in control_handler and get_control_handler There are segment fault because of argc. Buffer size of argv is 2 or 3, but it can exceed limitation by argc. So, change conditions as below. 1. Check conditions and return -EINAL when it's not satisfied ex) if argc is 3 in dbus_control_handler if argc is 2 in dbus_get_control_handler 2. Remove argc check in control_handler and get_control_handler, because it's wrong Change-Id: I22c4c89d59deeeb5181dd7787ed9ca60ea2af50d Signed-off-by: lokilee73 --- src/control/control.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/control/control.c b/src/control/control.c index d410134..6112898 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -55,12 +55,6 @@ static int control_handler(int argc, char **argv) for (i = 0; i < argc; ++i) _I("argv[%2d]=%s", i, argv[i]); - if (argc > 5) { - _E("Invalid argument."); - errno = EINVAL; - return -1; - } - pid = atoi(argv[0]); device = atoi(argv[1]); enable = atoi(argv[2]); @@ -102,12 +96,6 @@ static int get_control_handler(int argc, char **argv) for (i = 0; i < argc; ++i) _I("argv[%2d]=%s", i, argv[i]); - if (argc > 4) { - _E("Invalid argument."); - errno = EINVAL; - return -1; - } - pid = atoi(argv[0]); device = atoi(argv[1]); _I("pid=%d device=%d", pid, device); @@ -136,9 +124,8 @@ GVariant *dbus_control_handler(GDBusConnection *conn, char *argv[3]; g_variant_get(param, "(sisss)", NULL, &argc, &argv[0], &argv[1], &argv[2]); - - if (argc < 0) { - _E("Message is invalid."); + if (argc != 3) { + _E("Invalid argument."); ret = -EINVAL; goto out; } @@ -169,8 +156,8 @@ GVariant *dbus_get_control_handler(GDBusConnection *conn, char *argv[2]; g_variant_get(param, "(siss)", NULL, &argc, &argv[0], &argv[1]); - if (argc < 0) { - _E("Message is invalid."); + if (argc != 2) { + _E("Invalid argument."); ret = -EINVAL; goto out; } -- 2.7.4 From 08666c3c9dab1d68399a0e888cf669222d09a739 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 17 May 2019 16:55:06 +0900 Subject: [PATCH 03/16] Change lcd control method from dbus-send to using internal APIs supported by dpms Change-Id: I69e62ebbc8083a40fc383d2c2f36a63d7c975ebe Signed-off-by: lokilee73 --- CMakeLists.txt | 3 + packaging/deviced.spec | 3 + plugins/iot/display/CMakeLists.txt | 7 +- plugins/iot/display/core.c | 16 +-- plugins/iot/display/device-interface.c | 56 ++------- plugins/iot/display/dpms-wayland-none.c | 100 ---------------- plugins/mobile/display/CMakeLists.txt | 7 +- plugins/mobile/display/core.c | 16 +-- plugins/mobile/display/device-interface.c | 56 ++------- plugins/mobile/display/dpms-wayland-none.c | 100 ---------------- plugins/tv/display/CMakeLists.txt | 7 +- plugins/tv/display/core.c | 15 +-- plugins/tv/display/device-interface.c | 56 ++------- plugins/tv/display/dpms-wayland-none.c | 100 ---------------- plugins/wearable/display/CMakeLists.txt | 7 +- plugins/wearable/display/core.c | 15 +-- plugins/wearable/display/device-interface.c | 56 ++------- plugins/wearable/display/dpms-wayland-none.c | 100 ---------------- src/display/device-interface.h | 4 - src/display/display-dpms.c | 173 +++++++++++++++++++++++++++ src/display/display-dpms.h | 28 +++++ systemd/deviced.service | 1 + 22 files changed, 284 insertions(+), 642 deletions(-) delete mode 100644 plugins/iot/display/dpms-wayland-none.c delete mode 100644 plugins/mobile/display/dpms-wayland-none.c delete mode 100644 plugins/tv/display/dpms-wayland-none.c delete mode 100644 plugins/wearable/display/dpms-wayland-none.c create mode 100644 src/display/display-dpms.c create mode 100644 src/display/display-dpms.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 151bf1b..a90dec1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -176,6 +176,9 @@ SET(PKG_MODULES capi-system-device libsystemd libsyscommon + wayland-client + tizen-extension-client + tizen-dpms-client ) IF(DISPLAY_MODULE STREQUAL on) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 52e7605..b895131 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -37,6 +37,9 @@ BuildRequires: pkgconfig(libkmod) BuildRequires: pkgconfig(libusbgx) BuildRequires: pkgconfig(libsyscommon) BuildRequires: pkgconfig(capi-system-device) +BuildRequires: pkgconfig(wayland-client) +BuildRequires: pkgconfig(tizen-extension-client) +BuildRequires: pkgconfig(tizen-dpms-client) Requires: %{name}-tools = %{version}-%{release} %{?systemd_requires} diff --git a/plugins/iot/display/CMakeLists.txt b/plugins/iot/display/CMakeLists.txt index 95ccb0d..206e95a 100644 --- a/plugins/iot/display/CMakeLists.txt +++ b/plugins/iot/display/CMakeLists.txt @@ -3,6 +3,8 @@ PROJECT(iot-display C) FILE(GLOB ALL_SRCS "*.c") SET(SRCS ${ALL_SRCS}) +ADD_SOURCE(${CMAKE_SOURCE_DIR}/src/display COMMON_SRCS) +SET(SRCS ${SRCS} ${COMMON_SRCS}) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/display) @@ -13,7 +15,10 @@ pkg_check_modules(libpkgs REQUIRED gio-2.0 gio-unix-2.0 libinput - capi-system-sensor) + capi-system-sensor + wayland-client + tizen-extension-client + tizen-dpms-client) FOREACH(flag ${libpkgs_CFLAGS}) SET(EXTRA_LIB_CFLAGS "${EXTRA_LIB_CFLAGS} ${flag}") diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 7f26941..fe4d69b 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -51,13 +51,13 @@ #include "core/udev.h" #include "core/list.h" #include "core/common.h" -#include "battery/battery.h" -#include "shared/plugin.h" #include "core/config-parser.h" #include "core/launch.h" #include "extcon/extcon.h" #include "power/power-handler.h" #include "dd-display.h" +#include "display/display-dpms.h" +#include "battery/battery.h" #define PM_STATE_LOG_FILE tzplatform_mkpath(TZ_SYS_ALLLOGS, "pm_state.log") #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -1456,7 +1456,6 @@ static gboolean lcd_on_expired(void *data) /* check state of lock */ ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); - if (ret > 0 && lock_state == VCONFKEY_IDLE_LOCK) return G_SOURCE_REMOVE; else if (ret < 0) @@ -2168,17 +2167,6 @@ static int display_load_config(struct parse_result *result, void *user_data) return 0; } -static bool check_wm_ready(void) -{ - if (access("/run/.wm_ready", F_OK) == 0) { - _I("Window manager is ready."); - return true; - } - - _I("Window manager is not ready."); - return false; -} - static gboolean lcd_on_wm_ready(gpointer data) { int timeout; diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index 201a33e..c4c9c7d 100755 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -36,6 +36,7 @@ #include "core/devices.h" #include "core/list.h" #include "core/common.h" +#include "display/display-dpms.h" #include "util.h" #include "device-interface.h" #include "vconf.h" @@ -73,29 +74,13 @@ static struct display_device *display_dev; static int bl_onoff(int on) { - enum display_state val; - - if (!display_dev || !display_dev->set_state) - return dpms_set_power(on); - - switch (on) { - case DPMS_ON: - val = DISPLAY_ON; - break; - case DPMS_STANDBY: - val = DISPLAY_STANDBY; - break; - case DPMS_SUSPEND: - val = DISPLAY_SUSPEND; - break; - case DPMS_OFF: - val = DISPLAY_OFF; - break; - default: + if (!dpms_is_available()) { + _E("Dpms is not available."); return -EINVAL; } - return display_dev->set_state(val); + dpms_set_state(on); + return 0; } static int bl_brt(int brightness, int delay) @@ -191,36 +176,15 @@ out: static int get_lcd_power(void) { - enum dpms_state state; - enum display_state val; - int ret; - if (ambient_get_state()) return DPMS_OFF; - if (!display_dev || !display_dev->get_state) { - ret = dpms_get_power(&state); - if (ret < 0) - return ret; - return state; - } - - ret = display_dev->get_state(&val); - if (ret < 0) - return ret; - - switch (val) { - case DISPLAY_ON: - return DPMS_ON; - case DISPLAY_STANDBY: - return DPMS_STANDBY; - case DISPLAY_SUSPEND: - return DPMS_SUSPEND; - case DISPLAY_OFF: - return DPMS_OFF; - default: + if (!dpms_is_available()) { + _E("Dpms is not available."); return -EINVAL; } + + return dpms_get_state(); } void change_brightness(int start, int end, int step) @@ -691,6 +655,7 @@ int display_service_free(void) int init_sysfs() { _init_ops(); + return 0; } @@ -700,6 +665,7 @@ int exit_sysfs(void) backlight_update(); + disconnect_interface_with_dpms(); ops = find_device("touchscreen"); if (!check_default(ops)) ops->start(NORMAL_MODE); diff --git a/plugins/iot/display/dpms-wayland-none.c b/plugins/iot/display/dpms-wayland-none.c deleted file mode 100644 index 919c144..0000000 --- a/plugins/iot/display/dpms-wayland-none.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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 "device-interface.h" -#include "util.h" -#include "core.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(GVariant *var, void *user_data, GError *err) -{ - int state; - - if (!var) { - _E("no message [%s], Cannot get pmlock check", - err->message); - return; - } - - if (!dh_get_param_from_var(var, "(i)", &state)) { - _E("no message [%s]", g_variant_get_type_string(var)); - goto out; - } - - _D("DPMS was set %d", state); - -#ifdef ENABLE_PM_LOG - switch (state) { - case DPMS_ON: - pm_history_save(PM_LOG_LCD_ON, pm_cur_state); - break; - case DPMS_OFF: - pm_history_save(PM_LOG_LCD_OFF, pm_cur_state); - break; - default: - break; - } -#endif - -out: - g_variant_unref(var); -} - -int dpms_set_power(enum dpms_state state) -{ - int ret; - - ret = dbus_handle_method_async_with_reply_var(ENLIGHTENMENT_BUS_NAME, - ENLIGHTENMENT_OBJECT_PATH, - ENLIGHTENMENT_INTERFACE_NAME, - "set", - g_variant_new("(u)", state), - dpms_set_cb, - -1, - NULL); - - if (ret < 0) - return ret; - - return 0; -} - -int dpms_get_power(enum dpms_state *state) -{ - int ret; - - if (!state) - return -EINVAL; - - ret = dbus_handle_method_sync(ENLIGHTENMENT_BUS_NAME, - ENLIGHTENMENT_OBJECT_PATH, - ENLIGHTENMENT_INTERFACE_NAME, - "get", - NULL, NULL); - if (ret < 0) - return ret; - - *state = ret; - return 0; -} diff --git a/plugins/mobile/display/CMakeLists.txt b/plugins/mobile/display/CMakeLists.txt index 7aad0f4..071f366 100644 --- a/plugins/mobile/display/CMakeLists.txt +++ b/plugins/mobile/display/CMakeLists.txt @@ -3,6 +3,8 @@ PROJECT(mobile-display C) FILE(GLOB ALL_SRCS "*.c") SET(SRCS ${ALL_SRCS}) +ADD_SOURCE(${CMAKE_SOURCE_DIR}/src/display COMMON_SRCS) +SET(SRCS ${SRCS} ${COMMON_SRCS}) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/display) @@ -13,7 +15,10 @@ pkg_check_modules(libpkgs REQUIRED gio-2.0 gio-unix-2.0 libinput - capi-system-sensor) + capi-system-sensor + wayland-client + tizen-extension-client + tizen-dpms-client) FOREACH(flag ${libpkgs_CFLAGS}) SET(EXTRA_LIB_CFLAGS "${EXTRA_LIB_CFLAGS} ${flag}") diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 7f26941..fe4d69b 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -51,13 +51,13 @@ #include "core/udev.h" #include "core/list.h" #include "core/common.h" -#include "battery/battery.h" -#include "shared/plugin.h" #include "core/config-parser.h" #include "core/launch.h" #include "extcon/extcon.h" #include "power/power-handler.h" #include "dd-display.h" +#include "display/display-dpms.h" +#include "battery/battery.h" #define PM_STATE_LOG_FILE tzplatform_mkpath(TZ_SYS_ALLLOGS, "pm_state.log") #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -1456,7 +1456,6 @@ static gboolean lcd_on_expired(void *data) /* check state of lock */ ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); - if (ret > 0 && lock_state == VCONFKEY_IDLE_LOCK) return G_SOURCE_REMOVE; else if (ret < 0) @@ -2168,17 +2167,6 @@ static int display_load_config(struct parse_result *result, void *user_data) return 0; } -static bool check_wm_ready(void) -{ - if (access("/run/.wm_ready", F_OK) == 0) { - _I("Window manager is ready."); - return true; - } - - _I("Window manager is not ready."); - return false; -} - static gboolean lcd_on_wm_ready(gpointer data) { int timeout; diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 201a33e..c4c9c7d 100755 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -36,6 +36,7 @@ #include "core/devices.h" #include "core/list.h" #include "core/common.h" +#include "display/display-dpms.h" #include "util.h" #include "device-interface.h" #include "vconf.h" @@ -73,29 +74,13 @@ static struct display_device *display_dev; static int bl_onoff(int on) { - enum display_state val; - - if (!display_dev || !display_dev->set_state) - return dpms_set_power(on); - - switch (on) { - case DPMS_ON: - val = DISPLAY_ON; - break; - case DPMS_STANDBY: - val = DISPLAY_STANDBY; - break; - case DPMS_SUSPEND: - val = DISPLAY_SUSPEND; - break; - case DPMS_OFF: - val = DISPLAY_OFF; - break; - default: + if (!dpms_is_available()) { + _E("Dpms is not available."); return -EINVAL; } - return display_dev->set_state(val); + dpms_set_state(on); + return 0; } static int bl_brt(int brightness, int delay) @@ -191,36 +176,15 @@ out: static int get_lcd_power(void) { - enum dpms_state state; - enum display_state val; - int ret; - if (ambient_get_state()) return DPMS_OFF; - if (!display_dev || !display_dev->get_state) { - ret = dpms_get_power(&state); - if (ret < 0) - return ret; - return state; - } - - ret = display_dev->get_state(&val); - if (ret < 0) - return ret; - - switch (val) { - case DISPLAY_ON: - return DPMS_ON; - case DISPLAY_STANDBY: - return DPMS_STANDBY; - case DISPLAY_SUSPEND: - return DPMS_SUSPEND; - case DISPLAY_OFF: - return DPMS_OFF; - default: + if (!dpms_is_available()) { + _E("Dpms is not available."); return -EINVAL; } + + return dpms_get_state(); } void change_brightness(int start, int end, int step) @@ -691,6 +655,7 @@ int display_service_free(void) int init_sysfs() { _init_ops(); + return 0; } @@ -700,6 +665,7 @@ int exit_sysfs(void) backlight_update(); + disconnect_interface_with_dpms(); ops = find_device("touchscreen"); if (!check_default(ops)) ops->start(NORMAL_MODE); diff --git a/plugins/mobile/display/dpms-wayland-none.c b/plugins/mobile/display/dpms-wayland-none.c deleted file mode 100644 index 919c144..0000000 --- a/plugins/mobile/display/dpms-wayland-none.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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 "device-interface.h" -#include "util.h" -#include "core.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(GVariant *var, void *user_data, GError *err) -{ - int state; - - if (!var) { - _E("no message [%s], Cannot get pmlock check", - err->message); - return; - } - - if (!dh_get_param_from_var(var, "(i)", &state)) { - _E("no message [%s]", g_variant_get_type_string(var)); - goto out; - } - - _D("DPMS was set %d", state); - -#ifdef ENABLE_PM_LOG - switch (state) { - case DPMS_ON: - pm_history_save(PM_LOG_LCD_ON, pm_cur_state); - break; - case DPMS_OFF: - pm_history_save(PM_LOG_LCD_OFF, pm_cur_state); - break; - default: - break; - } -#endif - -out: - g_variant_unref(var); -} - -int dpms_set_power(enum dpms_state state) -{ - int ret; - - ret = dbus_handle_method_async_with_reply_var(ENLIGHTENMENT_BUS_NAME, - ENLIGHTENMENT_OBJECT_PATH, - ENLIGHTENMENT_INTERFACE_NAME, - "set", - g_variant_new("(u)", state), - dpms_set_cb, - -1, - NULL); - - if (ret < 0) - return ret; - - return 0; -} - -int dpms_get_power(enum dpms_state *state) -{ - int ret; - - if (!state) - return -EINVAL; - - ret = dbus_handle_method_sync(ENLIGHTENMENT_BUS_NAME, - ENLIGHTENMENT_OBJECT_PATH, - ENLIGHTENMENT_INTERFACE_NAME, - "get", - NULL, NULL); - if (ret < 0) - return ret; - - *state = ret; - return 0; -} diff --git a/plugins/tv/display/CMakeLists.txt b/plugins/tv/display/CMakeLists.txt index 317ab00..f996126 100644 --- a/plugins/tv/display/CMakeLists.txt +++ b/plugins/tv/display/CMakeLists.txt @@ -3,6 +3,8 @@ PROJECT(tv-display C) FILE(GLOB ALL_SRCS "*.c") SET(SRCS ${ALL_SRCS}) +ADD_SOURCE(${CMAKE_SOURCE_DIR}/src/display COMMON_SRCS) +SET(SRCS ${SRCS} ${COMMON_SRCS}) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/display) @@ -13,7 +15,10 @@ pkg_check_modules(libpkgs REQUIRED gio-2.0 gio-unix-2.0 libinput - capi-system-sensor) + capi-system-sensor + wayland-client + tizen-extension-client + tizen-dpms-client) FOREACH(flag ${libpkgs_CFLAGS}) SET(EXTRA_LIB_CFLAGS "${EXTRA_LIB_CFLAGS} ${flag}") diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 95ebe4f..5bf09f7 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -51,13 +51,13 @@ #include "core/udev.h" #include "core/list.h" #include "core/common.h" -#include "battery/battery.h" -#include "shared/plugin.h" #include "core/config-parser.h" #include "core/launch.h" #include "extcon/extcon.h" #include "power/power-handler.h" #include "dd-display.h" +#include "display/display-dpms.h" +#include "battery/battery.h" #define PM_STATE_LOG_FILE tzplatform_mkpath(TZ_SYS_ALLLOGS, "pm_state.log") #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -2169,17 +2169,6 @@ static int display_load_config(struct parse_result *result, void *user_data) return 0; } -static bool check_wm_ready(void) -{ - if (access("/run/.wm_ready", F_OK) == 0) { - _I("Window manager is ready."); - return true; - } - - _I("Window manager is not ready."); - return false; -} - static gboolean lcd_on_wm_ready(gpointer data) { int timeout; diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 201a33e..c4c9c7d 100755 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -36,6 +36,7 @@ #include "core/devices.h" #include "core/list.h" #include "core/common.h" +#include "display/display-dpms.h" #include "util.h" #include "device-interface.h" #include "vconf.h" @@ -73,29 +74,13 @@ static struct display_device *display_dev; static int bl_onoff(int on) { - enum display_state val; - - if (!display_dev || !display_dev->set_state) - return dpms_set_power(on); - - switch (on) { - case DPMS_ON: - val = DISPLAY_ON; - break; - case DPMS_STANDBY: - val = DISPLAY_STANDBY; - break; - case DPMS_SUSPEND: - val = DISPLAY_SUSPEND; - break; - case DPMS_OFF: - val = DISPLAY_OFF; - break; - default: + if (!dpms_is_available()) { + _E("Dpms is not available."); return -EINVAL; } - return display_dev->set_state(val); + dpms_set_state(on); + return 0; } static int bl_brt(int brightness, int delay) @@ -191,36 +176,15 @@ out: static int get_lcd_power(void) { - enum dpms_state state; - enum display_state val; - int ret; - if (ambient_get_state()) return DPMS_OFF; - if (!display_dev || !display_dev->get_state) { - ret = dpms_get_power(&state); - if (ret < 0) - return ret; - return state; - } - - ret = display_dev->get_state(&val); - if (ret < 0) - return ret; - - switch (val) { - case DISPLAY_ON: - return DPMS_ON; - case DISPLAY_STANDBY: - return DPMS_STANDBY; - case DISPLAY_SUSPEND: - return DPMS_SUSPEND; - case DISPLAY_OFF: - return DPMS_OFF; - default: + if (!dpms_is_available()) { + _E("Dpms is not available."); return -EINVAL; } + + return dpms_get_state(); } void change_brightness(int start, int end, int step) @@ -691,6 +655,7 @@ int display_service_free(void) int init_sysfs() { _init_ops(); + return 0; } @@ -700,6 +665,7 @@ int exit_sysfs(void) backlight_update(); + disconnect_interface_with_dpms(); ops = find_device("touchscreen"); if (!check_default(ops)) ops->start(NORMAL_MODE); diff --git a/plugins/tv/display/dpms-wayland-none.c b/plugins/tv/display/dpms-wayland-none.c deleted file mode 100644 index 919c144..0000000 --- a/plugins/tv/display/dpms-wayland-none.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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 "device-interface.h" -#include "util.h" -#include "core.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(GVariant *var, void *user_data, GError *err) -{ - int state; - - if (!var) { - _E("no message [%s], Cannot get pmlock check", - err->message); - return; - } - - if (!dh_get_param_from_var(var, "(i)", &state)) { - _E("no message [%s]", g_variant_get_type_string(var)); - goto out; - } - - _D("DPMS was set %d", state); - -#ifdef ENABLE_PM_LOG - switch (state) { - case DPMS_ON: - pm_history_save(PM_LOG_LCD_ON, pm_cur_state); - break; - case DPMS_OFF: - pm_history_save(PM_LOG_LCD_OFF, pm_cur_state); - break; - default: - break; - } -#endif - -out: - g_variant_unref(var); -} - -int dpms_set_power(enum dpms_state state) -{ - int ret; - - ret = dbus_handle_method_async_with_reply_var(ENLIGHTENMENT_BUS_NAME, - ENLIGHTENMENT_OBJECT_PATH, - ENLIGHTENMENT_INTERFACE_NAME, - "set", - g_variant_new("(u)", state), - dpms_set_cb, - -1, - NULL); - - if (ret < 0) - return ret; - - return 0; -} - -int dpms_get_power(enum dpms_state *state) -{ - int ret; - - if (!state) - return -EINVAL; - - ret = dbus_handle_method_sync(ENLIGHTENMENT_BUS_NAME, - ENLIGHTENMENT_OBJECT_PATH, - ENLIGHTENMENT_INTERFACE_NAME, - "get", - NULL, NULL); - if (ret < 0) - return ret; - - *state = ret; - return 0; -} diff --git a/plugins/wearable/display/CMakeLists.txt b/plugins/wearable/display/CMakeLists.txt index 0dcccb1..391ec59 100644 --- a/plugins/wearable/display/CMakeLists.txt +++ b/plugins/wearable/display/CMakeLists.txt @@ -3,6 +3,8 @@ PROJECT(wearable-display C) FILE(GLOB ALL_SRCS "*.c") SET(SRCS ${ALL_SRCS}) +ADD_SOURCE(${CMAKE_SOURCE_DIR}/src/display COMMON_SRCS) +SET(SRCS ${SRCS} ${COMMON_SRCS}) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/display) @@ -13,7 +15,10 @@ pkg_check_modules(libpkgs REQUIRED gio-2.0 gio-unix-2.0 libinput - capi-system-sensor) + capi-system-sensor + wayland-client + tizen-extension-client + tizen-dpms-client) FOREACH(flag ${libpkgs_CFLAGS}) SET(EXTRA_LIB_CFLAGS "${EXTRA_LIB_CFLAGS} ${flag}") diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 4fe0fc7..4823071 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -51,13 +51,13 @@ #include "core/udev.h" #include "core/list.h" #include "core/common.h" -#include "battery/battery.h" -#include "shared/plugin.h" #include "core/config-parser.h" #include "core/launch.h" #include "extcon/extcon.h" #include "power/power-handler.h" #include "dd-display.h" +#include "display/display-dpms.h" +#include "battery/battery.h" #define PM_STATE_LOG_FILE tzplatform_mkpath(TZ_SYS_ALLLOGS, "pm_state.log") #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -2171,17 +2171,6 @@ static int display_load_config(struct parse_result *result, void *user_data) return 0; } -static bool check_wm_ready(void) -{ - if (access("/run/.wm_ready", F_OK) == 0) { - _I("Window manager is ready."); - return true; - } - - _I("Window manager is not ready."); - return false; -} - static gboolean lcd_on_wm_ready(gpointer data) { int timeout; diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index a362b6e..69fd7d5 100755 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -36,6 +36,7 @@ #include "core/devices.h" #include "core/list.h" #include "core/common.h" +#include "display/display-dpms.h" #include "util.h" #include "device-interface.h" #include "vconf.h" @@ -73,29 +74,13 @@ static struct display_device *display_dev; static int bl_onoff(int on) { - enum display_state val; - - if (!display_dev || !display_dev->set_state) - return dpms_set_power(on); - - switch (on) { - case DPMS_ON: - val = DISPLAY_ON; - break; - case DPMS_STANDBY: - val = DISPLAY_STANDBY; - break; - case DPMS_SUSPEND: - val = DISPLAY_SUSPEND; - break; - case DPMS_OFF: - val = DISPLAY_OFF; - break; - default: + if (!dpms_is_available()) { + _E("Dpms is not available."); return -EINVAL; } - return display_dev->set_state(val); + dpms_set_state(on); + return 0; } static int bl_brt(int brightness, int delay) @@ -191,36 +176,15 @@ out: static int get_lcd_power(void) { - enum dpms_state state; - enum display_state val; - int ret; - if (ambient_get_state()) return DPMS_OFF; - if (!display_dev || !display_dev->get_state) { - ret = dpms_get_power(&state); - if (ret < 0) - return ret; - return state; - } - - ret = display_dev->get_state(&val); - if (ret < 0) - return ret; - - switch (val) { - case DISPLAY_ON: - return DPMS_ON; - case DISPLAY_STANDBY: - return DPMS_STANDBY; - case DISPLAY_SUSPEND: - return DPMS_SUSPEND; - case DISPLAY_OFF: - return DPMS_OFF; - default: + if (!dpms_is_available()) { + _E("Dpms is not available."); return -EINVAL; } + + return dpms_get_state(); } void change_brightness(int start, int end, int step) @@ -732,6 +696,7 @@ int display_service_free(void) int init_sysfs() { _init_ops(); + return 0; } @@ -741,6 +706,7 @@ int exit_sysfs(void) backlight_update(); + disconnect_interface_with_dpms(); ops = find_device("touchscreen"); if (!check_default(ops)) ops->start(NORMAL_MODE); diff --git a/plugins/wearable/display/dpms-wayland-none.c b/plugins/wearable/display/dpms-wayland-none.c deleted file mode 100644 index 919c144..0000000 --- a/plugins/wearable/display/dpms-wayland-none.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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 "device-interface.h" -#include "util.h" -#include "core.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(GVariant *var, void *user_data, GError *err) -{ - int state; - - if (!var) { - _E("no message [%s], Cannot get pmlock check", - err->message); - return; - } - - if (!dh_get_param_from_var(var, "(i)", &state)) { - _E("no message [%s]", g_variant_get_type_string(var)); - goto out; - } - - _D("DPMS was set %d", state); - -#ifdef ENABLE_PM_LOG - switch (state) { - case DPMS_ON: - pm_history_save(PM_LOG_LCD_ON, pm_cur_state); - break; - case DPMS_OFF: - pm_history_save(PM_LOG_LCD_OFF, pm_cur_state); - break; - default: - break; - } -#endif - -out: - g_variant_unref(var); -} - -int dpms_set_power(enum dpms_state state) -{ - int ret; - - ret = dbus_handle_method_async_with_reply_var(ENLIGHTENMENT_BUS_NAME, - ENLIGHTENMENT_OBJECT_PATH, - ENLIGHTENMENT_INTERFACE_NAME, - "set", - g_variant_new("(u)", state), - dpms_set_cb, - -1, - NULL); - - if (ret < 0) - return ret; - - return 0; -} - -int dpms_get_power(enum dpms_state *state) -{ - int ret; - - if (!state) - return -EINVAL; - - ret = dbus_handle_method_sync(ENLIGHTENMENT_BUS_NAME, - ENLIGHTENMENT_OBJECT_PATH, - ENLIGHTENMENT_INTERFACE_NAME, - "get", - NULL, NULL); - if (ret < 0) - return ret; - - *state = ret; - return 0; -} diff --git a/src/display/device-interface.h b/src/display/device-interface.h index b277c2d..81e8150 100644 --- a/src/display/device-interface.h +++ b/src/display/device-interface.h @@ -98,9 +98,5 @@ enum dpms_state { DPMS_SUSPEND, /* Blanked, lower power */ DPMS_OFF, /* Shut off, awaiting activity */ }; - -int dpms_set_power(enum dpms_state state); -int dpms_get_power(enum dpms_state *state); - #endif diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c new file mode 100644 index 0000000..37f5d1b --- /dev/null +++ b/src/display/display-dpms.c @@ -0,0 +1,173 @@ + /* + * deviced + * + * Copyright (c) 2019 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. + */ + +#include +#include +#include +#include +#include "core/log.h" +#include "display/util.h" +#include +#include +#include + +struct wl_display *display; +struct wl_output *wl_out; +struct tizen_dpms_manager *tz_dpms_mng = NULL; +int lcd_state = -1; +bool wm_is_ready; + +bool check_wm_ready(void) +{ + if (access("/run/.wm_ready", F_OK) == 0) { + _I("Window manager is ready."); + wm_is_ready = true; + return true; + } + + _I("Window manager is not ready."); + return false; +} + +void disconnect_interface_with_dpms(void) +{ + if (tz_dpms_mng) { + tizen_dpms_manager_destroy(tz_dpms_mng); + tz_dpms_mng = NULL; + } + + if (wl_out) { + wl_output_destroy(wl_out); + wl_out = NULL; + } + + if (display) { + wl_display_disconnect(display); + display = NULL; + } +} + +static void dpms_handle_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error) +{ + _D("dpms_state_cb - mode:%d, error:%d", mode, error); + lcd_state = mode; +} + +static const struct tizen_dpms_manager_listener dpms_listener = { + dpms_handle_state +}; + +static void handle_global(void *data, struct wl_registry *registry, + uint32_t name, const char *interface, uint32_t version) +{ + if (strcmp(interface, "wl_output") == 0) { + wl_out = wl_registry_bind(registry, name, &wl_output_interface, 2); + if (!wl_out) { + _E("Handle wl_output bind failed."); + disconnect_interface_with_dpms(); + } + _D("Get wl_output."); + } else if (strcmp(interface, "tizen_dpms_manager") == 0) { + tz_dpms_mng = wl_registry_bind(registry, name, &tizen_dpms_manager_interface, 1); + if (!tz_dpms_mng) { + _E("Handle tizen_dpms_manager bind failed."); + disconnect_interface_with_dpms(); + } + tizen_dpms_manager_add_listener(tz_dpms_mng, &dpms_listener, NULL); + + _D("Get dpms manager."); + } +} + +static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) +{ + +} + +static const struct wl_registry_listener registry_listener = { + handle_global, + handle_global_remove +}; + +bool connect_interface_with_dpms(void) +{ + struct wl_registry *registry = NULL; + + display = wl_display_connect(NULL); + if (display == NULL) { + _E("Display is NULL."); + goto error; + } + + registry = wl_display_get_registry(display); + if (registry == NULL) { + _E("Registry is NULL."); + goto error; + } + + wl_registry_add_listener(registry, ®istry_listener, NULL); + wl_display_roundtrip(display); + + if (!wl_out || !tz_dpms_mng) { + _E("Roundtrip failed."); + goto error; + } + + wl_registry_destroy(registry); + _D("Setup with dpms is done."); + return true; + +error: + if (registry) + wl_registry_destroy(registry); + disconnect_interface_with_dpms(); + return false; +} + +bool dpms_is_available(void) +{ + static bool dpms_connected; + + /* Check window manager */ + if (!wm_is_ready) { + _E("Window manager is not ready"); + return false; + } + /* Try to connect interface with dpms, because window manager is ready */ + if (!dpms_connected) { + _D("call connect_interface_with_dpms()"); + dpms_connected = connect_interface_with_dpms(); + return dpms_connected; + } + + return true; +} + +void dpms_set_state(int on) +{ + tizen_dpms_manager_set_dpms(tz_dpms_mng, wl_out, on); + wl_display_roundtrip(display); +} + +int dpms_get_state(void) +{ + tizen_dpms_manager_get_dpms(tz_dpms_mng, wl_out); + wl_display_roundtrip(display); + + return lcd_state; +} diff --git a/src/display/display-dpms.h b/src/display/display-dpms.h new file mode 100644 index 0000000..3b4e2ae --- /dev/null +++ b/src/display/display-dpms.h @@ -0,0 +1,28 @@ + /* + * deviced + * + * Copyright (c) 2019 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 __DISPLAY_DPMS_H__ +#define __DISPLAY_DPMS_H__ + +bool check_wm_ready(void); +bool dpms_is_available(void); +bool connect_interface_with_dpms(void); +void disconnect_interface_with_dpms(void); +void dpms_set_state(int on); +int dpms_get_state(void); +#endif /* __DISPLAY_DPMS_H__ */ diff --git a/systemd/deviced.service b/systemd/deviced.service index 5d5ce63..3a286d9 100644 --- a/systemd/deviced.service +++ b/systemd/deviced.service @@ -4,6 +4,7 @@ Description=System device daemon [Service] Type=notify SmackProcessLabel=System::Privileged +Environment=XDG_RUNTIME_DIR=/run ExecStart=/usr/bin/deviced Restart=always RestartSec=0 -- 2.7.4 From fe795aab3a42407e858bcaf90f9785994c91d276 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 22 May 2019 18:23:29 +0900 Subject: [PATCH 04/16] Move same files in each profile to display folder Change-Id: I8dac3442da66e23dfb3ce53b925c2af45bb8395d Signed-off-by: lokilee73 --- plugins/iot/display/ambient-mode.c | 210 ---- plugins/iot/display/auto-brightness.c | 681 ------------ plugins/iot/display/display-actor.c | 102 -- plugins/iot/display/display-dbus.c | 1168 --------------------- plugins/iot/display/display-ops.c | 74 -- plugins/iot/display/input.c | 224 ---- plugins/iot/display/lock-detector.c | 232 ---- plugins/iot/display/poll.c | 174 --- plugins/iot/display/setting.c | 271 ----- plugins/mobile/display/ambient-mode.c | 210 ---- plugins/mobile/display/display-actor.c | 102 -- plugins/mobile/display/display-dbus.c | 1168 --------------------- plugins/mobile/display/display-ops.c | 74 -- plugins/mobile/display/input.c | 224 ---- plugins/mobile/display/lock-detector.c | 232 ---- plugins/mobile/display/poll.c | 174 --- plugins/mobile/display/setting.c | 271 ----- plugins/tv/display/ambient-mode.c | 210 ---- plugins/tv/display/auto-brightness.c | 682 ------------ plugins/tv/display/display-actor.c | 102 -- plugins/tv/display/display-dbus.c | 1168 --------------------- plugins/tv/display/display-ops.c | 74 -- plugins/tv/display/input.c | 224 ---- plugins/tv/display/lock-detector.c | 232 ---- plugins/tv/display/poll.c | 174 --- plugins/tv/display/setting.c | 271 ----- plugins/wearable/display/auto-brightness.c | 681 ------------ {plugins/wearable => src}/display/ambient-mode.c | 0 {plugins/mobile => src}/display/auto-brightness.c | 0 {plugins/wearable => src}/display/display-actor.c | 0 {plugins/wearable => src}/display/display-dbus.c | 0 {plugins/wearable => src}/display/display-ops.c | 0 {plugins/wearable => src}/display/input.c | 0 {plugins/wearable => src}/display/lock-detector.c | 0 {plugins/wearable => src}/display/poll.c | 0 {plugins/wearable => src}/display/setting.c | 0 36 files changed, 9409 deletions(-) delete mode 100644 plugins/iot/display/ambient-mode.c delete mode 100644 plugins/iot/display/auto-brightness.c delete mode 100644 plugins/iot/display/display-actor.c delete mode 100644 plugins/iot/display/display-dbus.c delete mode 100644 plugins/iot/display/display-ops.c delete mode 100644 plugins/iot/display/input.c delete mode 100644 plugins/iot/display/lock-detector.c delete mode 100644 plugins/iot/display/poll.c delete mode 100644 plugins/iot/display/setting.c delete mode 100644 plugins/mobile/display/ambient-mode.c delete mode 100644 plugins/mobile/display/display-actor.c delete mode 100644 plugins/mobile/display/display-dbus.c delete mode 100644 plugins/mobile/display/display-ops.c delete mode 100644 plugins/mobile/display/input.c delete mode 100644 plugins/mobile/display/lock-detector.c delete mode 100644 plugins/mobile/display/poll.c delete mode 100644 plugins/mobile/display/setting.c delete mode 100644 plugins/tv/display/ambient-mode.c delete mode 100644 plugins/tv/display/auto-brightness.c delete mode 100644 plugins/tv/display/display-actor.c delete mode 100644 plugins/tv/display/display-dbus.c delete mode 100644 plugins/tv/display/display-ops.c delete mode 100644 plugins/tv/display/input.c delete mode 100644 plugins/tv/display/lock-detector.c delete mode 100644 plugins/tv/display/poll.c delete mode 100644 plugins/tv/display/setting.c delete mode 100644 plugins/wearable/display/auto-brightness.c rename {plugins/wearable => src}/display/ambient-mode.c (100%) rename {plugins/mobile => src}/display/auto-brightness.c (100%) rename {plugins/wearable => src}/display/display-actor.c (100%) rename {plugins/wearable => src}/display/display-dbus.c (100%) rename {plugins/wearable => src}/display/display-ops.c (100%) rename {plugins/wearable => src}/display/input.c (100%) rename {plugins/wearable => src}/display/lock-detector.c (100%) rename {plugins/wearable => src}/display/poll.c (100%) rename {plugins/wearable => src}/display/setting.c (100%) diff --git a/plugins/iot/display/ambient-mode.c b/plugins/iot/display/ambient-mode.c deleted file mode 100644 index b15fd56..0000000 --- a/plugins/iot/display/ambient-mode.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2017 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 "util.h" -#include "core.h" -#include "display-ops.h" -#include "core/device-notifier.h" -#include "core/devices.h" - -#define ON "on" -#define OFF "off" - -#define SIGNAL_AMBIENT_MODE "AmbientMode" -#define CLOCK_START "clockstart" -#define CLOCK_END "clockend" -#define TIMEOUT_NONE (-1) -#define AMBIENT_CLOCK_WAITING_TIME 5000 /* ms */ - -static int ambient_state; -static pid_t ambient_pid; /* Ambient Clock pid */ -static int ambient_condition; -static unsigned int update_count; - -void broadcast_ambient_state(int state) -{ - int ret; - - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, - DEVICED_INTERFACE_DISPLAY, - SIGNAL_AMBIENT_MODE, - g_variant_new("(i)", (state == 0 ? 0 : 1))); - if (ret < 0) - _E("Failed to send dbus signal(%s)", SIGNAL_AMBIENT_MODE); -} - -int ambient_get_condition(void) -{ - return ambient_condition; -} - -int ambient_get_state(void) -{ - return ambient_state; -} - -static void ambient_set_condition(keynode_t *key_nodes, void *data) -{ - int state; - - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - - ambient_condition = vconf_keynode_get_bool(key_nodes); - _I("Ambient mode condition is %d.", ambient_condition); - - state = (ambient_condition == 0 ? 0 : 1); - device_notify(DEVICE_NOTIFIER_DISPLAY_AMBIENT_CONDITION, (void *)&state); - - set_dim_state(state); -} - -int ambient_set_state(int on) -{ - if (!ambient_condition) - return 0; - - broadcast_ambient_state(on); - - update_count = 0; - - if (!on) - ambient_pid = 0; - - _D("AMBIENT is %s.", (on ? ON : OFF)); - - ambient_state = on; - - device_notify(DEVICE_NOTIFIER_DISPLAY_AMBIENT_STATE, (void *)&ambient_state); - - return 0; -} - -void ambient_check_invalid_state(pid_t pid) -{ - if (pid != INTERNAL_LOCK_AMBIENT) - return; - - if (backlight_ops.get_lcd_power() == DPMS_OFF) - return; - - if (is_emulator()) { - /* In emulator, deviced does not turn off the display. */ - if (backlight_ops.get_lcd_power() == DPMS_ON) - return; - } - - if (ambient_get_state() == false) - return; - - _E("Invalid state. Ambient state is change to off."); - - /* If lcd_power is on and ambient state is true - * when pm state is changed to sleep, - * deviced doesn't get the clock signal. - * deviced just turns off lcd in this case. */ - - ambient_set_state(false); - backlight_ops.off(NORMAL_MODE); -} - -static void start_clock(void) -{ - if (pm_cur_state == S_NORMAL || - pm_cur_state == S_LCDDIM || - ambient_state == false) - return; - - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, STAY_CUR_STATE, - AMBIENT_CLOCK_WAITING_TIME); -} - -static void end_clock(pid_t pid) -{ - if (pm_cur_state == S_NORMAL || - pm_cur_state == S_LCDDIM || - ambient_state == false) - return; - - if (update_count == 0) - broadcast_lcd_off_late(LCD_OFF_LATE_MODE); - - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, PM_SLEEP_MARGIN); - - update_count++; - if (update_count == UINT_MAX) - update_count = 1; - ambient_pid = pid; - - _I("Enter real ambient state by process(%d).", - ambient_pid); -} - -int ambient_set_screen(char *screen, pid_t pid) -{ - if (!screen) - return -EINVAL; - - if (!strncmp(screen, CLOCK_START, strlen(CLOCK_START))) - start_clock(); - else if (!strncmp(screen, CLOCK_END, strlen(CLOCK_END))) - end_clock(pid); - - return 0; -} - -static void ambient_init(void *data) -{ - int ret; - - ret = vconf_get_bool(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - &ambient_condition); - if (ret < 0) { - _E("Failed to get vconf value for ambient mode: %d", vconf_get_ext_errno()); - ambient_condition = false; - } - _I("Ambient mode condition is %d.", ambient_condition); - - vconf_notify_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - ambient_set_condition, NULL); -} - -static void ambient_exit(void *data) -{ - ambient_set_state(false); - vconf_ignore_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - ambient_set_condition); -} - -static const struct display_ops ambient_ops = { - .name = "ambient", - .init = ambient_init, - .exit = ambient_exit, -}; - -DISPLAY_OPS_REGISTER(&ambient_ops) - diff --git a/plugins/iot/display/auto-brightness.c b/plugins/iot/display/auto-brightness.c deleted file mode 100644 index 88ff66a..0000000 --- a/plugins/iot/display/auto-brightness.c +++ /dev/null @@ -1,681 +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 "util.h" -#include "core.h" -#include "display-ops.h" -#include "device-node.h" -#include "setting.h" -#include "core/device-notifier.h" -#include "core/config-parser.h" - -#define METHOD_CHECK_SUPPORTED "CheckSupported" - -#define DISP_FORCE_SHIFT 12 -#define DISP_FORCE_CMD(prop, force) (((force) << DISP_FORCE_SHIFT) | prop) - -#define SAMPLING_INTERVAL 1 /* 1 sec */ -#define MAX_SAMPLING_COUNT 3 -#define MAX_FAULT 5 -#define DEFAULT_AUTOMATIC_BRT 5 -#define AUTOMATIC_DEVIDE_VAL 10 -#define AUTOMATIC_DELAY_TIME 500 /* 0.5 sec */ - -#define RADIAN_VALUE (57.2957) -#define ROTATION_90 90 -#define WORKING_ANGLE_MIN 0 -#define WORKING_ANGLE_MAX 20 - -#define BOARD_CONF_FILE "/etc/deviced/display.conf" - -#define ON_LUX -1 -#define OFF_LUX -1 -#define ON_COUNT 1 -#define OFF_COUNT 1 - -static int (*_default_action) (int); -static guint alc_timeout_id = 0; -static guint update_timeout; -static sensor_listener_h light_listener; -static sensor_listener_h accel_listener; -static int fault_count; -static int automatic_brt = DEFAULT_AUTOMATIC_BRT; -static int min_brightness = PM_MIN_BRIGHTNESS; -static char *min_brightness_name = 0; - -/* light sensor */ -static float lmax, lmin; - -static bool update_working_position(void) -{ - sensor_event_s data; - int ret; - float x, y, z, pitch, realg; - - if (!display_conf.accel_sensor_on) - return false; - - ret = sensor_listener_read_data(accel_listener, &data); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get accelerometer data: %d", ret); - return true; - } - - x = data.values[0]; - y = data.values[1]; - z = data.values[2]; - - realg = (float)sqrt((x * x) + (y * y) + (z * z)); - pitch = ROTATION_90 - abs((int) (asin(z / realg) * RADIAN_VALUE)); - - _D("Accel data x=%f y=%f z=%f pitch=%f", x, y, z, pitch); - - if (pitch >= WORKING_ANGLE_MIN && pitch <= WORKING_ANGLE_MAX) - return true; - return false; -} - -static void alc_set_brightness(int setting, int value, float light) -{ - static float old; - int position, tmp_value = 0, ret; - - ret = backlight_ops.get_brightness(&tmp_value); - if (ret < 0) { - _E("Failed to get display brightness."); - return; - } - - if (value < min_brightness) - value = min_brightness; - - if (tmp_value != value) { - if (!setting && min_brightness == PM_MIN_BRIGHTNESS && - display_conf.accel_sensor_on == true) { - position = update_working_position(); - if (!position && (old > light)) { - _D("It's not working position, " - "LCD isn't getting dark."); - return; - } - } - int diff, step; - - diff = value - tmp_value; - if (abs(diff) < display_conf.brightness_change_step) - step = (diff > 0 ? 1 : -1); - else - step = (int)ceil(diff / - (float)display_conf.brightness_change_step); - - _D("%d", step); - while (tmp_value != value) { - if (step == 0) break; - - tmp_value += step; - if ((step > 0 && tmp_value > value) || - (step < 0 && tmp_value < value)) - tmp_value = value; - - backlight_ops.set_default_brt(tmp_value); - backlight_ops.update(); - } - _I("Load light data(%f). auto brt=%d min brightness=%d " - "brightness=%d", light, automatic_brt, min_brightness, value); - old = light; - } -} - -static bool check_brightness_changed(int value) -{ - int i; - static int values[MAX_SAMPLING_COUNT], count = 0; - - if (count >= MAX_SAMPLING_COUNT || count < 0) - count = 0; - - values[count++] = value; - - for (i = 0; i < MAX_SAMPLING_COUNT - 1; i++) - if (values[i] != values[i+1]) - return false; - return true; -} - -static bool alc_update_brt(bool setting) -{ - int value = 0; - int ret = -1; - sensor_event_s light_data; - int index; - float light; - - ret = sensor_listener_read_data(light_listener, &light_data); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to read light sensor data: %d", ret); - goto out; - } - - index = light_data.value_count - 1; - if (index < 0 || light_data.values[index] < 0) { - _E("Invalid light sensor data."); - goto out; - } - - light = light_data.values[index]; - ret = backlight_ops.get_brightness_by_light_sensor( - lmax, lmin, light, &value); - if (ret == -ENOTSUP) { - _E("Not supported to handle the light data."); - goto out; - } - - if (ret < 0 || value < PM_MIN_BRIGHTNESS || value > PM_MAX_BRIGHTNESS) { - _E("Failed to load light data. light=%f value=%d: %d", light, value, ret); - goto out; - } - - fault_count = 0; - - if (display_conf.continuous_sampling && - !check_brightness_changed(value) && - !setting) - return true; - - alc_set_brightness(setting, value, light); - - return true; - -out: - fault_count++; - - if ((fault_count > MAX_FAULT) && !(pm_status_flag & PWROFF_FLAG)) { - if (alc_timeout_id) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - SETTING_BRIGHTNESS_AUTOMATIC_OFF); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - _E("Fault counts is over %d, disable automatic brightness.", MAX_FAULT); - return false; - } - return true; -} - -static gboolean alc_handler(void *data) -{ - if (pm_cur_state != S_NORMAL) { - if (alc_timeout_id > 0) - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - return G_SOURCE_REMOVE; - } - - if (!alc_update_brt(false)) - return G_SOURCE_REMOVE; - - if (alc_timeout_id != 0) - return G_SOURCE_CONTINUE; - - return G_SOURCE_REMOVE; -} - -static int alc_action(int timeout) -{ - /* sampling timer add */ - if (alc_timeout_id == 0 && !(pm_status_flag & PWRSV_FLAG)) { - display_info.update_auto_brightness(true); - - alc_timeout_id = - g_timeout_add_seconds(display_conf.lightsensor_interval, - alc_handler, NULL); - } - - if (_default_action != NULL) - return _default_action(timeout); - - /* unreachable code */ - return -1; -} - -static int connect_sensor(void) -{ - int ret; - sensor_h sensor; - sensor_h *list = NULL; - int cnt = 0; - - _I("Connect with sensor fw."); - /* light sensor */ - ret = sensor_get_sensor_list(SENSOR_LIGHT, &list, &cnt); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor list: %d", ret); - goto error; - } - - /* TODO - * Sensor apis will be fixed - * to provide which sensor is effective among sensors */ - if (cnt == 3) /* three light sensors exist */ - sensor = list[2]; - else - sensor = list[0]; - - free(list); - - ret = sensor_get_min_range(sensor, &lmin); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor min range: %d", ret); - goto error; - } - ret = sensor_get_max_range(sensor, &lmax); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor max range: %d", ret); - goto error; - } - _I("Light sensor min=%f max=%f", lmin, lmax); - - ret = sensor_create_listener(sensor, &light_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to create listener(light)."); - goto error; - } - sensor_listener_set_option(light_listener, SENSOR_OPTION_ALWAYS_ON); - ret = sensor_listener_start(light_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to start light sensor."); - sensor_destroy_listener(light_listener); - light_listener = 0; - goto error; - } - - if (!display_conf.accel_sensor_on) - goto success; - - /* accelerometer sensor */ - ret = sensor_get_default_sensor(SENSOR_ACCELEROMETER, &sensor); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get default accel sensor."); - goto error; - } - ret = sensor_create_listener(&sensor, &accel_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to create listener(accel)."); - goto error; - } - sensor_listener_set_option(accel_listener, SENSOR_OPTION_ALWAYS_ON); - ret = sensor_listener_start(accel_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to start accel sensor."); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - goto error; - } - -success: - fault_count = 0; - return 0; - -error: - if (light_listener > 0) { - sensor_listener_stop(light_listener); - sensor_destroy_listener(light_listener); - light_listener = 0; - } - if (display_conf.accel_sensor_on && accel_listener > 0) { - sensor_listener_stop(accel_listener); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - } - return -EIO; -} - -static int disconnect_sensor(void) -{ - _I("Disconnect with sensor fw."); - /* light sensor*/ - if (light_listener > 0) { - sensor_listener_stop(light_listener); - sensor_destroy_listener(light_listener); - light_listener = 0; - } - - /* accelerometer sensor*/ - if (display_conf.accel_sensor_on && accel_listener > 0) { - sensor_listener_stop(accel_listener); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - } - - if (_default_action != NULL) { - states[S_NORMAL].action = _default_action; - _default_action = NULL; - } - if (alc_timeout_id > 0) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - - return 0; -} - -void set_brightness_changed_state(void) -{ - if (pm_status_flag & PWRSV_FLAG) { - pm_status_flag |= BRTCH_FLAG; - _D("Brightness changed in low battery," - "escape dim state (light)."); - } -} - -static int set_autobrightness_state(int status) -{ - int ret = -1; - int brt = -1; - int default_brt = -1; - - if (status == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - if (connect_sensor() < 0) - return -1; - - /* escape dim state if it's in low battery.*/ - set_brightness_changed_state(); - - /* change alc action func */ - if (_default_action == NULL) - _default_action = states[S_NORMAL].action; - states[S_NORMAL].action = alc_action; - - display_info.update_auto_brightness(true); - - alc_timeout_id = - g_timeout_add_seconds(display_conf.lightsensor_interval, - alc_handler, NULL); - } else if (status == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) { - _I("Auto brightness paused."); - disconnect_sensor(); - } else { - disconnect_sensor(); - /* escape dim state if it's in low battery.*/ - set_brightness_changed_state(); - - ret = get_setting_brightness(&default_brt); - if (ret != 0 || (default_brt < PM_MIN_BRIGHTNESS || default_brt > PM_MAX_BRIGHTNESS)) { - _I("Failed to read vconf value for brightness."); - brt = PM_DEFAULT_BRIGHTNESS; - if (default_brt < PM_MIN_BRIGHTNESS || default_brt > PM_MAX_BRIGHTNESS) { - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); - } - default_brt = brt; - } - - backlight_ops.set_default_brt(default_brt); - backlight_ops.update(); - } - - return 0; -} - -static void set_alc_function(keynode_t *key_nodes, void *data) -{ - int status, ret; - - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - - status = vconf_keynode_get_int(key_nodes); - - switch (status) { - case SETTING_BRIGHTNESS_AUTOMATIC_OFF: - case SETTING_BRIGHTNESS_AUTOMATIC_ON: - case SETTING_BRIGHTNESS_AUTOMATIC_PAUSE: - ret = set_autobrightness_state(status); - _D("Set auto brightness: %d", ret); - break; - default: - _E("Invalid value(%d)", status); - } -} - -static void set_alc_automatic_brt(keynode_t *key_nodes, void *data) -{ - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - automatic_brt = vconf_keynode_get_int(key_nodes) / AUTOMATIC_DEVIDE_VAL; - _D("Automatic brt(%d)", automatic_brt); - - alc_update_brt(true); -} - -static gboolean update_handler(void *data) -{ - int ret, on; - - update_timeout = 0; - - if (pm_cur_state != S_NORMAL) - return G_SOURCE_REMOVE; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &on); - if (ret < 0 || on != SETTING_BRIGHTNESS_AUTOMATIC_ON) { - if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - return G_SOURCE_REMOVE; - } - - _D("Auto brightness is working."); - alc_update_brt(true); - - return G_SOURCE_REMOVE; -} - -static void update_auto_brightness(bool update) -{ - if (update_timeout) { - g_source_remove(update_timeout); - update_timeout = 0; - } - - if (update) { - update_timeout = g_timeout_add(AUTOMATIC_DELAY_TIME, - update_handler, NULL); - } -} - -static int prepare_lsensor(void *data) -{ - int status, ret; - int brt = -1; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &status); - if (ret == 0 && status == SETTING_BRIGHTNESS_AUTOMATIC_ON) - set_autobrightness_state(status); - else if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - - /* add auto_brt_setting change handler */ - vconf_notify_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - set_alc_function, NULL); - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, &brt); - if (ret < 0) - _E("Failed to get vconf value for automatic lcd brightness: %d", vconf_get_ext_errno()); - - if (brt < PM_MIN_BRIGHTNESS || brt > PM_MAX_BRIGHTNESS) { - _E("Failed to get automatic brightness."); - } else { - automatic_brt = brt / AUTOMATIC_DEVIDE_VAL; - _I("Automatic brt(%d) init success.", automatic_brt); - } - - vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, - set_alc_automatic_brt, NULL); - - return 0; -} - -static void update_brightness_direct(void) -{ - int ret, status; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &status); - if (ret == 0 && status == SETTING_BRIGHTNESS_AUTOMATIC_ON) - alc_update_brt(true); - else if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); -} - -static int set_autobrightness_min(int val, char *name) -{ - if (!name) - return -EINVAL; - - if (val < PM_MIN_BRIGHTNESS || val > PM_MAX_BRIGHTNESS) - return -EINVAL; - - min_brightness = val; - - if (min_brightness_name) { - free(min_brightness_name); - min_brightness_name = 0; - } - min_brightness_name = strndup(name, strlen(name)); - - update_brightness_direct(); - - _I("Auto brightness min value changed. min_brightness=%d min_brightness_name=%s", - min_brightness, min_brightness_name); - - return 0; -} - -static void reset_autobrightness_min(GDBusConnection *conn, - const gchar *sender, - const gchar *unique_name, - gpointer data) -{ - if (!sender) - return; - - if (!min_brightness_name) - return; - - if (strcmp(sender, min_brightness_name)) - return; - - _I("Change to default min brightness. before=%d changed=%d brightness_name=%s", min_brightness, - PM_MIN_BRIGHTNESS, min_brightness_name); - min_brightness = PM_MIN_BRIGHTNESS; - if (min_brightness_name) { - free(min_brightness_name); - min_brightness_name = 0; - } - - update_brightness_direct(); -} - -static int lcd_changed_cb(void *data) -{ - int lcd_state; - - if (!data) - return 0; - lcd_state = *(int *)data; - if (lcd_state == S_LCDOFF && alc_timeout_id > 0) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - - return 0; -} - -static int booting_done_cb(void *data) -{ - int state; - - if (!data) - return 0; - - state = *(int *)data; - if (state != true) - return 0; - - /* get light data from sensor fw */ - prepare_lsensor(NULL); - - return 0; -} - -static void exit_lsensor(void) -{ - vconf_ignore_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - set_alc_function); - - vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, - set_alc_automatic_brt); - - set_autobrightness_state(SETTING_BRIGHTNESS_AUTOMATIC_OFF); -} - -static void auto_brightness_init(void *data) -{ - display_info.update_auto_brightness = update_auto_brightness; - display_info.set_autobrightness_min = set_autobrightness_min; - display_info.reset_autobrightness_min = reset_autobrightness_min; - - register_notifier(DEVICE_NOTIFIER_LCD, lcd_changed_cb); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); -} - -static void auto_brightness_exit(void *data) -{ - exit_lsensor(); - - unregister_notifier(DEVICE_NOTIFIER_LCD, lcd_changed_cb); - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); -} - -static const struct display_ops display_autobrightness_ops = { - .name = "auto-brightness", - .init = auto_brightness_init, - .exit = auto_brightness_exit, -}; - -DISPLAY_OPS_REGISTER(&display_autobrightness_ops) - diff --git a/plugins/iot/display/display-actor.c b/plugins/iot/display/display-actor.c deleted file mode 100644 index bab8630..0000000 --- a/plugins/iot/display/display-actor.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include - -#include "util.h" -#include "display-actor.h" -#include "core/list.h" -#include "core/common.h" - -static dd_list *actor_head; - -void display_add_actor(struct display_actor_ops *actor) -{ - DD_LIST_APPEND(actor_head, actor); -} - -static struct display_actor_ops *display_find_actor(enum display_actor_id id) -{ - dd_list *elem; - struct display_actor_ops *actor; - - DD_LIST_FOREACH(actor_head, elem, actor) { - if (actor->id == id) - return actor; - } - return NULL; -} - -int display_set_caps(enum display_actor_id id, unsigned int caps) -{ - struct display_actor_ops *actor; - - if (id <= 0 || !caps) - return -EINVAL; - - actor = display_find_actor(id); - if (!actor) - return -EINVAL; - - actor->caps |= caps; - - return 0; -} - -int display_reset_caps(enum display_actor_id id, unsigned int caps) -{ - struct display_actor_ops *actor; - - if (id <= 0 || !caps) - return -EINVAL; - - actor = display_find_actor(id); - if (!actor) - return -EINVAL; - - actor->caps &= ~caps; - - return 0; -} - -unsigned int display_get_caps(enum display_actor_id id) -{ - struct display_actor_ops *actor; - - if (id <= 0) - return 0; - - actor = display_find_actor(id); - if (!actor) - return 0; - - return actor->caps; -} - -int display_has_caps(unsigned int total_caps, unsigned int caps) -{ - if (!total_caps || !caps) - return false; - - if ((total_caps & caps) == caps) - return true; - - return false; -} - diff --git a/plugins/iot/display/display-dbus.c b/plugins/iot/display/display-dbus.c deleted file mode 100644 index 308d665..0000000 --- a/plugins/iot/display/display-dbus.c +++ /dev/null @@ -1,1168 +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. - */ - - -/** - * @file display-dbus.c - * @brief dbus interface - * - */ - -#include -#include -#include -#include -#include -#include - -#include "ambient-mode.h" -#include "core/log.h" -#include "util.h" -#include "core.h" -#include "core/common.h" -#include "core/devices.h" -#include "core/device-idler.h" -#include "apps/apps.h" -#include "dd-display.h" -#include "display-actor.h" -#include "display-ops.h" -#include - -#define SIGNAL_HOMESCREEN "HomeScreen" - -#define DUMP_MODE_WATING_TIME 600000 - -#define EXPIRED_POPUP_TYPE_POWER "power_lock_expired" -#define EXPIRED_POPUP_PID "_APP_PID_" -#define EXPIRED_POPUP_COMM "_APP_COMM_" -#define EXPIRED_POPUP_ID "_REQUEST_ID_" - -#define CHECK_POWEROFF() \ - do { \ - if (device_poweroff(NULL)) { \ - _E("Ignore requests for display during power off"); \ - return g_variant_new("(i)", -EBUSY); \ - } \ - } while (0) - -GVariant *dbus_start(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - static const struct device_ops *display_device_ops = NULL; - - if (device_poweroff(NULL)) - goto out; - - if (!display_device_ops) - display_device_ops = find_device("display"); - if (NOT_SUPPORT_OPS(display_device_ops)) - goto out; - - display_device_ops->start(CORE_LOGIC_MODE); -out: - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_stop(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - static const struct device_ops *display_device_ops = NULL; - - if (device_poweroff(NULL)) - goto out; - - if (!display_device_ops) - display_device_ops = find_device("display"); - if (NOT_SUPPORT_OPS(display_device_ops)) - goto out; - - display_device_ops->stop(CORE_LOGIC_MODE); -out: - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_lockstate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - char *option1_str; - char *option2_str; - int timeout; - pid_t pid; - int state; - int flag; - int ret = 0; - unsigned int caps; - - CHECK_POWEROFF(); - - g_variant_get(param, "(sssi)", &state_str, &option1_str, &option2_str, &timeout); - - if (!state_str || timeout < 0) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - if (!strcmp(option1_str, STAYCURSTATE_STR)) - flag = STAY_CUR_STATE; - else if (!strcmp(option1_str, GOTOSTATENOW_STR)) - flag = GOTO_STATE_NOW; - else { - _E("%s option is invalid. set default option!", option1_str); - flag = STAY_CUR_STATE; - } - - if (!strcmp(option2_str, HOLDKEYBLOCK_STR)) - flag |= HOLD_KEY_BLOCK; - - if (flag & GOTO_STATE_NOW) { - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) && - state == LCD_NORMAL) { - _D("No lcdon capability!"); - ret = -EPERM; - goto out; - } - if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) && - state == LCD_OFF) { - _D("No lcdoff capability!"); - ret = -EPERM; - goto out; - } - } - - if (check_dimstay(state, flag) == true) { - _E("LCD state can not be changed to OFF state now!"); - flag &= ~GOTO_STATE_NOW; - flag |= STAY_CUR_STATE; - } - - if (disp_plgn.pm_lock_internal) - ret = disp_plgn.pm_lock_internal(pid, state, flag, timeout); -out: - g_free(state_str); - g_free(option1_str); - g_free(option2_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_unlockstate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - char *option_str; - pid_t pid; - int state; - int flag; - int ret = 0; - - CHECK_POWEROFF(); - - g_variant_get(param, "(ss)", &state_str, &option_str); - - if (!state_str) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - if (!strcmp(option_str, SLEEP_MARGIN_STR)) - flag = PM_SLEEP_MARGIN; - else if (!strcmp(option_str, RESET_TIMER_STR)) - flag = PM_RESET_TIMER; - else if (!strcmp(option_str, KEEP_TIMER_STR)) - flag = PM_KEEP_TIMER; - else { - _E("%s option is invalid. set default option!", option_str); - flag = PM_RESET_TIMER; - } - - if (disp_plgn.pm_unlock_internal) - ret = disp_plgn.pm_unlock_internal(pid, state, flag); -out: - g_free(state_str); - g_free(option_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_changestate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - pid_t pid; - int state; - int ret = 0; - unsigned int caps; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &state_str); - - if (!state_str) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else if (!strcmp(state_str, PM_STANDBY_STR)) - state = STANDBY; - else if (!strcmp(state_str, PM_SUSPEND_STR)) - state = SUSPEND; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) && - state == LCD_NORMAL) { - _D("No lcdon capability!"); - ret = -EPERM; - goto out; - } - if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) && - state == LCD_OFF) { - _D("No lcdoff capability!"); - ret = -EPERM; - goto out; - } - - if (check_dimstay(state, GOTO_STATE_NOW) == true) { - _E("LCD state can not be changed to OFF state!"); - ret = -EBUSY; - goto out; - } - - if (disp_plgn.pm_change_internal) - ret = disp_plgn.pm_change_internal(pid, state); - - if (!ret && state == LCD_OFF) - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); -out: - g_free(state_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getdisplaycount(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - ret = DEFAULT_DISPLAY_COUNT; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getmaxbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret, state; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &state); - if (state == DISPLAY_STATE_NORMAL) - ret = DEFAULT_DISPLAY_MAX_BRIGHTNESS; - else if (state == DISPLAY_STATE_SCREEN_DIM) - ret = DEFAULT_DISPLAY_MAX_DIM_BRIGHTNESS; - else - ret = -EINVAL; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setmaxbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - ret = -ENOTSUP; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int brt = -1, state, ret; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &state); - - if (state == DISPLAY_STATE_NORMAL) - ret = backlight_ops.get_brightness(&brt); - else if (state == DISPLAY_STATE_SCREEN_DIM) { - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, &brt); - if (ret < 0) - _E("Failed to get vconf value for lcd dim brightness: %d", vconf_get_ext_errno()); - } else - ret = -EINVAL; - - if (ret >= 0) - ret = brt; - - _I("get brightness %d, %d", brt, ret); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int state, brt, autobrt, ret = 0, caps; - - CHECK_POWEROFF(); - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) { - _D("No brightness changing capability!"); - ret = -EPERM; - goto error; - } - - g_variant_get(param, "(ii)", &state, &brt); - - //Check if brt is same with DIM - if (brt == 0) { - _E("application can not set this value(DIM VALUE:%d)", brt); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - autobrt = SETTING_BRIGHTNESS_AUTOMATIC_OFF; - } - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - _E("auto_brightness state is ON, can not change the brightness value"); - ret = -EPERM; - goto error; - } - - if (state == DISPLAY_STATE_NORMAL) { - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); - } else if (state == DISPLAY_STATE_SCREEN_DIM) { - if (pm_cur_state == S_LCDDIM) { - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - } - - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd dim brightness: %d", vconf_get_ext_errno()); - } else - ret = -EINVAL; - - _I("set brightness %d, %d", brt, ret); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_holdbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int brt, autobrt, ret, caps; - - CHECK_POWEROFF(); - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) { - _D("No brightness changing capability!"); - ret = -EPERM; - goto error; - } - - g_variant_get(param, "(i)", &brt); - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - autobrt = SETTING_BRIGHTNESS_AUTOMATIC_OFF; - } - - ret = vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON); - if (ret < 0) - _E("Failed to set vconf value for custom brightness status: %d", vconf_get_ext_errno()); - - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - _D("Auto brightness will be paused"); - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_PAUSE); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - } - - _I("hold brightness %d, %d", brt, ret); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_releasebrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int bat, charger, changed, setting, brt, autobrt, ret = 0; - - CHECK_POWEROFF(); - - ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat); - if (ret < 0) { - _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charger); - if (ret < 0) { - _E("Failed to get vconf value for charger status: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_bool(VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM, &changed); - if (ret < 0) { - _E("Failed to get vconf value for brightness changed in lpm: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &setting); - if (ret < 0) { - _E("Failed to get vconf value for lcd brightness: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_OFF); - if (ret < 0) - _E("Failed to set vconf value for custom brightness status: %d", vconf_get_ext_errno()); - - ret = backlight_ops.get_brightness(&brt); - if (ret < 0) - brt = ret; - - // check dim state - if (low_battery_state(bat) && - charger == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED && !changed) { - _D("batt warning low : brightness is not changed!"); - if (brt != 0) - backlight_ops.set_brightness(0); - goto error; - } - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_OFF) { - if (brt != setting) - backlight_ops.set_brightness(setting); - } else if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) { - _D("Auto brightness will be enable"); - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_ON); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - } - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setrefreshrate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int app, val, ret, control; - - CHECK_POWEROFF(); - - g_variant_get(param, "(ii)", &app, &val); - - if (app < 0 || app >= ARRAY_SIZE(display_conf.framerate_app) || val < 0) { - ret = -EINVAL; - goto error; - } - - if (!display_conf.framerate_app[app]) { - _I("This case(%d) is not support in this target", app); - ret = -EPERM; - goto error; - } - - control = display_conf.control_display; - - if (control) - backlight_ops.off(NORMAL_MODE); - - _D("app : %d, value : %d", app, val); - ret = backlight_ops.set_frame_rate(val); - if (ret < 0) - _E("Failed to set frame rate (%d)", ret); - - if (control) - backlight_ops.on(NORMAL_MODE); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setautobrightnessmin(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int val, ret; - pid_t pid; - int id = 0; - - CHECK_POWEROFF(); - - if (!display_info.set_autobrightness_min) { - ret = -EIO; - goto error; - } - g_variant_get(param, "(i)", &val); - - pid = dbus_connection_get_sender_pid(conn, sender); - ret = display_info.set_autobrightness_min(val, (char *)sender); - if (ret) { - _W("fail to set autobrightness min %d, %d by %d", val, ret, pid); - goto error; - } - if (display_info.reset_autobrightness_min) { - id = dbus_handle_watch_name(sender, display_info.reset_autobrightness_min, NULL, NULL, NULL); - if (id <= 0) { - _E("failed to watch name %s, id %d", sender, id); - //todo: set return value - } - _I("set autobrightness min %d by %d", val, pid); - } -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setlcdtimeout(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int on, dim, holdkey_block, ret; - pid_t pid; - int id = 0; - - CHECK_POWEROFF(); - - g_variant_get(param, "(iii)", &on, &dim, &holdkey_block); - - pid = dbus_connection_get_sender_pid(conn, sender); - ret = set_lcd_timeout(on, dim, holdkey_block, sender); - if (ret) { - _W("fail to set lcd timeout %d by %d", ret, pid); - } else { - id = dbus_handle_watch_name(sender, reset_lcd_timeout, NULL, NULL, NULL); - if (id <= 0) { - _E("failed to watch name %s, id %d", sender, id); - //todo: set return value - } - _I("set lcd timeout on %d, dim %d, holdblock %d by %d", - on, dim, holdkey_block, pid); - } - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_lockscreenbgon(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - char *on = NULL; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &on); - - if (!strcmp(on, "true")) { - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_LOCK_SCREEN_BG, true); - } else if (!strcmp(on, "false")) { - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_LOCK_SCREEN_BG, false); - } else - ret = -EINVAL; - - g_free(on); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_dumpmode(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - char *on; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &on); - - if (!strcmp(on, "on")) { - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, - STAY_CUR_STATE, DUMP_MODE_WATING_TIME); - } else if (!strcmp(on, "off")) { - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, PM_SLEEP_MARGIN); - } else - ret = -EINVAL; - - g_free(on); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_savelog(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - if (!device_poweroff(NULL)) - save_display_log(); - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_powerkeyignore(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int on; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &on); - - if (CHECK_OPS(keyfilter_ops, set_powerkey_ignore)) - keyfilter_ops->set_powerkey_ignore(on == 1 ? true : false); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_powerkeylcdoff(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - if (CHECK_OPS(keyfilter_ops, powerkey_lcdoff)) - ret = keyfilter_ops->powerkey_lcdoff(); - else - ret = -ENOSYS; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_customlcdon(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int timeout; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &timeout); - - ret = custom_lcdon(timeout); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_staytouchscreenoff(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int val; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &val); - - set_stay_touchscreen_off(val); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_lcdpaneloffmode(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int val; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &val); - - set_lcd_paneloff_mode(val); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_actorcontrol(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0, val, actor; - char *op; - - CHECK_POWEROFF(); - - g_variant_get(param, "(sii)", &op, &actor, &val); - - if (!strcmp(op, "set")) - ret = display_set_caps(actor, val); - else if (!strcmp(op, "reset")) - ret = display_reset_caps(actor, val); - else - ret = -EINVAL; - - g_free(op); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getcustombrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int status = 0; - - CHECK_POWEROFF(); - - status = backlight_ops.get_custom_status(); - - return g_variant_new("(i)", status); -} - -struct pmlock_expired_s { - char req_id[32]; - GDBusMethodInvocation *invocation; - int value; - pid_t pid; -}; - -static dd_list *expired_req_list; - -static int get_command(pid_t pid, char *comm, size_t len) -{ - FILE *fp; - char path[PATH_MAX]; - char name[NAME_MAX]; - char *tmp; - int ret; - - snprintf(path, sizeof(path), "/proc/%d/comm", pid); - - fp = fopen(path, "r"); - if (!fp) { - _E("Failed to open file %s, errno:%d", path, errno); - return -errno; - } - - ret = fread(name, 1, sizeof(name) - 1, fp); - name[ret] = '\0'; - fclose(fp); - - tmp = name; - while (*tmp != '\0') { - if (*tmp == '\n' || - *tmp == '\r') { - *tmp = '\0'; - break; - } - tmp++; - } - - snprintf(comm, len, "%s", name); - - return 0; -} - -GVariant *dbus_locktimeout_expired(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - char *req_id; - pid_t pid; - char pid_str[16]; - char comm[NAME_MAX]; - struct pmlock_expired_s *ex = NULL; - GVariant *gvar = NULL; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &req_id); - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - ret = get_command(pid, comm, sizeof(comm)); - if (ret < 0) { - _E("Failed to get command (%d)", ret); - goto out; - } - - ex = calloc(1, sizeof(struct pmlock_expired_s)); - if (!ex) { - _E("calloc() failed"); - ret = -ENOMEM; - goto out; - } - - snprintf(pid_str, sizeof(pid_str), "%d", pid); - ret = launch_system_app(APP_DEFAULT, 8, - APP_KEY_TYPE, - EXPIRED_POPUP_TYPE_POWER, - EXPIRED_POPUP_PID, - pid_str, - EXPIRED_POPUP_COMM, - comm, - EXPIRED_POPUP_ID, - req_id); - if (ret < 0) { - _E("Failed to launch pmlock expired popup(%d)", ret); - goto out; - } - - ex->pid = pid; - snprintf(ex->req_id, sizeof(ex->req_id), "%s", req_id); - - ex->invocation = invocation; - - DD_LIST_APPEND(expired_req_list, ex); - - g_free(req_id); - return NULL; - -out: - gvar = g_variant_new("(i)", ret); - g_free(req_id); - if (ex) - free(ex); - return gvar; -} - -static gboolean app_term(gpointer data) -{ - struct pmlock_expired_s *ex = data; - - if (ex) { - if (kill(ex->pid, 0) != -1) - kill(ex->pid, SIGKILL); - free(ex); - } - return G_SOURCE_REMOVE; -} - -static void expired_deliver_result(void *data) -{ - struct pmlock_expired_s *ex = data; - struct pmlock_expired_s *item = NULL; - dd_list *l; - size_t len; - int value; - char *id; - - if (!ex) - return; - - len = strlen(ex->req_id) + 1; - DD_LIST_FOREACH(expired_req_list, l, item) { - if (!strncmp(item->req_id, ex->req_id, len)) { - DD_LIST_REMOVE(expired_req_list, item); - break; - } - } - if (!item) - goto out; - - id = ex->req_id; - value = ex->value; - - _I("User input of req_id(%s) is (%s)", id, value == 0 ? "ALLOW power lock" : - (value == 2) ? "KILL app" : "Release power lock"); - - if (!item->invocation) { - _E("item->invocation is null"); - goto out; - } - g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(i)", 0)); - - if (value == 2) { - kill(item->pid, SIGTERM); - g_timeout_add(3000, app_term, (gpointer)item); - item = NULL; - } - -out: - free(ex); - free(item); -} - -GVariant *dbus_locktimeout_input(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - char *req_id; - struct pmlock_expired_s *ex; - int value; - - CHECK_POWEROFF(); - - g_variant_get(param, "(si)", &req_id, &value); - - ex = calloc(1, sizeof(struct pmlock_expired_s)); - if (!ex) { - _E("calloc() failed"); - ret = -ENOMEM; - goto out; - } - - snprintf(ex->req_id, sizeof(ex->req_id), "%s", req_id); - ex->value = value; - - _I("req_id(%s), value(%d)", ex->req_id, ex->value); - - add_idle_request(expired_deliver_result, ex); - - ret = 0; - -out: - g_free(req_id); - return g_variant_new("(i)", ret); -} - -static const dbus_method_s dbus_methods[] = { - { "start", NULL, NULL, dbus_start }, - { "stop", NULL, NULL, dbus_stop }, - { "lockstate", "sssi", "i", dbus_lockstate }, - { "unlockstate", "ss", "i", dbus_unlockstate }, - { "changestate", "s", "i", dbus_changestate }, - { "ChangeState", "s", "i", dbus_changestate }, - { "getbrightness", "i", "i", dbus_getbrightness }, /* deprecated */ - { "setbrightness", "ii", "i", dbus_setbrightness }, /* deprecated */ - { "setframerate", "ii", "i", dbus_setrefreshrate }, /* deprecated */ - { "setautobrightnessmin", "i", "i", dbus_setautobrightnessmin }, - { "setlcdtimeout", "iii", "i", dbus_setlcdtimeout }, - { "LockScreenBgOn", "s", "i", dbus_lockscreenbgon }, - { "GetDisplayCount", NULL, "i", dbus_getdisplaycount }, - { "GetMaxBrightness", "i", "i", dbus_getmaxbrightness }, - { "SetMaxBrightness", "i", "i", dbus_setmaxbrightness }, - { "GetBrightness", "i", "i", dbus_getbrightness }, - { "SetBrightness", "ii", "i", dbus_setbrightness }, - { "HoldBrightness", "i", "i", dbus_holdbrightness }, - { "ReleaseBrightness", NULL, "i", dbus_releasebrightness }, - { "SetRefreshRate", "ii", "i", dbus_setrefreshrate }, - { "Dumpmode", "s", "i", dbus_dumpmode }, - { "SaveLog", NULL, NULL, dbus_savelog }, - { "PowerKeyIgnore", "i", "i", dbus_powerkeyignore }, - { "PowerKeyLCDOff", NULL, "i", dbus_powerkeylcdoff }, - { "CustomLCDOn", "i", "i", dbus_customlcdon }, - { "StayTouchScreenOff", "i", "i", dbus_staytouchscreenoff }, - { "LCDPanelOffMode", "i", "i", dbus_lcdpaneloffmode }, - { "ActorControl", "sii", "i", dbus_actorcontrol }, - { "CustomBrightness", NULL, "i", dbus_getcustombrightness }, - { "CurrentBrightness", NULL, "i", dbus_getbrightness }, /* deprecated. It is remained for tizen 2.4 */ - { "LockTimeoutExpired", "s", "i", dbus_locktimeout_expired }, - { "LockTimeoutInput", "si", "i", dbus_locktimeout_input }, - /* Add methods here */ -}; - -static const dbus_interface_u dbus_interface = { - .oh = NULL, - .name = DEVICED_INTERFACE_DISPLAY, - .methods = dbus_methods, - .nr_methods = ARRAY_SIZE(dbus_methods), -}; - -static void homescreen_signal_handler(GDBusConnection *conn, - const gchar *sender, - const gchar *path, - const gchar *iface, - const gchar *name, - GVariant *param, - gpointer data) -{ - char *screen; - pid_t pid; - - g_variant_get(param, "(s)", &screen); - - _D("screen : %s", screen); - - pid = dbus_connection_get_sender_pid(conn, sender); - ambient_set_screen(screen, pid); - g_free(screen); -} - -/* - * Default capability - * api := LCDON | LCDOFF | BRIGHTNESS - * gesture := LCDON - */ -static struct display_actor_ops display_api_actor = { - .id = DISPLAY_ACTOR_API, - .caps = DISPLAY_CAPA_LCDON | - DISPLAY_CAPA_LCDOFF | - DISPLAY_CAPA_BRIGHTNESS, -}; - -static struct display_actor_ops display_gesture_actor = { - .id = DISPLAY_ACTOR_GESTURE, - .caps = DISPLAY_CAPA_LCDON, -}; - -int init_pm_dbus(void) -{ - int ret; - - display_add_actor(&display_api_actor); - display_add_actor(&display_gesture_actor); - - ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_DISPLAY, &dbus_interface); - if (ret < 0) - _E("fail to init dbus method(%d)", ret); - - ret = subscribe_dbus_signal(NULL, - DEVICED_OBJECT_PATH, - DEVICED_INTERFACE_NAME, - SIGNAL_HOMESCREEN, - homescreen_signal_handler, - NULL, NULL); - if (ret <= 0) { - _E("Failed to register signal handler! %d", ret); - return ret; - } - - return 0; -} - diff --git a/plugins/iot/display/display-ops.c b/plugins/iot/display/display-ops.c deleted file mode 100644 index 22b9137..0000000 --- a/plugins/iot/display/display-ops.c +++ /dev/null @@ -1,74 +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 "util.h" -#include "display-ops.h" -#include "core/list.h" -#include "core/common.h" - -static dd_list *disp_head; - -void add_display(const struct display_ops *disp) -{ - DD_LIST_APPEND(disp_head, disp); -} - -void remove_display(const struct display_ops *disp) -{ - DD_LIST_REMOVE(disp_head, disp); -} - -const struct display_ops *find_display_feature(const char *name) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - if (!strcmp(disp->name, name)) - return disp; - } - return NULL; -} - -void display_ops_init(void *data) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - _D("[%s] initialize", disp->name); - if (disp->init) - disp->init(data); - } -} - -void display_ops_exit(void *data) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - _D("[%s] deinitialize", disp->name); - if (disp->exit) - disp->exit(data); - } -} - diff --git a/plugins/iot/display/input.c b/plugins/iot/display/input.c deleted file mode 100644 index a986504..0000000 --- a/plugins/iot/display/input.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - * 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 -#include - -#include "util.h" -#include "core.h" -#include "poll.h" - -#define SEAT_NAME "seat0" - -static struct udev *udev; -static struct libinput *li; -static guint efd; - -int (*pm_callback) (int, PMMsg *); - -static inline void process_event(struct libinput_event *ev) -{ - static const struct device_ops *display_device_ops; - struct input_event input; - struct libinput *li; - struct libinput_event_keyboard *k; - unsigned int time; - int fd; - - if (!pm_callback) - return; - - if (!display_device_ops) { - display_device_ops = find_device("display"); - if (!display_device_ops) - return; - } - - /* do not operate when display stops */ - if (device_get_status(display_device_ops) - != DEVICE_OPS_STATUS_START) { - _E("display status is stop"); - return; - } - - switch (libinput_event_get_type(ev)) { - case LIBINPUT_EVENT_DEVICE_ADDED: - return; - case LIBINPUT_EVENT_KEYBOARD_KEY: - k = libinput_event_get_keyboard_event(ev); - time = libinput_event_keyboard_get_time(k); - li = libinput_event_get_context(ev); - - input.time.tv_sec = MSEC_TO_SEC(time); - input.time.tv_usec = MSEC_TO_USEC(time % 1000); - input.type = EV_KEY; - input.code = libinput_event_keyboard_get_key(k); - input.value = libinput_event_keyboard_get_key_state(k); - - fd = libinput_get_fd(li); - _D("time %ld.%06ld type %d code %d value %d fd %d", - input.time.tv_sec, input.time.tv_usec, input.type, - input.code, input.value, fd); - - if (CHECK_OPS(keyfilter_ops, check) && - keyfilter_ops->check(&input, fd) != 0) - return; - break; - case LIBINPUT_EVENT_POINTER_MOTION: - case LIBINPUT_EVENT_POINTER_BUTTON: - case LIBINPUT_EVENT_POINTER_AXIS: - li = libinput_event_get_context(ev); - input.type = EV_REL; - - fd = libinput_get_fd(li); - _D("type %d fd %d", input.type, fd); - - if (CHECK_OPS(keyfilter_ops, check) && - keyfilter_ops->check(&input, fd) != 0) - return; - break; - case LIBINPUT_EVENT_TOUCH_DOWN: - case LIBINPUT_EVENT_TOUCH_UP: - case LIBINPUT_EVENT_TOUCH_MOTION: - case LIBINPUT_EVENT_TOUCH_FRAME: - if (touch_event_blocked()) - return ; - break; - default: - break; - } - - /* lcd on or update lcd timeout */ - (*pm_callback) (INPUT_POLL_EVENT, NULL); -} - -static gboolean input_handler(gint fd, GIOCondition cond, void *data) -{ - struct libinput_event *ev; - struct libinput *input = (struct libinput *)data; - - /* Ignore input during poweroff */ - if (device_poweroff(NULL)) - return G_SOURCE_CONTINUE; - - if (!input) - return G_SOURCE_CONTINUE; - - libinput_dispatch(input); - - while ((ev = libinput_get_event(input))) { - process_event(ev); - - libinput_event_destroy(ev); - libinput_dispatch(input); - } - - return G_SOURCE_CONTINUE; -} - -static int open_restricted(const char *path, int flags, void *user_data) -{ - int fd; - unsigned int clockid = CLOCK_MONOTONIC; - - if (!path) - return -EINVAL; - - fd = open(path, flags); - if (fd >= 0) { - /* TODO Why does fd change the clock? */ - if (ioctl(fd, EVIOCSCLOCKID, &clockid) < 0) - _E("fail to change clock %s", path); - } - - return fd < 0 ? -errno : fd; -} - -static void close_restricted(int fd, void *user_data) -{ - close(fd); -} - -static const struct libinput_interface interface = { - .open_restricted = open_restricted, - .close_restricted = close_restricted, -}; - -int init_input(void) -{ - int ret; - int fd; - - udev = udev_new(); - if (!udev) { - _E("fail to create udev library context"); - return -EPERM; - } - - li = libinput_udev_create_context(&interface, NULL, udev); - if (!li) { - _E("fail to create a new libinput context from udev"); - return -EPERM; - } - - ret = libinput_udev_assign_seat(li, SEAT_NAME); - if (ret < 0) { - _E("fail to assign a seat"); - return -EPERM; - } - - fd = libinput_get_fd(li); - if (fd < 0) { - _E("fail to get file descriptor from libinput context"); - return -EPERM; - } - - /* add to poll handler */ - efd = g_unix_fd_add(fd, G_IO_IN, - input_handler, - (void *)((intptr_t)li)); - if (!efd) { - _E("fail to g_unix_fd_add"); - /* TODO Does it really need close()? */ - close(fd); - return -EPERM; - } - - return 0; -} - -int exit_input(void) -{ - if (efd) { - g_source_remove(efd); - efd = -1; - } - /* todo: close fd */ - - if (li) - libinput_unref(li); - - if (udev) - udev_unref(udev); - - return 0; -} diff --git a/plugins/iot/display/lock-detector.c b/plugins/iot/display/lock-detector.c deleted file mode 100644 index 0560ef4..0000000 --- a/plugins/iot/display/lock-detector.c +++ /dev/null @@ -1,232 +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. - */ - - -/** - * @file lock-detector.c - * @brief - * - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "util.h" -#include "core.h" -#include "core/list.h" - -struct lock_info { - unsigned long hash; - char *name; - int state; - int count; - long locktime; - long unlocktime; - long time; -}; - -#define LIMIT_COUNT 128 - -static dd_list *lock_info_list; - -static long get_time(void) -{ - struct timeval now; - gettimeofday(&now, NULL); - return (long)(now.tv_sec * 1000 + now.tv_usec / 1000); -} - -static void shrink_lock_info_list(void) -{ - dd_list *l, *l_prev; - struct lock_info *info; - unsigned int count; - - count = DD_LIST_LENGTH(lock_info_list); - if (count <= LIMIT_COUNT) - return; - _D("list is shrink : count %d", count); - - DD_LIST_REVERSE_FOREACH_SAFE(lock_info_list, l, l_prev, info) { - if (info->locktime == 0) { - DD_LIST_REMOVE_LIST(lock_info_list, l); - if (info->name) - free(info->name); - free(info); - count--; - } - if (count <= (LIMIT_COUNT / 2)) - break; - } -} - -int set_lock_time(const char *pname, int state) -{ - struct lock_info *info; - dd_list *l; - unsigned long val; - - if (!pname) - return -EINVAL; - - if (state < S_NORMAL || state > S_SLEEP) - return -EINVAL; - - val = g_str_hash(pname); - - 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; - DD_LIST_REMOVE(lock_info_list, info); - DD_LIST_PREPEND(lock_info_list, info); - return 0; - } - - info = malloc(sizeof(struct lock_info)); - if (!info) { - _E("Malloc is failed for lock_info!"); - return -ENOMEM; - } - - info->hash = val; - info->name = strndup(pname, strlen(pname)); - info->state = state; - info->count = 1; - info->locktime = get_time(); - info->unlocktime = 0; - info->time = 0; - - DD_LIST_APPEND(lock_info_list, info); - - return 0; -} - -int set_unlock_time(const char *pname, int state) -{ - bool find = false; - long diff; - struct lock_info *info; - dd_list *l; - unsigned long val; - - if (!pname) - return -EINVAL; - - if (state < S_NORMAL || state > S_SLEEP) - return -EINVAL; - - val = g_str_hash(pname); - - 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; - } - - if (!find) - return -EINVAL; - - if (info->locktime == 0) - return -EINVAL; - - /* update time */ - info->unlocktime = get_time(); - diff = info->unlocktime - info->locktime; - if (diff > 0) - info->time += diff; - info->locktime = 0; - - if (DD_LIST_LENGTH(lock_info_list) > LIMIT_COUNT) - shrink_lock_info_list(); - - return 0; -} - -void free_lock_info_list(void) -{ - dd_list *l, *l_next; - struct lock_info *info; - - if (!lock_info_list) - return; - - 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); - } - lock_info_list = NULL; -} - -void print_lock_info_list(int fd) -{ - struct lock_info *info; - dd_list *l; - char buf[255]; - int ret; - - if (!lock_info_list) - return; - - snprintf(buf, sizeof(buf), - "current time : %ld ms\n", get_time()); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - - snprintf(buf, sizeof(buf), - "[%10s %6s] %6s %10s %10s %10s %s\n", "hash", "state", - "count", "locktime", "unlocktime", "time", "process name"); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - - DD_LIST_FOREACH(lock_info_list, l, info) { - long time = 0; - if (info->locktime != 0 && info->unlocktime == 0) - time = get_time() - info->locktime; - snprintf(buf, sizeof(buf), - "[%10lu %6d] %6d %10ld %10ld %10ld %s\n", - info->hash, - info->state, - info->count, - info->locktime, - info->unlocktime, - info->time + time, - info->name); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - } -} - diff --git a/plugins/iot/display/poll.c b/plugins/iot/display/poll.c deleted file mode 100644 index ee0471d..0000000 --- a/plugins/iot/display/poll.c +++ /dev/null @@ -1,174 +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. - */ - - -/** - * @file poll.c - * @brief Power Manager poll implementation - * - */ - -#include -#include "util.h" -#include "core.h" -#include "poll.h" -#include "display/display-ops.h" - -#define SHIFT_UNLOCK 4 -#define SHIFT_UNLOCK_PARAMETER 12 -#define SHIFT_CHANGE_STATE 8 -#define SHIFT_CHANGE_TIMEOUT 20 -#define LOCK_FLAG_SHIFT 16 -#define __HOLDKEY_BLOCK_BIT 0x1 -#define HOLDKEY_BLOCK_BIT (__HOLDKEY_BLOCK_BIT << LOCK_FLAG_SHIFT) - -static PMMsg recv_data; - -int check_dimstay(int next_state, int flag) -{ - if (next_state != LCD_OFF) - return false; - - if (!(flag & GOTO_STATE_NOW)) - return false; - - if (!(pm_status_flag & DIMSTAY_FLAG)) - return false; - - return true; -} - -static enum state_t get_state(int s_bits) -{ - switch (s_bits) { - case LCD_NORMAL: - return S_NORMAL; - case LCD_DIM: - return S_LCDDIM; - case LCD_OFF: - return S_LCDOFF; - case STANDBY: - return S_STANDBY; - case SUSPEND: - return S_SLEEP; - default: - return -EINVAL; - } -} - -static bool state_supported(enum state_t st) -{ - if (states[st].trans) - return true; - return false; -} - -static int __pm_lock_internal(pid_t pid, int s_bits, int flag, int timeout) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_LOCK); - - if (flag & GOTO_STATE_NOW) - /* if the flag is true, go to the locking state directly */ - cond = SET_COND_FLAG(cond, PM_REQUEST_CHANGE); - - if (flag & HOLD_KEY_BLOCK) - cond = SET_COND_FLAG(cond, PM_FLAG_BLOCK_HOLDKEY); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = timeout; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -static int __pm_unlock_internal(pid_t pid, int s_bits, int flag) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_UNLOCK); - - if (flag & PM_KEEP_TIMER) - cond = SET_COND_FLAG(cond, PM_FLAG_KEEP_TIMER); - - if (flag & PM_RESET_TIMER) - cond = SET_COND_FLAG(cond, PM_FLAG_RESET_TIMER); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = 0; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -static int __pm_change_internal(pid_t pid, int s_bits) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_CHANGE); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = 0; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -void init_pm_internal() -{ - disp_plgn.pm_lock_internal = __pm_lock_internal; - disp_plgn.pm_unlock_internal = __pm_unlock_internal; - disp_plgn.pm_change_internal = __pm_change_internal; -} diff --git a/plugins/iot/display/setting.c b/plugins/iot/display/setting.c deleted file mode 100644 index 1f2f1c7..0000000 --- a/plugins/iot/display/setting.c +++ /dev/null @@ -1,271 +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 "ambient-mode.h" -#include "core.h" -#include "util.h" -#include "setting.h" -#include "display-ops.h" - -#define LCD_DIM_RATIO 0.3 -#define LCD_MAX_DIM_TIMEOUT 7000 -#define LCD_MIN_DIM_TIMEOUT 500 - -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_POWER_CUSTOM_BRIGHTNESS] = VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, -}; - -static int lock_screen_state = VCONFKEY_IDLE_UNLOCK; -static bool lock_screen_bg_state = false; -static int force_lcdtimeout = 0; -static int custom_on_timeout = 0; -static int custom_normal_timeout = 0; -static int custom_dim_timeout = 0; - -static void display_state_send_system_event(int state) -{ - bundle *b; - const char *str; - - if (state == S_NORMAL) - str = EVT_VAL_DISPLAY_NORMAL; - else if (state == S_LCDDIM) - str = EVT_VAL_DISPLAY_DIM; - else if (state == S_LCDOFF) - str = EVT_VAL_DISPLAY_OFF; - else - return; - - _I("eventsystem (%s)", str); - - b = bundle_create(); - bundle_add_str(b, EVT_KEY_DISPLAY_STATE, str); - eventsystem_send_system_event(SYS_EVENT_DISPLAY_STATE, b); - bundle_free(b); -} - -int set_force_lcdtimeout(int timeout) -{ - if (timeout < 0) - return -EINVAL; - - force_lcdtimeout = timeout; - - return 0; -} - -int __get_lock_screen_state(void) -{ - return lock_screen_state; -} - -void set_lock_screen_state(int state) -{ - switch (state) { - case VCONFKEY_IDLE_LOCK: - case VCONFKEY_IDLE_UNLOCK: - lock_screen_state = state; - break; - default: - lock_screen_state = VCONFKEY_IDLE_UNLOCK; - } -} - -int get_lock_screen_bg_state(void) -{ - return lock_screen_bg_state; -} - -void set_lock_screen_bg_state(bool state) -{ - _I("state is %d", state); - lock_screen_bg_state = state; -} - -int set_setting_pmstate(int val) -{ - static int old = -1; - int ret; - - if (old == val) - return 0; - old = val; - - display_state_send_system_event(val); - ret = vconf_set_int(VCONFKEY_PM_STATE, val); - if (ret < 0) - _E("Failed to set vconf value for pm state: %d", vconf_get_ext_errno()); - - return ret; -} - -int get_setting_brightness(int *level) -{ - int ret; - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, level); - if (ret < 0) - _E("Failed to get vconf value for lcd brightness: %d", vconf_get_ext_errno()); - - return ret; -} - -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; - } - - if (ambient_get_condition() == true) { - *dim_timeout = LCD_MIN_DIM_TIMEOUT; - return; - } - - ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout); - if (ret < 0) { - _E("Failed to get vconf value for setting timeout: %d", vconf_get_ext_errno()); - vconf_timeout = DEFAULT_NORMAL_TIMEOUT; - } - - if (force_lcdtimeout > 0) - on_timeout = SEC_TO_MSEC(force_lcdtimeout); - else - on_timeout = SEC_TO_MSEC(vconf_timeout); - - val = (double)on_timeout * LCD_DIM_RATIO; - if (val > LCD_MAX_DIM_TIMEOUT) - val = LCD_MAX_DIM_TIMEOUT; - - *dim_timeout = val; -} - -void get_run_timeout(int *timeout) -{ - int dim_timeout = -1; - int vconf_timeout = -1; - int on_timeout; - int ret; - - if (custom_normal_timeout > 0) { - *timeout = custom_normal_timeout; - return; - } - - ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout); - if (ret < 0) { - _E("Failed to get vconf value for setting timeout: %d", vconf_get_ext_errno()); - vconf_timeout = DEFAULT_NORMAL_TIMEOUT; - } - - if (force_lcdtimeout > 0) - on_timeout = SEC_TO_MSEC(force_lcdtimeout); - else - on_timeout = SEC_TO_MSEC(vconf_timeout); - - if (on_timeout == 0) { - *timeout = on_timeout; - return; - } - - get_dim_timeout(&dim_timeout); - *timeout = on_timeout - dim_timeout; -} - -int set_custom_lcdon_timeout(int timeout) -{ - int changed = (custom_on_timeout == timeout ? false : true); - - custom_on_timeout = timeout; - - if (timeout <= 0) { - custom_normal_timeout = 0; - custom_dim_timeout = 0; - return changed; - } - - custom_dim_timeout = (double)timeout * LCD_DIM_RATIO; - custom_normal_timeout = timeout - custom_dim_timeout; - - _I("custom normal(%d), dim(%d)", custom_normal_timeout, - custom_dim_timeout); - - return changed; -} - -static int setting_cb(keynode_t *key_nodes, void *data) -{ - keynode_t *tmp = key_nodes; - int index; - - index = (int)((intptr_t)data); - if (index > SETTING_END) { - _E("Unknown setting key: %s, idx=%d", - vconf_keynode_get_name(tmp), index); - return -1; - } - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(index, vconf_keynode_get_int(tmp)); - - return 0; -} - -int init_setting(int (*func) (int key_idx, int val)) -{ - int i; - - if (func != NULL) - disp_plgn.update_pm_setting = func; - - for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) { - /* - * To pass an index data through the vconf infratstructure - * without memory allocation, an index data becomes typecast - * to proper pointer size on each architecture. - */ - vconf_notify_key_changed(setting_keys[i], (void *)setting_cb, - (void *)((intptr_t)i)); - } - - disp_plgn.get_lock_screen_state = __get_lock_screen_state; - - return 0; -} - -int exit_setting(void) -{ - int i; - for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) - vconf_ignore_key_changed(setting_keys[i], (void *)setting_cb); - - return 0; -} - diff --git a/plugins/mobile/display/ambient-mode.c b/plugins/mobile/display/ambient-mode.c deleted file mode 100644 index b15fd56..0000000 --- a/plugins/mobile/display/ambient-mode.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2017 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 "util.h" -#include "core.h" -#include "display-ops.h" -#include "core/device-notifier.h" -#include "core/devices.h" - -#define ON "on" -#define OFF "off" - -#define SIGNAL_AMBIENT_MODE "AmbientMode" -#define CLOCK_START "clockstart" -#define CLOCK_END "clockend" -#define TIMEOUT_NONE (-1) -#define AMBIENT_CLOCK_WAITING_TIME 5000 /* ms */ - -static int ambient_state; -static pid_t ambient_pid; /* Ambient Clock pid */ -static int ambient_condition; -static unsigned int update_count; - -void broadcast_ambient_state(int state) -{ - int ret; - - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, - DEVICED_INTERFACE_DISPLAY, - SIGNAL_AMBIENT_MODE, - g_variant_new("(i)", (state == 0 ? 0 : 1))); - if (ret < 0) - _E("Failed to send dbus signal(%s)", SIGNAL_AMBIENT_MODE); -} - -int ambient_get_condition(void) -{ - return ambient_condition; -} - -int ambient_get_state(void) -{ - return ambient_state; -} - -static void ambient_set_condition(keynode_t *key_nodes, void *data) -{ - int state; - - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - - ambient_condition = vconf_keynode_get_bool(key_nodes); - _I("Ambient mode condition is %d.", ambient_condition); - - state = (ambient_condition == 0 ? 0 : 1); - device_notify(DEVICE_NOTIFIER_DISPLAY_AMBIENT_CONDITION, (void *)&state); - - set_dim_state(state); -} - -int ambient_set_state(int on) -{ - if (!ambient_condition) - return 0; - - broadcast_ambient_state(on); - - update_count = 0; - - if (!on) - ambient_pid = 0; - - _D("AMBIENT is %s.", (on ? ON : OFF)); - - ambient_state = on; - - device_notify(DEVICE_NOTIFIER_DISPLAY_AMBIENT_STATE, (void *)&ambient_state); - - return 0; -} - -void ambient_check_invalid_state(pid_t pid) -{ - if (pid != INTERNAL_LOCK_AMBIENT) - return; - - if (backlight_ops.get_lcd_power() == DPMS_OFF) - return; - - if (is_emulator()) { - /* In emulator, deviced does not turn off the display. */ - if (backlight_ops.get_lcd_power() == DPMS_ON) - return; - } - - if (ambient_get_state() == false) - return; - - _E("Invalid state. Ambient state is change to off."); - - /* If lcd_power is on and ambient state is true - * when pm state is changed to sleep, - * deviced doesn't get the clock signal. - * deviced just turns off lcd in this case. */ - - ambient_set_state(false); - backlight_ops.off(NORMAL_MODE); -} - -static void start_clock(void) -{ - if (pm_cur_state == S_NORMAL || - pm_cur_state == S_LCDDIM || - ambient_state == false) - return; - - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, STAY_CUR_STATE, - AMBIENT_CLOCK_WAITING_TIME); -} - -static void end_clock(pid_t pid) -{ - if (pm_cur_state == S_NORMAL || - pm_cur_state == S_LCDDIM || - ambient_state == false) - return; - - if (update_count == 0) - broadcast_lcd_off_late(LCD_OFF_LATE_MODE); - - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, PM_SLEEP_MARGIN); - - update_count++; - if (update_count == UINT_MAX) - update_count = 1; - ambient_pid = pid; - - _I("Enter real ambient state by process(%d).", - ambient_pid); -} - -int ambient_set_screen(char *screen, pid_t pid) -{ - if (!screen) - return -EINVAL; - - if (!strncmp(screen, CLOCK_START, strlen(CLOCK_START))) - start_clock(); - else if (!strncmp(screen, CLOCK_END, strlen(CLOCK_END))) - end_clock(pid); - - return 0; -} - -static void ambient_init(void *data) -{ - int ret; - - ret = vconf_get_bool(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - &ambient_condition); - if (ret < 0) { - _E("Failed to get vconf value for ambient mode: %d", vconf_get_ext_errno()); - ambient_condition = false; - } - _I("Ambient mode condition is %d.", ambient_condition); - - vconf_notify_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - ambient_set_condition, NULL); -} - -static void ambient_exit(void *data) -{ - ambient_set_state(false); - vconf_ignore_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - ambient_set_condition); -} - -static const struct display_ops ambient_ops = { - .name = "ambient", - .init = ambient_init, - .exit = ambient_exit, -}; - -DISPLAY_OPS_REGISTER(&ambient_ops) - diff --git a/plugins/mobile/display/display-actor.c b/plugins/mobile/display/display-actor.c deleted file mode 100644 index bab8630..0000000 --- a/plugins/mobile/display/display-actor.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include - -#include "util.h" -#include "display-actor.h" -#include "core/list.h" -#include "core/common.h" - -static dd_list *actor_head; - -void display_add_actor(struct display_actor_ops *actor) -{ - DD_LIST_APPEND(actor_head, actor); -} - -static struct display_actor_ops *display_find_actor(enum display_actor_id id) -{ - dd_list *elem; - struct display_actor_ops *actor; - - DD_LIST_FOREACH(actor_head, elem, actor) { - if (actor->id == id) - return actor; - } - return NULL; -} - -int display_set_caps(enum display_actor_id id, unsigned int caps) -{ - struct display_actor_ops *actor; - - if (id <= 0 || !caps) - return -EINVAL; - - actor = display_find_actor(id); - if (!actor) - return -EINVAL; - - actor->caps |= caps; - - return 0; -} - -int display_reset_caps(enum display_actor_id id, unsigned int caps) -{ - struct display_actor_ops *actor; - - if (id <= 0 || !caps) - return -EINVAL; - - actor = display_find_actor(id); - if (!actor) - return -EINVAL; - - actor->caps &= ~caps; - - return 0; -} - -unsigned int display_get_caps(enum display_actor_id id) -{ - struct display_actor_ops *actor; - - if (id <= 0) - return 0; - - actor = display_find_actor(id); - if (!actor) - return 0; - - return actor->caps; -} - -int display_has_caps(unsigned int total_caps, unsigned int caps) -{ - if (!total_caps || !caps) - return false; - - if ((total_caps & caps) == caps) - return true; - - return false; -} - diff --git a/plugins/mobile/display/display-dbus.c b/plugins/mobile/display/display-dbus.c deleted file mode 100644 index 308d665..0000000 --- a/plugins/mobile/display/display-dbus.c +++ /dev/null @@ -1,1168 +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. - */ - - -/** - * @file display-dbus.c - * @brief dbus interface - * - */ - -#include -#include -#include -#include -#include -#include - -#include "ambient-mode.h" -#include "core/log.h" -#include "util.h" -#include "core.h" -#include "core/common.h" -#include "core/devices.h" -#include "core/device-idler.h" -#include "apps/apps.h" -#include "dd-display.h" -#include "display-actor.h" -#include "display-ops.h" -#include - -#define SIGNAL_HOMESCREEN "HomeScreen" - -#define DUMP_MODE_WATING_TIME 600000 - -#define EXPIRED_POPUP_TYPE_POWER "power_lock_expired" -#define EXPIRED_POPUP_PID "_APP_PID_" -#define EXPIRED_POPUP_COMM "_APP_COMM_" -#define EXPIRED_POPUP_ID "_REQUEST_ID_" - -#define CHECK_POWEROFF() \ - do { \ - if (device_poweroff(NULL)) { \ - _E("Ignore requests for display during power off"); \ - return g_variant_new("(i)", -EBUSY); \ - } \ - } while (0) - -GVariant *dbus_start(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - static const struct device_ops *display_device_ops = NULL; - - if (device_poweroff(NULL)) - goto out; - - if (!display_device_ops) - display_device_ops = find_device("display"); - if (NOT_SUPPORT_OPS(display_device_ops)) - goto out; - - display_device_ops->start(CORE_LOGIC_MODE); -out: - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_stop(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - static const struct device_ops *display_device_ops = NULL; - - if (device_poweroff(NULL)) - goto out; - - if (!display_device_ops) - display_device_ops = find_device("display"); - if (NOT_SUPPORT_OPS(display_device_ops)) - goto out; - - display_device_ops->stop(CORE_LOGIC_MODE); -out: - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_lockstate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - char *option1_str; - char *option2_str; - int timeout; - pid_t pid; - int state; - int flag; - int ret = 0; - unsigned int caps; - - CHECK_POWEROFF(); - - g_variant_get(param, "(sssi)", &state_str, &option1_str, &option2_str, &timeout); - - if (!state_str || timeout < 0) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - if (!strcmp(option1_str, STAYCURSTATE_STR)) - flag = STAY_CUR_STATE; - else if (!strcmp(option1_str, GOTOSTATENOW_STR)) - flag = GOTO_STATE_NOW; - else { - _E("%s option is invalid. set default option!", option1_str); - flag = STAY_CUR_STATE; - } - - if (!strcmp(option2_str, HOLDKEYBLOCK_STR)) - flag |= HOLD_KEY_BLOCK; - - if (flag & GOTO_STATE_NOW) { - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) && - state == LCD_NORMAL) { - _D("No lcdon capability!"); - ret = -EPERM; - goto out; - } - if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) && - state == LCD_OFF) { - _D("No lcdoff capability!"); - ret = -EPERM; - goto out; - } - } - - if (check_dimstay(state, flag) == true) { - _E("LCD state can not be changed to OFF state now!"); - flag &= ~GOTO_STATE_NOW; - flag |= STAY_CUR_STATE; - } - - if (disp_plgn.pm_lock_internal) - ret = disp_plgn.pm_lock_internal(pid, state, flag, timeout); -out: - g_free(state_str); - g_free(option1_str); - g_free(option2_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_unlockstate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - char *option_str; - pid_t pid; - int state; - int flag; - int ret = 0; - - CHECK_POWEROFF(); - - g_variant_get(param, "(ss)", &state_str, &option_str); - - if (!state_str) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - if (!strcmp(option_str, SLEEP_MARGIN_STR)) - flag = PM_SLEEP_MARGIN; - else if (!strcmp(option_str, RESET_TIMER_STR)) - flag = PM_RESET_TIMER; - else if (!strcmp(option_str, KEEP_TIMER_STR)) - flag = PM_KEEP_TIMER; - else { - _E("%s option is invalid. set default option!", option_str); - flag = PM_RESET_TIMER; - } - - if (disp_plgn.pm_unlock_internal) - ret = disp_plgn.pm_unlock_internal(pid, state, flag); -out: - g_free(state_str); - g_free(option_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_changestate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - pid_t pid; - int state; - int ret = 0; - unsigned int caps; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &state_str); - - if (!state_str) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else if (!strcmp(state_str, PM_STANDBY_STR)) - state = STANDBY; - else if (!strcmp(state_str, PM_SUSPEND_STR)) - state = SUSPEND; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) && - state == LCD_NORMAL) { - _D("No lcdon capability!"); - ret = -EPERM; - goto out; - } - if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) && - state == LCD_OFF) { - _D("No lcdoff capability!"); - ret = -EPERM; - goto out; - } - - if (check_dimstay(state, GOTO_STATE_NOW) == true) { - _E("LCD state can not be changed to OFF state!"); - ret = -EBUSY; - goto out; - } - - if (disp_plgn.pm_change_internal) - ret = disp_plgn.pm_change_internal(pid, state); - - if (!ret && state == LCD_OFF) - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); -out: - g_free(state_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getdisplaycount(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - ret = DEFAULT_DISPLAY_COUNT; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getmaxbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret, state; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &state); - if (state == DISPLAY_STATE_NORMAL) - ret = DEFAULT_DISPLAY_MAX_BRIGHTNESS; - else if (state == DISPLAY_STATE_SCREEN_DIM) - ret = DEFAULT_DISPLAY_MAX_DIM_BRIGHTNESS; - else - ret = -EINVAL; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setmaxbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - ret = -ENOTSUP; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int brt = -1, state, ret; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &state); - - if (state == DISPLAY_STATE_NORMAL) - ret = backlight_ops.get_brightness(&brt); - else if (state == DISPLAY_STATE_SCREEN_DIM) { - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, &brt); - if (ret < 0) - _E("Failed to get vconf value for lcd dim brightness: %d", vconf_get_ext_errno()); - } else - ret = -EINVAL; - - if (ret >= 0) - ret = brt; - - _I("get brightness %d, %d", brt, ret); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int state, brt, autobrt, ret = 0, caps; - - CHECK_POWEROFF(); - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) { - _D("No brightness changing capability!"); - ret = -EPERM; - goto error; - } - - g_variant_get(param, "(ii)", &state, &brt); - - //Check if brt is same with DIM - if (brt == 0) { - _E("application can not set this value(DIM VALUE:%d)", brt); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - autobrt = SETTING_BRIGHTNESS_AUTOMATIC_OFF; - } - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - _E("auto_brightness state is ON, can not change the brightness value"); - ret = -EPERM; - goto error; - } - - if (state == DISPLAY_STATE_NORMAL) { - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); - } else if (state == DISPLAY_STATE_SCREEN_DIM) { - if (pm_cur_state == S_LCDDIM) { - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - } - - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd dim brightness: %d", vconf_get_ext_errno()); - } else - ret = -EINVAL; - - _I("set brightness %d, %d", brt, ret); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_holdbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int brt, autobrt, ret, caps; - - CHECK_POWEROFF(); - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) { - _D("No brightness changing capability!"); - ret = -EPERM; - goto error; - } - - g_variant_get(param, "(i)", &brt); - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - autobrt = SETTING_BRIGHTNESS_AUTOMATIC_OFF; - } - - ret = vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON); - if (ret < 0) - _E("Failed to set vconf value for custom brightness status: %d", vconf_get_ext_errno()); - - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - _D("Auto brightness will be paused"); - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_PAUSE); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - } - - _I("hold brightness %d, %d", brt, ret); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_releasebrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int bat, charger, changed, setting, brt, autobrt, ret = 0; - - CHECK_POWEROFF(); - - ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat); - if (ret < 0) { - _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charger); - if (ret < 0) { - _E("Failed to get vconf value for charger status: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_bool(VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM, &changed); - if (ret < 0) { - _E("Failed to get vconf value for brightness changed in lpm: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &setting); - if (ret < 0) { - _E("Failed to get vconf value for lcd brightness: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_OFF); - if (ret < 0) - _E("Failed to set vconf value for custom brightness status: %d", vconf_get_ext_errno()); - - ret = backlight_ops.get_brightness(&brt); - if (ret < 0) - brt = ret; - - // check dim state - if (low_battery_state(bat) && - charger == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED && !changed) { - _D("batt warning low : brightness is not changed!"); - if (brt != 0) - backlight_ops.set_brightness(0); - goto error; - } - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_OFF) { - if (brt != setting) - backlight_ops.set_brightness(setting); - } else if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) { - _D("Auto brightness will be enable"); - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_ON); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - } - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setrefreshrate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int app, val, ret, control; - - CHECK_POWEROFF(); - - g_variant_get(param, "(ii)", &app, &val); - - if (app < 0 || app >= ARRAY_SIZE(display_conf.framerate_app) || val < 0) { - ret = -EINVAL; - goto error; - } - - if (!display_conf.framerate_app[app]) { - _I("This case(%d) is not support in this target", app); - ret = -EPERM; - goto error; - } - - control = display_conf.control_display; - - if (control) - backlight_ops.off(NORMAL_MODE); - - _D("app : %d, value : %d", app, val); - ret = backlight_ops.set_frame_rate(val); - if (ret < 0) - _E("Failed to set frame rate (%d)", ret); - - if (control) - backlight_ops.on(NORMAL_MODE); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setautobrightnessmin(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int val, ret; - pid_t pid; - int id = 0; - - CHECK_POWEROFF(); - - if (!display_info.set_autobrightness_min) { - ret = -EIO; - goto error; - } - g_variant_get(param, "(i)", &val); - - pid = dbus_connection_get_sender_pid(conn, sender); - ret = display_info.set_autobrightness_min(val, (char *)sender); - if (ret) { - _W("fail to set autobrightness min %d, %d by %d", val, ret, pid); - goto error; - } - if (display_info.reset_autobrightness_min) { - id = dbus_handle_watch_name(sender, display_info.reset_autobrightness_min, NULL, NULL, NULL); - if (id <= 0) { - _E("failed to watch name %s, id %d", sender, id); - //todo: set return value - } - _I("set autobrightness min %d by %d", val, pid); - } -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setlcdtimeout(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int on, dim, holdkey_block, ret; - pid_t pid; - int id = 0; - - CHECK_POWEROFF(); - - g_variant_get(param, "(iii)", &on, &dim, &holdkey_block); - - pid = dbus_connection_get_sender_pid(conn, sender); - ret = set_lcd_timeout(on, dim, holdkey_block, sender); - if (ret) { - _W("fail to set lcd timeout %d by %d", ret, pid); - } else { - id = dbus_handle_watch_name(sender, reset_lcd_timeout, NULL, NULL, NULL); - if (id <= 0) { - _E("failed to watch name %s, id %d", sender, id); - //todo: set return value - } - _I("set lcd timeout on %d, dim %d, holdblock %d by %d", - on, dim, holdkey_block, pid); - } - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_lockscreenbgon(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - char *on = NULL; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &on); - - if (!strcmp(on, "true")) { - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_LOCK_SCREEN_BG, true); - } else if (!strcmp(on, "false")) { - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_LOCK_SCREEN_BG, false); - } else - ret = -EINVAL; - - g_free(on); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_dumpmode(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - char *on; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &on); - - if (!strcmp(on, "on")) { - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, - STAY_CUR_STATE, DUMP_MODE_WATING_TIME); - } else if (!strcmp(on, "off")) { - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, PM_SLEEP_MARGIN); - } else - ret = -EINVAL; - - g_free(on); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_savelog(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - if (!device_poweroff(NULL)) - save_display_log(); - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_powerkeyignore(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int on; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &on); - - if (CHECK_OPS(keyfilter_ops, set_powerkey_ignore)) - keyfilter_ops->set_powerkey_ignore(on == 1 ? true : false); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_powerkeylcdoff(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - if (CHECK_OPS(keyfilter_ops, powerkey_lcdoff)) - ret = keyfilter_ops->powerkey_lcdoff(); - else - ret = -ENOSYS; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_customlcdon(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int timeout; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &timeout); - - ret = custom_lcdon(timeout); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_staytouchscreenoff(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int val; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &val); - - set_stay_touchscreen_off(val); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_lcdpaneloffmode(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int val; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &val); - - set_lcd_paneloff_mode(val); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_actorcontrol(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0, val, actor; - char *op; - - CHECK_POWEROFF(); - - g_variant_get(param, "(sii)", &op, &actor, &val); - - if (!strcmp(op, "set")) - ret = display_set_caps(actor, val); - else if (!strcmp(op, "reset")) - ret = display_reset_caps(actor, val); - else - ret = -EINVAL; - - g_free(op); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getcustombrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int status = 0; - - CHECK_POWEROFF(); - - status = backlight_ops.get_custom_status(); - - return g_variant_new("(i)", status); -} - -struct pmlock_expired_s { - char req_id[32]; - GDBusMethodInvocation *invocation; - int value; - pid_t pid; -}; - -static dd_list *expired_req_list; - -static int get_command(pid_t pid, char *comm, size_t len) -{ - FILE *fp; - char path[PATH_MAX]; - char name[NAME_MAX]; - char *tmp; - int ret; - - snprintf(path, sizeof(path), "/proc/%d/comm", pid); - - fp = fopen(path, "r"); - if (!fp) { - _E("Failed to open file %s, errno:%d", path, errno); - return -errno; - } - - ret = fread(name, 1, sizeof(name) - 1, fp); - name[ret] = '\0'; - fclose(fp); - - tmp = name; - while (*tmp != '\0') { - if (*tmp == '\n' || - *tmp == '\r') { - *tmp = '\0'; - break; - } - tmp++; - } - - snprintf(comm, len, "%s", name); - - return 0; -} - -GVariant *dbus_locktimeout_expired(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - char *req_id; - pid_t pid; - char pid_str[16]; - char comm[NAME_MAX]; - struct pmlock_expired_s *ex = NULL; - GVariant *gvar = NULL; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &req_id); - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - ret = get_command(pid, comm, sizeof(comm)); - if (ret < 0) { - _E("Failed to get command (%d)", ret); - goto out; - } - - ex = calloc(1, sizeof(struct pmlock_expired_s)); - if (!ex) { - _E("calloc() failed"); - ret = -ENOMEM; - goto out; - } - - snprintf(pid_str, sizeof(pid_str), "%d", pid); - ret = launch_system_app(APP_DEFAULT, 8, - APP_KEY_TYPE, - EXPIRED_POPUP_TYPE_POWER, - EXPIRED_POPUP_PID, - pid_str, - EXPIRED_POPUP_COMM, - comm, - EXPIRED_POPUP_ID, - req_id); - if (ret < 0) { - _E("Failed to launch pmlock expired popup(%d)", ret); - goto out; - } - - ex->pid = pid; - snprintf(ex->req_id, sizeof(ex->req_id), "%s", req_id); - - ex->invocation = invocation; - - DD_LIST_APPEND(expired_req_list, ex); - - g_free(req_id); - return NULL; - -out: - gvar = g_variant_new("(i)", ret); - g_free(req_id); - if (ex) - free(ex); - return gvar; -} - -static gboolean app_term(gpointer data) -{ - struct pmlock_expired_s *ex = data; - - if (ex) { - if (kill(ex->pid, 0) != -1) - kill(ex->pid, SIGKILL); - free(ex); - } - return G_SOURCE_REMOVE; -} - -static void expired_deliver_result(void *data) -{ - struct pmlock_expired_s *ex = data; - struct pmlock_expired_s *item = NULL; - dd_list *l; - size_t len; - int value; - char *id; - - if (!ex) - return; - - len = strlen(ex->req_id) + 1; - DD_LIST_FOREACH(expired_req_list, l, item) { - if (!strncmp(item->req_id, ex->req_id, len)) { - DD_LIST_REMOVE(expired_req_list, item); - break; - } - } - if (!item) - goto out; - - id = ex->req_id; - value = ex->value; - - _I("User input of req_id(%s) is (%s)", id, value == 0 ? "ALLOW power lock" : - (value == 2) ? "KILL app" : "Release power lock"); - - if (!item->invocation) { - _E("item->invocation is null"); - goto out; - } - g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(i)", 0)); - - if (value == 2) { - kill(item->pid, SIGTERM); - g_timeout_add(3000, app_term, (gpointer)item); - item = NULL; - } - -out: - free(ex); - free(item); -} - -GVariant *dbus_locktimeout_input(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - char *req_id; - struct pmlock_expired_s *ex; - int value; - - CHECK_POWEROFF(); - - g_variant_get(param, "(si)", &req_id, &value); - - ex = calloc(1, sizeof(struct pmlock_expired_s)); - if (!ex) { - _E("calloc() failed"); - ret = -ENOMEM; - goto out; - } - - snprintf(ex->req_id, sizeof(ex->req_id), "%s", req_id); - ex->value = value; - - _I("req_id(%s), value(%d)", ex->req_id, ex->value); - - add_idle_request(expired_deliver_result, ex); - - ret = 0; - -out: - g_free(req_id); - return g_variant_new("(i)", ret); -} - -static const dbus_method_s dbus_methods[] = { - { "start", NULL, NULL, dbus_start }, - { "stop", NULL, NULL, dbus_stop }, - { "lockstate", "sssi", "i", dbus_lockstate }, - { "unlockstate", "ss", "i", dbus_unlockstate }, - { "changestate", "s", "i", dbus_changestate }, - { "ChangeState", "s", "i", dbus_changestate }, - { "getbrightness", "i", "i", dbus_getbrightness }, /* deprecated */ - { "setbrightness", "ii", "i", dbus_setbrightness }, /* deprecated */ - { "setframerate", "ii", "i", dbus_setrefreshrate }, /* deprecated */ - { "setautobrightnessmin", "i", "i", dbus_setautobrightnessmin }, - { "setlcdtimeout", "iii", "i", dbus_setlcdtimeout }, - { "LockScreenBgOn", "s", "i", dbus_lockscreenbgon }, - { "GetDisplayCount", NULL, "i", dbus_getdisplaycount }, - { "GetMaxBrightness", "i", "i", dbus_getmaxbrightness }, - { "SetMaxBrightness", "i", "i", dbus_setmaxbrightness }, - { "GetBrightness", "i", "i", dbus_getbrightness }, - { "SetBrightness", "ii", "i", dbus_setbrightness }, - { "HoldBrightness", "i", "i", dbus_holdbrightness }, - { "ReleaseBrightness", NULL, "i", dbus_releasebrightness }, - { "SetRefreshRate", "ii", "i", dbus_setrefreshrate }, - { "Dumpmode", "s", "i", dbus_dumpmode }, - { "SaveLog", NULL, NULL, dbus_savelog }, - { "PowerKeyIgnore", "i", "i", dbus_powerkeyignore }, - { "PowerKeyLCDOff", NULL, "i", dbus_powerkeylcdoff }, - { "CustomLCDOn", "i", "i", dbus_customlcdon }, - { "StayTouchScreenOff", "i", "i", dbus_staytouchscreenoff }, - { "LCDPanelOffMode", "i", "i", dbus_lcdpaneloffmode }, - { "ActorControl", "sii", "i", dbus_actorcontrol }, - { "CustomBrightness", NULL, "i", dbus_getcustombrightness }, - { "CurrentBrightness", NULL, "i", dbus_getbrightness }, /* deprecated. It is remained for tizen 2.4 */ - { "LockTimeoutExpired", "s", "i", dbus_locktimeout_expired }, - { "LockTimeoutInput", "si", "i", dbus_locktimeout_input }, - /* Add methods here */ -}; - -static const dbus_interface_u dbus_interface = { - .oh = NULL, - .name = DEVICED_INTERFACE_DISPLAY, - .methods = dbus_methods, - .nr_methods = ARRAY_SIZE(dbus_methods), -}; - -static void homescreen_signal_handler(GDBusConnection *conn, - const gchar *sender, - const gchar *path, - const gchar *iface, - const gchar *name, - GVariant *param, - gpointer data) -{ - char *screen; - pid_t pid; - - g_variant_get(param, "(s)", &screen); - - _D("screen : %s", screen); - - pid = dbus_connection_get_sender_pid(conn, sender); - ambient_set_screen(screen, pid); - g_free(screen); -} - -/* - * Default capability - * api := LCDON | LCDOFF | BRIGHTNESS - * gesture := LCDON - */ -static struct display_actor_ops display_api_actor = { - .id = DISPLAY_ACTOR_API, - .caps = DISPLAY_CAPA_LCDON | - DISPLAY_CAPA_LCDOFF | - DISPLAY_CAPA_BRIGHTNESS, -}; - -static struct display_actor_ops display_gesture_actor = { - .id = DISPLAY_ACTOR_GESTURE, - .caps = DISPLAY_CAPA_LCDON, -}; - -int init_pm_dbus(void) -{ - int ret; - - display_add_actor(&display_api_actor); - display_add_actor(&display_gesture_actor); - - ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_DISPLAY, &dbus_interface); - if (ret < 0) - _E("fail to init dbus method(%d)", ret); - - ret = subscribe_dbus_signal(NULL, - DEVICED_OBJECT_PATH, - DEVICED_INTERFACE_NAME, - SIGNAL_HOMESCREEN, - homescreen_signal_handler, - NULL, NULL); - if (ret <= 0) { - _E("Failed to register signal handler! %d", ret); - return ret; - } - - return 0; -} - diff --git a/plugins/mobile/display/display-ops.c b/plugins/mobile/display/display-ops.c deleted file mode 100644 index 22b9137..0000000 --- a/plugins/mobile/display/display-ops.c +++ /dev/null @@ -1,74 +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 "util.h" -#include "display-ops.h" -#include "core/list.h" -#include "core/common.h" - -static dd_list *disp_head; - -void add_display(const struct display_ops *disp) -{ - DD_LIST_APPEND(disp_head, disp); -} - -void remove_display(const struct display_ops *disp) -{ - DD_LIST_REMOVE(disp_head, disp); -} - -const struct display_ops *find_display_feature(const char *name) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - if (!strcmp(disp->name, name)) - return disp; - } - return NULL; -} - -void display_ops_init(void *data) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - _D("[%s] initialize", disp->name); - if (disp->init) - disp->init(data); - } -} - -void display_ops_exit(void *data) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - _D("[%s] deinitialize", disp->name); - if (disp->exit) - disp->exit(data); - } -} - diff --git a/plugins/mobile/display/input.c b/plugins/mobile/display/input.c deleted file mode 100644 index a986504..0000000 --- a/plugins/mobile/display/input.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - * 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 -#include - -#include "util.h" -#include "core.h" -#include "poll.h" - -#define SEAT_NAME "seat0" - -static struct udev *udev; -static struct libinput *li; -static guint efd; - -int (*pm_callback) (int, PMMsg *); - -static inline void process_event(struct libinput_event *ev) -{ - static const struct device_ops *display_device_ops; - struct input_event input; - struct libinput *li; - struct libinput_event_keyboard *k; - unsigned int time; - int fd; - - if (!pm_callback) - return; - - if (!display_device_ops) { - display_device_ops = find_device("display"); - if (!display_device_ops) - return; - } - - /* do not operate when display stops */ - if (device_get_status(display_device_ops) - != DEVICE_OPS_STATUS_START) { - _E("display status is stop"); - return; - } - - switch (libinput_event_get_type(ev)) { - case LIBINPUT_EVENT_DEVICE_ADDED: - return; - case LIBINPUT_EVENT_KEYBOARD_KEY: - k = libinput_event_get_keyboard_event(ev); - time = libinput_event_keyboard_get_time(k); - li = libinput_event_get_context(ev); - - input.time.tv_sec = MSEC_TO_SEC(time); - input.time.tv_usec = MSEC_TO_USEC(time % 1000); - input.type = EV_KEY; - input.code = libinput_event_keyboard_get_key(k); - input.value = libinput_event_keyboard_get_key_state(k); - - fd = libinput_get_fd(li); - _D("time %ld.%06ld type %d code %d value %d fd %d", - input.time.tv_sec, input.time.tv_usec, input.type, - input.code, input.value, fd); - - if (CHECK_OPS(keyfilter_ops, check) && - keyfilter_ops->check(&input, fd) != 0) - return; - break; - case LIBINPUT_EVENT_POINTER_MOTION: - case LIBINPUT_EVENT_POINTER_BUTTON: - case LIBINPUT_EVENT_POINTER_AXIS: - li = libinput_event_get_context(ev); - input.type = EV_REL; - - fd = libinput_get_fd(li); - _D("type %d fd %d", input.type, fd); - - if (CHECK_OPS(keyfilter_ops, check) && - keyfilter_ops->check(&input, fd) != 0) - return; - break; - case LIBINPUT_EVENT_TOUCH_DOWN: - case LIBINPUT_EVENT_TOUCH_UP: - case LIBINPUT_EVENT_TOUCH_MOTION: - case LIBINPUT_EVENT_TOUCH_FRAME: - if (touch_event_blocked()) - return ; - break; - default: - break; - } - - /* lcd on or update lcd timeout */ - (*pm_callback) (INPUT_POLL_EVENT, NULL); -} - -static gboolean input_handler(gint fd, GIOCondition cond, void *data) -{ - struct libinput_event *ev; - struct libinput *input = (struct libinput *)data; - - /* Ignore input during poweroff */ - if (device_poweroff(NULL)) - return G_SOURCE_CONTINUE; - - if (!input) - return G_SOURCE_CONTINUE; - - libinput_dispatch(input); - - while ((ev = libinput_get_event(input))) { - process_event(ev); - - libinput_event_destroy(ev); - libinput_dispatch(input); - } - - return G_SOURCE_CONTINUE; -} - -static int open_restricted(const char *path, int flags, void *user_data) -{ - int fd; - unsigned int clockid = CLOCK_MONOTONIC; - - if (!path) - return -EINVAL; - - fd = open(path, flags); - if (fd >= 0) { - /* TODO Why does fd change the clock? */ - if (ioctl(fd, EVIOCSCLOCKID, &clockid) < 0) - _E("fail to change clock %s", path); - } - - return fd < 0 ? -errno : fd; -} - -static void close_restricted(int fd, void *user_data) -{ - close(fd); -} - -static const struct libinput_interface interface = { - .open_restricted = open_restricted, - .close_restricted = close_restricted, -}; - -int init_input(void) -{ - int ret; - int fd; - - udev = udev_new(); - if (!udev) { - _E("fail to create udev library context"); - return -EPERM; - } - - li = libinput_udev_create_context(&interface, NULL, udev); - if (!li) { - _E("fail to create a new libinput context from udev"); - return -EPERM; - } - - ret = libinput_udev_assign_seat(li, SEAT_NAME); - if (ret < 0) { - _E("fail to assign a seat"); - return -EPERM; - } - - fd = libinput_get_fd(li); - if (fd < 0) { - _E("fail to get file descriptor from libinput context"); - return -EPERM; - } - - /* add to poll handler */ - efd = g_unix_fd_add(fd, G_IO_IN, - input_handler, - (void *)((intptr_t)li)); - if (!efd) { - _E("fail to g_unix_fd_add"); - /* TODO Does it really need close()? */ - close(fd); - return -EPERM; - } - - return 0; -} - -int exit_input(void) -{ - if (efd) { - g_source_remove(efd); - efd = -1; - } - /* todo: close fd */ - - if (li) - libinput_unref(li); - - if (udev) - udev_unref(udev); - - return 0; -} diff --git a/plugins/mobile/display/lock-detector.c b/plugins/mobile/display/lock-detector.c deleted file mode 100644 index 0560ef4..0000000 --- a/plugins/mobile/display/lock-detector.c +++ /dev/null @@ -1,232 +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. - */ - - -/** - * @file lock-detector.c - * @brief - * - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "util.h" -#include "core.h" -#include "core/list.h" - -struct lock_info { - unsigned long hash; - char *name; - int state; - int count; - long locktime; - long unlocktime; - long time; -}; - -#define LIMIT_COUNT 128 - -static dd_list *lock_info_list; - -static long get_time(void) -{ - struct timeval now; - gettimeofday(&now, NULL); - return (long)(now.tv_sec * 1000 + now.tv_usec / 1000); -} - -static void shrink_lock_info_list(void) -{ - dd_list *l, *l_prev; - struct lock_info *info; - unsigned int count; - - count = DD_LIST_LENGTH(lock_info_list); - if (count <= LIMIT_COUNT) - return; - _D("list is shrink : count %d", count); - - DD_LIST_REVERSE_FOREACH_SAFE(lock_info_list, l, l_prev, info) { - if (info->locktime == 0) { - DD_LIST_REMOVE_LIST(lock_info_list, l); - if (info->name) - free(info->name); - free(info); - count--; - } - if (count <= (LIMIT_COUNT / 2)) - break; - } -} - -int set_lock_time(const char *pname, int state) -{ - struct lock_info *info; - dd_list *l; - unsigned long val; - - if (!pname) - return -EINVAL; - - if (state < S_NORMAL || state > S_SLEEP) - return -EINVAL; - - val = g_str_hash(pname); - - 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; - DD_LIST_REMOVE(lock_info_list, info); - DD_LIST_PREPEND(lock_info_list, info); - return 0; - } - - info = malloc(sizeof(struct lock_info)); - if (!info) { - _E("Malloc is failed for lock_info!"); - return -ENOMEM; - } - - info->hash = val; - info->name = strndup(pname, strlen(pname)); - info->state = state; - info->count = 1; - info->locktime = get_time(); - info->unlocktime = 0; - info->time = 0; - - DD_LIST_APPEND(lock_info_list, info); - - return 0; -} - -int set_unlock_time(const char *pname, int state) -{ - bool find = false; - long diff; - struct lock_info *info; - dd_list *l; - unsigned long val; - - if (!pname) - return -EINVAL; - - if (state < S_NORMAL || state > S_SLEEP) - return -EINVAL; - - val = g_str_hash(pname); - - 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; - } - - if (!find) - return -EINVAL; - - if (info->locktime == 0) - return -EINVAL; - - /* update time */ - info->unlocktime = get_time(); - diff = info->unlocktime - info->locktime; - if (diff > 0) - info->time += diff; - info->locktime = 0; - - if (DD_LIST_LENGTH(lock_info_list) > LIMIT_COUNT) - shrink_lock_info_list(); - - return 0; -} - -void free_lock_info_list(void) -{ - dd_list *l, *l_next; - struct lock_info *info; - - if (!lock_info_list) - return; - - 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); - } - lock_info_list = NULL; -} - -void print_lock_info_list(int fd) -{ - struct lock_info *info; - dd_list *l; - char buf[255]; - int ret; - - if (!lock_info_list) - return; - - snprintf(buf, sizeof(buf), - "current time : %ld ms\n", get_time()); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - - snprintf(buf, sizeof(buf), - "[%10s %6s] %6s %10s %10s %10s %s\n", "hash", "state", - "count", "locktime", "unlocktime", "time", "process name"); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - - DD_LIST_FOREACH(lock_info_list, l, info) { - long time = 0; - if (info->locktime != 0 && info->unlocktime == 0) - time = get_time() - info->locktime; - snprintf(buf, sizeof(buf), - "[%10lu %6d] %6d %10ld %10ld %10ld %s\n", - info->hash, - info->state, - info->count, - info->locktime, - info->unlocktime, - info->time + time, - info->name); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - } -} - diff --git a/plugins/mobile/display/poll.c b/plugins/mobile/display/poll.c deleted file mode 100644 index ee0471d..0000000 --- a/plugins/mobile/display/poll.c +++ /dev/null @@ -1,174 +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. - */ - - -/** - * @file poll.c - * @brief Power Manager poll implementation - * - */ - -#include -#include "util.h" -#include "core.h" -#include "poll.h" -#include "display/display-ops.h" - -#define SHIFT_UNLOCK 4 -#define SHIFT_UNLOCK_PARAMETER 12 -#define SHIFT_CHANGE_STATE 8 -#define SHIFT_CHANGE_TIMEOUT 20 -#define LOCK_FLAG_SHIFT 16 -#define __HOLDKEY_BLOCK_BIT 0x1 -#define HOLDKEY_BLOCK_BIT (__HOLDKEY_BLOCK_BIT << LOCK_FLAG_SHIFT) - -static PMMsg recv_data; - -int check_dimstay(int next_state, int flag) -{ - if (next_state != LCD_OFF) - return false; - - if (!(flag & GOTO_STATE_NOW)) - return false; - - if (!(pm_status_flag & DIMSTAY_FLAG)) - return false; - - return true; -} - -static enum state_t get_state(int s_bits) -{ - switch (s_bits) { - case LCD_NORMAL: - return S_NORMAL; - case LCD_DIM: - return S_LCDDIM; - case LCD_OFF: - return S_LCDOFF; - case STANDBY: - return S_STANDBY; - case SUSPEND: - return S_SLEEP; - default: - return -EINVAL; - } -} - -static bool state_supported(enum state_t st) -{ - if (states[st].trans) - return true; - return false; -} - -static int __pm_lock_internal(pid_t pid, int s_bits, int flag, int timeout) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_LOCK); - - if (flag & GOTO_STATE_NOW) - /* if the flag is true, go to the locking state directly */ - cond = SET_COND_FLAG(cond, PM_REQUEST_CHANGE); - - if (flag & HOLD_KEY_BLOCK) - cond = SET_COND_FLAG(cond, PM_FLAG_BLOCK_HOLDKEY); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = timeout; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -static int __pm_unlock_internal(pid_t pid, int s_bits, int flag) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_UNLOCK); - - if (flag & PM_KEEP_TIMER) - cond = SET_COND_FLAG(cond, PM_FLAG_KEEP_TIMER); - - if (flag & PM_RESET_TIMER) - cond = SET_COND_FLAG(cond, PM_FLAG_RESET_TIMER); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = 0; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -static int __pm_change_internal(pid_t pid, int s_bits) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_CHANGE); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = 0; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -void init_pm_internal() -{ - disp_plgn.pm_lock_internal = __pm_lock_internal; - disp_plgn.pm_unlock_internal = __pm_unlock_internal; - disp_plgn.pm_change_internal = __pm_change_internal; -} diff --git a/plugins/mobile/display/setting.c b/plugins/mobile/display/setting.c deleted file mode 100644 index b109d8c..0000000 --- a/plugins/mobile/display/setting.c +++ /dev/null @@ -1,271 +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 "ambient-mode.h" -#include "core.h" -#include "util.h" -#include "setting.h" -#include "display-ops.h" - -#define LCD_DIM_RATIO 0.3 -#define LCD_MAX_DIM_TIMEOUT 7000 -#define LCD_MIN_DIM_TIMEOUT 500 - -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_POWER_CUSTOM_BRIGHTNESS] = VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, -}; - -static int lock_screen_state = VCONFKEY_IDLE_UNLOCK; -static bool lock_screen_bg_state = false; -static int force_lcdtimeout = 0; -static int custom_on_timeout = 0; -static int custom_normal_timeout = 0; -static int custom_dim_timeout = 0; - -static void display_state_send_system_event(int state) -{ - bundle *b; - const char *str; - - if (state == S_NORMAL) - str = EVT_VAL_DISPLAY_NORMAL; - else if (state == S_LCDDIM) - str = EVT_VAL_DISPLAY_DIM; - else if (state == S_LCDOFF) - str = EVT_VAL_DISPLAY_OFF; - else - return; - - _I("eventsystem (%s)", str); - - b = bundle_create(); - bundle_add_str(b, EVT_KEY_DISPLAY_STATE, str); - eventsystem_send_system_event(SYS_EVENT_DISPLAY_STATE, b); - bundle_free(b); -} - -int set_force_lcdtimeout(int timeout) -{ - if (timeout < 0) - return -EINVAL; - - force_lcdtimeout = timeout; - - return 0; -} - -int __get_lock_screen_state(void) -{ - return lock_screen_state; -} - -void set_lock_screen_state(int state) -{ - switch (state) { - case VCONFKEY_IDLE_LOCK: - case VCONFKEY_IDLE_UNLOCK: - lock_screen_state = state; - break; - default: - lock_screen_state = VCONFKEY_IDLE_UNLOCK; - } -} - -int get_lock_screen_bg_state(void) -{ - return lock_screen_bg_state; -} - -void set_lock_screen_bg_state(bool state) -{ - _I("state is %d", state); - lock_screen_bg_state = state; -} - -int set_setting_pmstate(int val) -{ - static int old = -1; - int ret; - - if (old == val) - return 0; - old = val; - - display_state_send_system_event(val); - ret = vconf_set_int(VCONFKEY_PM_STATE, val); - if (ret < 0) - _E("Failed to set vconf value for pm state: %d", vconf_get_ext_errno()); - - return ret; -} - -int get_setting_brightness(int *level) -{ - int ret; - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, level); - if (ret < 0) - _E("Failed to get vconf value for lcd brightness: %d", vconf_get_ext_errno()); - - return ret; -} - -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; - } - - if (ambient_get_condition() == true) { - *dim_timeout = LCD_MIN_DIM_TIMEOUT; - return; - } - - ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout); - if (ret < 0) { - _E("Failed to get vconf value for setting timeout: %d", vconf_get_ext_errno()); - vconf_timeout = DEFAULT_NORMAL_TIMEOUT; - } - - if (force_lcdtimeout > 0) - on_timeout = SEC_TO_MSEC(force_lcdtimeout); - else - on_timeout = SEC_TO_MSEC(vconf_timeout); - - val = (double)on_timeout * LCD_DIM_RATIO; - if (val > LCD_MAX_DIM_TIMEOUT) - val = LCD_MAX_DIM_TIMEOUT; - - *dim_timeout = val; -} - -void get_run_timeout(int *timeout) -{ - int dim_timeout = -1; - int vconf_timeout = -1; - int on_timeout; - int ret; - - if (custom_normal_timeout > 0) { - *timeout = custom_normal_timeout; - return; - } - - ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout); - if (ret < 0) { - _E("Failed to get vconf value for setting timeout: %d", vconf_get_ext_errno()); - vconf_timeout = DEFAULT_NORMAL_TIMEOUT; - } - - if (force_lcdtimeout > 0) - on_timeout = SEC_TO_MSEC(force_lcdtimeout); - else - on_timeout = SEC_TO_MSEC(vconf_timeout); - - if (on_timeout == 0) { - *timeout = on_timeout; - return; - } - - get_dim_timeout(&dim_timeout); - *timeout = on_timeout - dim_timeout; -} - -int set_custom_lcdon_timeout(int timeout) -{ - int changed = (custom_on_timeout == timeout ? false : true); - - custom_on_timeout = timeout; - - if (timeout <= 0) { - custom_normal_timeout = 0; - custom_dim_timeout = 0; - return changed; - } - - custom_dim_timeout = (double)timeout * LCD_DIM_RATIO; - custom_normal_timeout = timeout - custom_dim_timeout; - - _I("custom normal(%d), dim(%d)", custom_normal_timeout, - custom_dim_timeout); - - return changed; -} - -static int setting_cb(keynode_t *key_nodes, void *data) -{ - keynode_t *tmp = key_nodes; - int index; - - index = (int)((intptr_t)data); - if (index > SETTING_END) { - _E("Unknown setting key: %s, idx=%d", - vconf_keynode_get_name(tmp), index); - return -1; - } - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(index, vconf_keynode_get_int(tmp)); - - return 0; -} - -int init_setting(int (*func) (int key_idx, int val)) -{ - int i; - - if (func != NULL) - disp_plgn.update_pm_setting = func; - - for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) { - /* - * To pass an index data through the vconf infratstructure - * without memory allocation, an index data becomes typecast - * to proper pointer size on each architecture. - */ - vconf_notify_key_changed(setting_keys[i], (void *)setting_cb, - (void *)((intptr_t)i)); - } - - disp_plgn.get_lock_screen_state = __get_lock_screen_state; - - return 0; -} - -int exit_setting(void) -{ - int i; - for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) - vconf_ignore_key_changed(setting_keys[i], (void *)setting_cb); - - return 0; -} - diff --git a/plugins/tv/display/ambient-mode.c b/plugins/tv/display/ambient-mode.c deleted file mode 100644 index b15fd56..0000000 --- a/plugins/tv/display/ambient-mode.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2017 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 "util.h" -#include "core.h" -#include "display-ops.h" -#include "core/device-notifier.h" -#include "core/devices.h" - -#define ON "on" -#define OFF "off" - -#define SIGNAL_AMBIENT_MODE "AmbientMode" -#define CLOCK_START "clockstart" -#define CLOCK_END "clockend" -#define TIMEOUT_NONE (-1) -#define AMBIENT_CLOCK_WAITING_TIME 5000 /* ms */ - -static int ambient_state; -static pid_t ambient_pid; /* Ambient Clock pid */ -static int ambient_condition; -static unsigned int update_count; - -void broadcast_ambient_state(int state) -{ - int ret; - - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, - DEVICED_INTERFACE_DISPLAY, - SIGNAL_AMBIENT_MODE, - g_variant_new("(i)", (state == 0 ? 0 : 1))); - if (ret < 0) - _E("Failed to send dbus signal(%s)", SIGNAL_AMBIENT_MODE); -} - -int ambient_get_condition(void) -{ - return ambient_condition; -} - -int ambient_get_state(void) -{ - return ambient_state; -} - -static void ambient_set_condition(keynode_t *key_nodes, void *data) -{ - int state; - - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - - ambient_condition = vconf_keynode_get_bool(key_nodes); - _I("Ambient mode condition is %d.", ambient_condition); - - state = (ambient_condition == 0 ? 0 : 1); - device_notify(DEVICE_NOTIFIER_DISPLAY_AMBIENT_CONDITION, (void *)&state); - - set_dim_state(state); -} - -int ambient_set_state(int on) -{ - if (!ambient_condition) - return 0; - - broadcast_ambient_state(on); - - update_count = 0; - - if (!on) - ambient_pid = 0; - - _D("AMBIENT is %s.", (on ? ON : OFF)); - - ambient_state = on; - - device_notify(DEVICE_NOTIFIER_DISPLAY_AMBIENT_STATE, (void *)&ambient_state); - - return 0; -} - -void ambient_check_invalid_state(pid_t pid) -{ - if (pid != INTERNAL_LOCK_AMBIENT) - return; - - if (backlight_ops.get_lcd_power() == DPMS_OFF) - return; - - if (is_emulator()) { - /* In emulator, deviced does not turn off the display. */ - if (backlight_ops.get_lcd_power() == DPMS_ON) - return; - } - - if (ambient_get_state() == false) - return; - - _E("Invalid state. Ambient state is change to off."); - - /* If lcd_power is on and ambient state is true - * when pm state is changed to sleep, - * deviced doesn't get the clock signal. - * deviced just turns off lcd in this case. */ - - ambient_set_state(false); - backlight_ops.off(NORMAL_MODE); -} - -static void start_clock(void) -{ - if (pm_cur_state == S_NORMAL || - pm_cur_state == S_LCDDIM || - ambient_state == false) - return; - - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, STAY_CUR_STATE, - AMBIENT_CLOCK_WAITING_TIME); -} - -static void end_clock(pid_t pid) -{ - if (pm_cur_state == S_NORMAL || - pm_cur_state == S_LCDDIM || - ambient_state == false) - return; - - if (update_count == 0) - broadcast_lcd_off_late(LCD_OFF_LATE_MODE); - - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, PM_SLEEP_MARGIN); - - update_count++; - if (update_count == UINT_MAX) - update_count = 1; - ambient_pid = pid; - - _I("Enter real ambient state by process(%d).", - ambient_pid); -} - -int ambient_set_screen(char *screen, pid_t pid) -{ - if (!screen) - return -EINVAL; - - if (!strncmp(screen, CLOCK_START, strlen(CLOCK_START))) - start_clock(); - else if (!strncmp(screen, CLOCK_END, strlen(CLOCK_END))) - end_clock(pid); - - return 0; -} - -static void ambient_init(void *data) -{ - int ret; - - ret = vconf_get_bool(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - &ambient_condition); - if (ret < 0) { - _E("Failed to get vconf value for ambient mode: %d", vconf_get_ext_errno()); - ambient_condition = false; - } - _I("Ambient mode condition is %d.", ambient_condition); - - vconf_notify_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - ambient_set_condition, NULL); -} - -static void ambient_exit(void *data) -{ - ambient_set_state(false); - vconf_ignore_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - ambient_set_condition); -} - -static const struct display_ops ambient_ops = { - .name = "ambient", - .init = ambient_init, - .exit = ambient_exit, -}; - -DISPLAY_OPS_REGISTER(&ambient_ops) - diff --git a/plugins/tv/display/auto-brightness.c b/plugins/tv/display/auto-brightness.c deleted file mode 100644 index ed957cd..0000000 --- a/plugins/tv/display/auto-brightness.c +++ /dev/null @@ -1,682 +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 "util.h" -#include "core.h" -#include "display-ops.h" -#include "device-node.h" -#include "setting.h" -#include "core/device-notifier.h" -#include "core/config-parser.h" - -#define METHOD_CHECK_SUPPORTED "CheckSupported" - -#define DISP_FORCE_SHIFT 12 -#define DISP_FORCE_CMD(prop, force) (((force) << DISP_FORCE_SHIFT) | prop) - -#define SAMPLING_INTERVAL 1 /* 1 sec */ -#define MAX_SAMPLING_COUNT 3 -#define MAX_FAULT 5 -#define DEFAULT_AUTOMATIC_BRT 5 -#define AUTOMATIC_DEVIDE_VAL 10 -#define AUTOMATIC_DELAY_TIME 500 /* 0.5 sec */ - -#define RADIAN_VALUE (57.2957) -#define ROTATION_90 90 -#define WORKING_ANGLE_MIN 0 -#define WORKING_ANGLE_MAX 20 - -#define BOARD_CONF_FILE "/etc/deviced/display.conf" - -#define ON_LUX -1 -#define OFF_LUX -1 -#define ON_COUNT 1 -#define OFF_COUNT 1 - -static int (*_default_action) (int); -static guint alc_timeout_id = 0; -static guint update_timeout; -static sensor_listener_h light_listener; -static sensor_listener_h accel_listener; -static int fault_count; -static int automatic_brt = DEFAULT_AUTOMATIC_BRT; -static int min_brightness = PM_MIN_BRIGHTNESS; -static char *min_brightness_name = 0; - -/* light sensor */ -static float lmax, lmin; - -static bool update_working_position(void) -{ - sensor_event_s data; - int ret; - float x, y, z, pitch, realg; - - if (!display_conf.accel_sensor_on) - return false; - - ret = sensor_listener_read_data(accel_listener, &data); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get accelerometer data: %d", ret); - return true; - } - - x = data.values[0]; - y = data.values[1]; - z = data.values[2]; - - realg = (float)sqrt((x * x) + (y * y) + (z * z)); - pitch = ROTATION_90 - abs((int) (asin(z / realg) * RADIAN_VALUE)); - - _D("Accel data x=%f y=%f z=%f pitch=%f", x, y, z, pitch); - - if (pitch >= WORKING_ANGLE_MIN && pitch <= WORKING_ANGLE_MAX) - return true; - return false; -} - -static void alc_set_brightness(int setting, int value, float light) -{ - static float old; - int position, tmp_value = 0, ret; - - ret = backlight_ops.get_brightness(&tmp_value); - if (ret < 0) { - _E("Failed to get display brightness."); - return; - } - - if (value < min_brightness) - value = min_brightness; - - if (tmp_value != value) { - if (!setting && min_brightness == PM_MIN_BRIGHTNESS && - display_conf.accel_sensor_on == true) { - position = update_working_position(); - if (!position && (old > light)) { - _D("It's not working position, " - "LCD isn't getting dark."); - return; - } - } - int diff, step; - - diff = value - tmp_value; - if (abs(diff) < display_conf.brightness_change_step) - step = (diff > 0 ? 1 : -1); - else - step = (int)ceil(diff / - (float)display_conf.brightness_change_step); - - _D("%d", step); - while (tmp_value != value) { - if (step == 0) break; - - tmp_value += step; - if ((step > 0 && tmp_value > value) || - (step < 0 && tmp_value < value)) - tmp_value = value; - - backlight_ops.set_default_brt(tmp_value); - backlight_ops.update(); - } - _I("Load light data(%f). auto brt=%d min brightness=%d " - "brightness=%d", light, automatic_brt, min_brightness, value); - old = light; - } -} - -static bool check_brightness_changed(int value) -{ - int i; - static int values[MAX_SAMPLING_COUNT], count = 0; - - if (count >= MAX_SAMPLING_COUNT || count < 0) - count = 0; - - values[count++] = value; - - for (i = 0; i < MAX_SAMPLING_COUNT - 1; i++) - if (values[i] != values[i+1]) - return false; - return true; -} - -static bool alc_update_brt(bool setting) -{ - int value = 0; - int ret = -1; - sensor_event_s light_data; - int index; - float light; - - ret = sensor_listener_read_data(light_listener, &light_data); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to read light sensor data: %d", ret); - goto out; - } - - index = light_data.value_count - 1; - if (index < 0 || light_data.values[index] < 0) { - _E("Invalid light sensor data."); - goto out; - } - - light = light_data.values[index]; - ret = backlight_ops.get_brightness_by_light_sensor( - lmax, lmin, light, &value); - if (ret == -ENOTSUP) { - _E("Not supported to handle the light data."); - goto out; - } - - if (ret < 0 || value < PM_MIN_BRIGHTNESS || value > PM_MAX_BRIGHTNESS) { - _E("Failed to load light data. light=%f value=%d: %d", light, value, ret); - goto out; - } - - fault_count = 0; - - if (display_conf.continuous_sampling && - !check_brightness_changed(value) && - !setting) - return true; - - alc_set_brightness(setting, value, light); - - return true; - -out: - fault_count++; - - if ((fault_count > MAX_FAULT) && !(pm_status_flag & PWROFF_FLAG)) { - if (alc_timeout_id) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - SETTING_BRIGHTNESS_AUTOMATIC_OFF); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - _E("Fault counts is over %d, disable automatic brightness.", MAX_FAULT); - return false; - } - return true; -} - -static gboolean alc_handler(void *data) -{ - if (pm_cur_state != S_NORMAL) { - if (alc_timeout_id > 0) - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - return G_SOURCE_REMOVE; - } - - if (!alc_update_brt(false)) - return G_SOURCE_REMOVE; - - if (alc_timeout_id != 0) - return G_SOURCE_CONTINUE; - - return G_SOURCE_REMOVE; -} - -static int alc_action(int timeout) -{ - /* sampling timer add */ - if (alc_timeout_id == 0 && !(pm_status_flag & PWRSV_FLAG)) { - display_info.update_auto_brightness(true); - - alc_timeout_id = - g_timeout_add_seconds(display_conf.lightsensor_interval, - alc_handler, NULL); - } - - if (_default_action != NULL) - return _default_action(timeout); - - /* unreachable code */ - return -1; -} - -static int connect_sensor(void) -{ - int ret; - sensor_h sensor; - sensor_h *list = NULL; - int cnt = 0; - - _I("Connect with sensor fw."); - /* light sensor */ - ret = sensor_get_sensor_list(SENSOR_LIGHT, &list, &cnt); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor list: %d", ret); - goto error; - } - - /* TODO - * Sensor apis will be fixed - * to provide which sensor is effective among sensors */ - if (cnt == 3) /* three light sensors exist */ - sensor = list[2]; - else - sensor = list[0]; - - free(list); - - ret = sensor_get_min_range(sensor, &lmin); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor min range: %d", ret); - goto error; - } - ret = sensor_get_max_range(sensor, &lmax); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor max range: %d", ret); - goto error; - } - _I("Light sensor min=%f max=%f", lmin, lmax); - - ret = sensor_create_listener(sensor, &light_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to create listener(light)."); - goto error; - } - sensor_listener_set_option(light_listener, SENSOR_OPTION_ALWAYS_ON); - ret = sensor_listener_start(light_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to start light sensor."); - sensor_destroy_listener(light_listener); - light_listener = 0; - goto error; - } - - if (!display_conf.accel_sensor_on) - goto success; - - /* accelerometer sensor */ - ret = sensor_get_default_sensor(SENSOR_ACCELEROMETER, &sensor); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get default accel sensor."); - goto error; - } - ret = sensor_create_listener(&sensor, &accel_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to create listener(accel)."); - goto error; - } - sensor_listener_set_option(accel_listener, SENSOR_OPTION_ALWAYS_ON); - ret = sensor_listener_start(accel_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to start accel sensor."); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - goto error; - } - -success: - fault_count = 0; - return 0; - -error: - if (light_listener > 0) { - sensor_listener_stop(light_listener); - sensor_destroy_listener(light_listener); - light_listener = 0; - } - if (display_conf.accel_sensor_on && accel_listener > 0) { - sensor_listener_stop(accel_listener); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - } - return -EIO; -} - -static int disconnect_sensor(void) -{ - _I("Disconnect with sensor fw."); - /* light sensor*/ - if (light_listener > 0) { - sensor_listener_stop(light_listener); - sensor_destroy_listener(light_listener); - light_listener = 0; - } - - /* accelerometer sensor*/ - if (display_conf.accel_sensor_on && accel_listener > 0) { - sensor_listener_stop(accel_listener); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - } - - if (_default_action != NULL) { - states[S_NORMAL].action = _default_action; - _default_action = NULL; - } - if (alc_timeout_id > 0) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - - return 0; -} - -void set_brightness_changed_state(void) -{ - if (pm_status_flag & PWRSV_FLAG) { - pm_status_flag |= BRTCH_FLAG; - _D("Brightness changed in low battery," - "escape dim state (light)."); - } -} - -static int set_autobrightness_state(int status) -{ - int ret = -1; - int brt = -1; - int default_brt = -1; - - if (status == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - if (connect_sensor() < 0) - return -1; - - /* escape dim state if it's in low battery.*/ - set_brightness_changed_state(); - - /* change alc action func */ - if (_default_action == NULL) - _default_action = states[S_NORMAL].action; - states[S_NORMAL].action = alc_action; - - display_info.update_auto_brightness(true); - - alc_timeout_id = - g_timeout_add_seconds(display_conf.lightsensor_interval, - alc_handler, NULL); - } else if (status == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) { - _I("Auto brightness paused."); - disconnect_sensor(); - } else { - disconnect_sensor(); - /* escape dim state if it's in low battery.*/ - set_brightness_changed_state(); - - ret = get_setting_brightness(&default_brt); - if (ret != 0 || (default_brt < PM_MIN_BRIGHTNESS || default_brt > PM_MAX_BRIGHTNESS)) { - _I("Failed to read vconf value for brightness."); - brt = PM_DEFAULT_BRIGHTNESS; - if (default_brt < PM_MIN_BRIGHTNESS || default_brt > PM_MAX_BRIGHTNESS) { - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); - } - default_brt = brt; - } - - backlight_ops.set_default_brt(default_brt); - backlight_ops.update(); - } - - return 0; -} - -static void set_alc_function(keynode_t *key_nodes, void *data) -{ - int status, ret; - - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - - status = vconf_keynode_get_int(key_nodes); - - switch (status) { - case SETTING_BRIGHTNESS_AUTOMATIC_OFF: - case SETTING_BRIGHTNESS_AUTOMATIC_ON: - case SETTING_BRIGHTNESS_AUTOMATIC_PAUSE: - ret = set_autobrightness_state(status); - _D("Set auto brightness: %d", ret); - break; - default: - _E("Invalid value(%d)", status); - } -} - -static void set_alc_automatic_brt(keynode_t *key_nodes, void *data) -{ - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - automatic_brt = vconf_keynode_get_int(key_nodes) / AUTOMATIC_DEVIDE_VAL; - _D("Automatic brt(%d)", automatic_brt); - - alc_update_brt(true); -} - -static gboolean update_handler(void *data) -{ - int ret, on; - - update_timeout = 0; - - if (pm_cur_state != S_NORMAL) - return G_SOURCE_REMOVE; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &on); - if (ret < 0 || on != SETTING_BRIGHTNESS_AUTOMATIC_ON) { - if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - return G_SOURCE_REMOVE; - } - - _D("Auto brightness is working."); - alc_update_brt(true); - - return G_SOURCE_REMOVE; -} - -static void update_auto_brightness(bool update) -{ - if (update_timeout) { - g_source_remove(update_timeout); - update_timeout = 0; - } - - if (update) { - update_timeout = g_timeout_add(AUTOMATIC_DELAY_TIME, - update_handler, NULL); - } -} - -static int prepare_lsensor(void *data) -{ - int status, ret; - int brt = -1; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &status); - - if (ret == 0 && status == SETTING_BRIGHTNESS_AUTOMATIC_ON) - set_autobrightness_state(status); - else if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - - /* add auto_brt_setting change handler */ - vconf_notify_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - set_alc_function, NULL); - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, &brt); - if (ret < 0) - _E("Failed to get vconf value for automatic lcd brightness: %d", vconf_get_ext_errno()); - - if (brt < PM_MIN_BRIGHTNESS || brt > PM_MAX_BRIGHTNESS) { - _E("Failed to get automatic brightness."); - } else { - automatic_brt = brt / AUTOMATIC_DEVIDE_VAL; - _I("Automatic brt(%d) init success." , automatic_brt); - } - - vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, - set_alc_automatic_brt, NULL); - - return 0; -} - -static void update_brightness_direct(void) -{ - int ret, status; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &status); - if (ret == 0 && status == SETTING_BRIGHTNESS_AUTOMATIC_ON) - alc_update_brt(true); - else if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); -} - -static int set_autobrightness_min(int val, char *name) -{ - if (!name) - return -EINVAL; - - if (val < PM_MIN_BRIGHTNESS || val > PM_MAX_BRIGHTNESS) - return -EINVAL; - - min_brightness = val; - - if (min_brightness_name) { - free(min_brightness_name); - min_brightness_name = 0; - } - min_brightness_name = strndup(name, strlen(name)); - - update_brightness_direct(); - - _I("Auto brightness min value changed. min_brightness=%d min_brightness_name=%s", - min_brightness, min_brightness_name); - - return 0; -} - -static void reset_autobrightness_min(GDBusConnection *conn, - const gchar *sender, - const gchar *unique_name, - gpointer data) -{ - if (!sender) - return; - - if (!min_brightness_name) - return; - - if (strcmp(sender, min_brightness_name)) - return; - - _I("Change to default min brightness. before=%d changed=%d brightness_name=%s", min_brightness, - PM_MIN_BRIGHTNESS, min_brightness_name); - min_brightness = PM_MIN_BRIGHTNESS; - if (min_brightness_name) { - free(min_brightness_name); - min_brightness_name = 0; - } - - update_brightness_direct(); -} - -static int lcd_changed_cb(void *data) -{ - int lcd_state; - - if (!data) - return 0; - lcd_state = *(int *)data; - if (lcd_state == S_LCDOFF && alc_timeout_id > 0) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - - return 0; -} - -static int booting_done_cb(void *data) -{ - int state; - - if (!data) - return 0; - - state = *(int *)data; - if (state != true) - return 0; - - /* get light data from sensor fw */ - prepare_lsensor(NULL); - - return 0; -} - -static void exit_lsensor(void) -{ - vconf_ignore_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - set_alc_function); - - vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, - set_alc_automatic_brt); - - set_autobrightness_state(SETTING_BRIGHTNESS_AUTOMATIC_OFF); -} - -static void auto_brightness_init(void *data) -{ - display_info.update_auto_brightness = update_auto_brightness; - display_info.set_autobrightness_min = set_autobrightness_min; - display_info.reset_autobrightness_min = reset_autobrightness_min; - - register_notifier(DEVICE_NOTIFIER_LCD, lcd_changed_cb); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); -} - -static void auto_brightness_exit(void *data) -{ - exit_lsensor(); - - unregister_notifier(DEVICE_NOTIFIER_LCD, lcd_changed_cb); - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); -} - -static const struct display_ops display_autobrightness_ops = { - .name = "auto-brightness", - .init = auto_brightness_init, - .exit = auto_brightness_exit, -}; - -DISPLAY_OPS_REGISTER(&display_autobrightness_ops) - diff --git a/plugins/tv/display/display-actor.c b/plugins/tv/display/display-actor.c deleted file mode 100644 index bab8630..0000000 --- a/plugins/tv/display/display-actor.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include - -#include "util.h" -#include "display-actor.h" -#include "core/list.h" -#include "core/common.h" - -static dd_list *actor_head; - -void display_add_actor(struct display_actor_ops *actor) -{ - DD_LIST_APPEND(actor_head, actor); -} - -static struct display_actor_ops *display_find_actor(enum display_actor_id id) -{ - dd_list *elem; - struct display_actor_ops *actor; - - DD_LIST_FOREACH(actor_head, elem, actor) { - if (actor->id == id) - return actor; - } - return NULL; -} - -int display_set_caps(enum display_actor_id id, unsigned int caps) -{ - struct display_actor_ops *actor; - - if (id <= 0 || !caps) - return -EINVAL; - - actor = display_find_actor(id); - if (!actor) - return -EINVAL; - - actor->caps |= caps; - - return 0; -} - -int display_reset_caps(enum display_actor_id id, unsigned int caps) -{ - struct display_actor_ops *actor; - - if (id <= 0 || !caps) - return -EINVAL; - - actor = display_find_actor(id); - if (!actor) - return -EINVAL; - - actor->caps &= ~caps; - - return 0; -} - -unsigned int display_get_caps(enum display_actor_id id) -{ - struct display_actor_ops *actor; - - if (id <= 0) - return 0; - - actor = display_find_actor(id); - if (!actor) - return 0; - - return actor->caps; -} - -int display_has_caps(unsigned int total_caps, unsigned int caps) -{ - if (!total_caps || !caps) - return false; - - if ((total_caps & caps) == caps) - return true; - - return false; -} - diff --git a/plugins/tv/display/display-dbus.c b/plugins/tv/display/display-dbus.c deleted file mode 100644 index 308d665..0000000 --- a/plugins/tv/display/display-dbus.c +++ /dev/null @@ -1,1168 +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. - */ - - -/** - * @file display-dbus.c - * @brief dbus interface - * - */ - -#include -#include -#include -#include -#include -#include - -#include "ambient-mode.h" -#include "core/log.h" -#include "util.h" -#include "core.h" -#include "core/common.h" -#include "core/devices.h" -#include "core/device-idler.h" -#include "apps/apps.h" -#include "dd-display.h" -#include "display-actor.h" -#include "display-ops.h" -#include - -#define SIGNAL_HOMESCREEN "HomeScreen" - -#define DUMP_MODE_WATING_TIME 600000 - -#define EXPIRED_POPUP_TYPE_POWER "power_lock_expired" -#define EXPIRED_POPUP_PID "_APP_PID_" -#define EXPIRED_POPUP_COMM "_APP_COMM_" -#define EXPIRED_POPUP_ID "_REQUEST_ID_" - -#define CHECK_POWEROFF() \ - do { \ - if (device_poweroff(NULL)) { \ - _E("Ignore requests for display during power off"); \ - return g_variant_new("(i)", -EBUSY); \ - } \ - } while (0) - -GVariant *dbus_start(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - static const struct device_ops *display_device_ops = NULL; - - if (device_poweroff(NULL)) - goto out; - - if (!display_device_ops) - display_device_ops = find_device("display"); - if (NOT_SUPPORT_OPS(display_device_ops)) - goto out; - - display_device_ops->start(CORE_LOGIC_MODE); -out: - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_stop(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - static const struct device_ops *display_device_ops = NULL; - - if (device_poweroff(NULL)) - goto out; - - if (!display_device_ops) - display_device_ops = find_device("display"); - if (NOT_SUPPORT_OPS(display_device_ops)) - goto out; - - display_device_ops->stop(CORE_LOGIC_MODE); -out: - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_lockstate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - char *option1_str; - char *option2_str; - int timeout; - pid_t pid; - int state; - int flag; - int ret = 0; - unsigned int caps; - - CHECK_POWEROFF(); - - g_variant_get(param, "(sssi)", &state_str, &option1_str, &option2_str, &timeout); - - if (!state_str || timeout < 0) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - if (!strcmp(option1_str, STAYCURSTATE_STR)) - flag = STAY_CUR_STATE; - else if (!strcmp(option1_str, GOTOSTATENOW_STR)) - flag = GOTO_STATE_NOW; - else { - _E("%s option is invalid. set default option!", option1_str); - flag = STAY_CUR_STATE; - } - - if (!strcmp(option2_str, HOLDKEYBLOCK_STR)) - flag |= HOLD_KEY_BLOCK; - - if (flag & GOTO_STATE_NOW) { - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) && - state == LCD_NORMAL) { - _D("No lcdon capability!"); - ret = -EPERM; - goto out; - } - if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) && - state == LCD_OFF) { - _D("No lcdoff capability!"); - ret = -EPERM; - goto out; - } - } - - if (check_dimstay(state, flag) == true) { - _E("LCD state can not be changed to OFF state now!"); - flag &= ~GOTO_STATE_NOW; - flag |= STAY_CUR_STATE; - } - - if (disp_plgn.pm_lock_internal) - ret = disp_plgn.pm_lock_internal(pid, state, flag, timeout); -out: - g_free(state_str); - g_free(option1_str); - g_free(option2_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_unlockstate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - char *option_str; - pid_t pid; - int state; - int flag; - int ret = 0; - - CHECK_POWEROFF(); - - g_variant_get(param, "(ss)", &state_str, &option_str); - - if (!state_str) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - if (!strcmp(option_str, SLEEP_MARGIN_STR)) - flag = PM_SLEEP_MARGIN; - else if (!strcmp(option_str, RESET_TIMER_STR)) - flag = PM_RESET_TIMER; - else if (!strcmp(option_str, KEEP_TIMER_STR)) - flag = PM_KEEP_TIMER; - else { - _E("%s option is invalid. set default option!", option_str); - flag = PM_RESET_TIMER; - } - - if (disp_plgn.pm_unlock_internal) - ret = disp_plgn.pm_unlock_internal(pid, state, flag); -out: - g_free(state_str); - g_free(option_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_changestate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - char *state_str; - pid_t pid; - int state; - int ret = 0; - unsigned int caps; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &state_str); - - if (!state_str) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - if (!strcmp(state_str, "privilege check")) - goto out; - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (!strcmp(state_str, PM_LCDON_STR)) - state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; - else if (!strcmp(state_str, PM_LCDOFF_STR)) - state = LCD_OFF; - else if (!strcmp(state_str, PM_STANDBY_STR)) - state = STANDBY; - else if (!strcmp(state_str, PM_SUSPEND_STR)) - state = SUSPEND; - else { - _E("%s state is invalid, dbus ignored!", state_str); - ret = -EINVAL; - goto out; - } - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_LCDON) && - state == LCD_NORMAL) { - _D("No lcdon capability!"); - ret = -EPERM; - goto out; - } - if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF) && - state == LCD_OFF) { - _D("No lcdoff capability!"); - ret = -EPERM; - goto out; - } - - if (check_dimstay(state, GOTO_STATE_NOW) == true) { - _E("LCD state can not be changed to OFF state!"); - ret = -EBUSY; - goto out; - } - - if (disp_plgn.pm_change_internal) - ret = disp_plgn.pm_change_internal(pid, state); - - if (!ret && state == LCD_OFF) - update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); -out: - g_free(state_str); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getdisplaycount(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - ret = DEFAULT_DISPLAY_COUNT; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getmaxbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret, state; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &state); - if (state == DISPLAY_STATE_NORMAL) - ret = DEFAULT_DISPLAY_MAX_BRIGHTNESS; - else if (state == DISPLAY_STATE_SCREEN_DIM) - ret = DEFAULT_DISPLAY_MAX_DIM_BRIGHTNESS; - else - ret = -EINVAL; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setmaxbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - ret = -ENOTSUP; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int brt = -1, state, ret; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &state); - - if (state == DISPLAY_STATE_NORMAL) - ret = backlight_ops.get_brightness(&brt); - else if (state == DISPLAY_STATE_SCREEN_DIM) { - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, &brt); - if (ret < 0) - _E("Failed to get vconf value for lcd dim brightness: %d", vconf_get_ext_errno()); - } else - ret = -EINVAL; - - if (ret >= 0) - ret = brt; - - _I("get brightness %d, %d", brt, ret); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int state, brt, autobrt, ret = 0, caps; - - CHECK_POWEROFF(); - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) { - _D("No brightness changing capability!"); - ret = -EPERM; - goto error; - } - - g_variant_get(param, "(ii)", &state, &brt); - - //Check if brt is same with DIM - if (brt == 0) { - _E("application can not set this value(DIM VALUE:%d)", brt); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - autobrt = SETTING_BRIGHTNESS_AUTOMATIC_OFF; - } - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - _E("auto_brightness state is ON, can not change the brightness value"); - ret = -EPERM; - goto error; - } - - if (state == DISPLAY_STATE_NORMAL) { - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); - } else if (state == DISPLAY_STATE_SCREEN_DIM) { - if (pm_cur_state == S_LCDDIM) { - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - } - - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd dim brightness: %d", vconf_get_ext_errno()); - } else - ret = -EINVAL; - - _I("set brightness %d, %d", brt, ret); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_holdbrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int brt, autobrt, ret, caps; - - CHECK_POWEROFF(); - - caps = display_get_caps(DISPLAY_ACTOR_API); - - if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) { - _D("No brightness changing capability!"); - ret = -EPERM; - goto error; - } - - g_variant_get(param, "(i)", &brt); - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - autobrt = SETTING_BRIGHTNESS_AUTOMATIC_OFF; - } - - ret = vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON); - if (ret < 0) - _E("Failed to set vconf value for custom brightness status: %d", vconf_get_ext_errno()); - - ret = backlight_ops.set_brightness(brt); - if (ret < 0) - goto error; - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - _D("Auto brightness will be paused"); - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_PAUSE); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - } - - _I("hold brightness %d, %d", brt, ret); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_releasebrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int bat, charger, changed, setting, brt, autobrt, ret = 0; - - CHECK_POWEROFF(); - - ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat); - if (ret < 0) { - _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charger); - if (ret < 0) { - _E("Failed to get vconf value for charger status: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_bool(VCONFKEY_PM_BRIGHTNESS_CHANGED_IN_LPM, &changed); - if (ret < 0) { - _E("Failed to get vconf value for brightness changed in lpm: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &setting); - if (ret < 0) { - _E("Failed to get vconf value for lcd brightness: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); - if (ret < 0) { - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - ret = -EPERM; - goto error; - } - - ret = vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_OFF); - if (ret < 0) - _E("Failed to set vconf value for custom brightness status: %d", vconf_get_ext_errno()); - - ret = backlight_ops.get_brightness(&brt); - if (ret < 0) - brt = ret; - - // check dim state - if (low_battery_state(bat) && - charger == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED && !changed) { - _D("batt warning low : brightness is not changed!"); - if (brt != 0) - backlight_ops.set_brightness(0); - goto error; - } - - if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_OFF) { - if (brt != setting) - backlight_ops.set_brightness(setting); - } else if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) { - _D("Auto brightness will be enable"); - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, SETTING_BRIGHTNESS_AUTOMATIC_ON); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - } - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setrefreshrate(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int app, val, ret, control; - - CHECK_POWEROFF(); - - g_variant_get(param, "(ii)", &app, &val); - - if (app < 0 || app >= ARRAY_SIZE(display_conf.framerate_app) || val < 0) { - ret = -EINVAL; - goto error; - } - - if (!display_conf.framerate_app[app]) { - _I("This case(%d) is not support in this target", app); - ret = -EPERM; - goto error; - } - - control = display_conf.control_display; - - if (control) - backlight_ops.off(NORMAL_MODE); - - _D("app : %d, value : %d", app, val); - ret = backlight_ops.set_frame_rate(val); - if (ret < 0) - _E("Failed to set frame rate (%d)", ret); - - if (control) - backlight_ops.on(NORMAL_MODE); - -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setautobrightnessmin(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int val, ret; - pid_t pid; - int id = 0; - - CHECK_POWEROFF(); - - if (!display_info.set_autobrightness_min) { - ret = -EIO; - goto error; - } - g_variant_get(param, "(i)", &val); - - pid = dbus_connection_get_sender_pid(conn, sender); - ret = display_info.set_autobrightness_min(val, (char *)sender); - if (ret) { - _W("fail to set autobrightness min %d, %d by %d", val, ret, pid); - goto error; - } - if (display_info.reset_autobrightness_min) { - id = dbus_handle_watch_name(sender, display_info.reset_autobrightness_min, NULL, NULL, NULL); - if (id <= 0) { - _E("failed to watch name %s, id %d", sender, id); - //todo: set return value - } - _I("set autobrightness min %d by %d", val, pid); - } -error: - return g_variant_new("(i)", ret); -} - -GVariant *dbus_setlcdtimeout(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int on, dim, holdkey_block, ret; - pid_t pid; - int id = 0; - - CHECK_POWEROFF(); - - g_variant_get(param, "(iii)", &on, &dim, &holdkey_block); - - pid = dbus_connection_get_sender_pid(conn, sender); - ret = set_lcd_timeout(on, dim, holdkey_block, sender); - if (ret) { - _W("fail to set lcd timeout %d by %d", ret, pid); - } else { - id = dbus_handle_watch_name(sender, reset_lcd_timeout, NULL, NULL, NULL); - if (id <= 0) { - _E("failed to watch name %s, id %d", sender, id); - //todo: set return value - } - _I("set lcd timeout on %d, dim %d, holdblock %d by %d", - on, dim, holdkey_block, pid); - } - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_lockscreenbgon(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - char *on = NULL; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &on); - - if (!strcmp(on, "true")) { - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_LOCK_SCREEN_BG, true); - } else if (!strcmp(on, "false")) { - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_LOCK_SCREEN_BG, false); - } else - ret = -EINVAL; - - g_free(on); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_dumpmode(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - char *on; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &on); - - if (!strcmp(on, "on")) { - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, - STAY_CUR_STATE, DUMP_MODE_WATING_TIME); - } else if (!strcmp(on, "off")) { - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, PM_SLEEP_MARGIN); - } else - ret = -EINVAL; - - g_free(on); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_savelog(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - if (!device_poweroff(NULL)) - save_display_log(); - return dbus_handle_new_g_variant_tuple(); -} - -GVariant *dbus_powerkeyignore(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int on; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &on); - - if (CHECK_OPS(keyfilter_ops, set_powerkey_ignore)) - keyfilter_ops->set_powerkey_ignore(on == 1 ? true : false); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_powerkeylcdoff(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - - CHECK_POWEROFF(); - - if (CHECK_OPS(keyfilter_ops, powerkey_lcdoff)) - ret = keyfilter_ops->powerkey_lcdoff(); - else - ret = -ENOSYS; - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_customlcdon(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int timeout; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &timeout); - - ret = custom_lcdon(timeout); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_staytouchscreenoff(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int val; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &val); - - set_stay_touchscreen_off(val); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_lcdpaneloffmode(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0; - int val; - - CHECK_POWEROFF(); - - g_variant_get(param, "(i)", &val); - - set_lcd_paneloff_mode(val); - - return g_variant_new("(i)", ret); -} - -GVariant *dbus_actorcontrol(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret = 0, val, actor; - char *op; - - CHECK_POWEROFF(); - - g_variant_get(param, "(sii)", &op, &actor, &val); - - if (!strcmp(op, "set")) - ret = display_set_caps(actor, val); - else if (!strcmp(op, "reset")) - ret = display_reset_caps(actor, val); - else - ret = -EINVAL; - - g_free(op); - return g_variant_new("(i)", ret); -} - -GVariant *dbus_getcustombrightness(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int status = 0; - - CHECK_POWEROFF(); - - status = backlight_ops.get_custom_status(); - - return g_variant_new("(i)", status); -} - -struct pmlock_expired_s { - char req_id[32]; - GDBusMethodInvocation *invocation; - int value; - pid_t pid; -}; - -static dd_list *expired_req_list; - -static int get_command(pid_t pid, char *comm, size_t len) -{ - FILE *fp; - char path[PATH_MAX]; - char name[NAME_MAX]; - char *tmp; - int ret; - - snprintf(path, sizeof(path), "/proc/%d/comm", pid); - - fp = fopen(path, "r"); - if (!fp) { - _E("Failed to open file %s, errno:%d", path, errno); - return -errno; - } - - ret = fread(name, 1, sizeof(name) - 1, fp); - name[ret] = '\0'; - fclose(fp); - - tmp = name; - while (*tmp != '\0') { - if (*tmp == '\n' || - *tmp == '\r') { - *tmp = '\0'; - break; - } - tmp++; - } - - snprintf(comm, len, "%s", name); - - return 0; -} - -GVariant *dbus_locktimeout_expired(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - char *req_id; - pid_t pid; - char pid_str[16]; - char comm[NAME_MAX]; - struct pmlock_expired_s *ex = NULL; - GVariant *gvar = NULL; - - CHECK_POWEROFF(); - - g_variant_get(param, "(s)", &req_id); - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - ret = get_command(pid, comm, sizeof(comm)); - if (ret < 0) { - _E("Failed to get command (%d)", ret); - goto out; - } - - ex = calloc(1, sizeof(struct pmlock_expired_s)); - if (!ex) { - _E("calloc() failed"); - ret = -ENOMEM; - goto out; - } - - snprintf(pid_str, sizeof(pid_str), "%d", pid); - ret = launch_system_app(APP_DEFAULT, 8, - APP_KEY_TYPE, - EXPIRED_POPUP_TYPE_POWER, - EXPIRED_POPUP_PID, - pid_str, - EXPIRED_POPUP_COMM, - comm, - EXPIRED_POPUP_ID, - req_id); - if (ret < 0) { - _E("Failed to launch pmlock expired popup(%d)", ret); - goto out; - } - - ex->pid = pid; - snprintf(ex->req_id, sizeof(ex->req_id), "%s", req_id); - - ex->invocation = invocation; - - DD_LIST_APPEND(expired_req_list, ex); - - g_free(req_id); - return NULL; - -out: - gvar = g_variant_new("(i)", ret); - g_free(req_id); - if (ex) - free(ex); - return gvar; -} - -static gboolean app_term(gpointer data) -{ - struct pmlock_expired_s *ex = data; - - if (ex) { - if (kill(ex->pid, 0) != -1) - kill(ex->pid, SIGKILL); - free(ex); - } - return G_SOURCE_REMOVE; -} - -static void expired_deliver_result(void *data) -{ - struct pmlock_expired_s *ex = data; - struct pmlock_expired_s *item = NULL; - dd_list *l; - size_t len; - int value; - char *id; - - if (!ex) - return; - - len = strlen(ex->req_id) + 1; - DD_LIST_FOREACH(expired_req_list, l, item) { - if (!strncmp(item->req_id, ex->req_id, len)) { - DD_LIST_REMOVE(expired_req_list, item); - break; - } - } - if (!item) - goto out; - - id = ex->req_id; - value = ex->value; - - _I("User input of req_id(%s) is (%s)", id, value == 0 ? "ALLOW power lock" : - (value == 2) ? "KILL app" : "Release power lock"); - - if (!item->invocation) { - _E("item->invocation is null"); - goto out; - } - g_dbus_method_invocation_return_value(item->invocation, g_variant_new("(i)", 0)); - - if (value == 2) { - kill(item->pid, SIGTERM); - g_timeout_add(3000, app_term, (gpointer)item); - item = NULL; - } - -out: - free(ex); - free(item); -} - -GVariant *dbus_locktimeout_input(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - char *req_id; - struct pmlock_expired_s *ex; - int value; - - CHECK_POWEROFF(); - - g_variant_get(param, "(si)", &req_id, &value); - - ex = calloc(1, sizeof(struct pmlock_expired_s)); - if (!ex) { - _E("calloc() failed"); - ret = -ENOMEM; - goto out; - } - - snprintf(ex->req_id, sizeof(ex->req_id), "%s", req_id); - ex->value = value; - - _I("req_id(%s), value(%d)", ex->req_id, ex->value); - - add_idle_request(expired_deliver_result, ex); - - ret = 0; - -out: - g_free(req_id); - return g_variant_new("(i)", ret); -} - -static const dbus_method_s dbus_methods[] = { - { "start", NULL, NULL, dbus_start }, - { "stop", NULL, NULL, dbus_stop }, - { "lockstate", "sssi", "i", dbus_lockstate }, - { "unlockstate", "ss", "i", dbus_unlockstate }, - { "changestate", "s", "i", dbus_changestate }, - { "ChangeState", "s", "i", dbus_changestate }, - { "getbrightness", "i", "i", dbus_getbrightness }, /* deprecated */ - { "setbrightness", "ii", "i", dbus_setbrightness }, /* deprecated */ - { "setframerate", "ii", "i", dbus_setrefreshrate }, /* deprecated */ - { "setautobrightnessmin", "i", "i", dbus_setautobrightnessmin }, - { "setlcdtimeout", "iii", "i", dbus_setlcdtimeout }, - { "LockScreenBgOn", "s", "i", dbus_lockscreenbgon }, - { "GetDisplayCount", NULL, "i", dbus_getdisplaycount }, - { "GetMaxBrightness", "i", "i", dbus_getmaxbrightness }, - { "SetMaxBrightness", "i", "i", dbus_setmaxbrightness }, - { "GetBrightness", "i", "i", dbus_getbrightness }, - { "SetBrightness", "ii", "i", dbus_setbrightness }, - { "HoldBrightness", "i", "i", dbus_holdbrightness }, - { "ReleaseBrightness", NULL, "i", dbus_releasebrightness }, - { "SetRefreshRate", "ii", "i", dbus_setrefreshrate }, - { "Dumpmode", "s", "i", dbus_dumpmode }, - { "SaveLog", NULL, NULL, dbus_savelog }, - { "PowerKeyIgnore", "i", "i", dbus_powerkeyignore }, - { "PowerKeyLCDOff", NULL, "i", dbus_powerkeylcdoff }, - { "CustomLCDOn", "i", "i", dbus_customlcdon }, - { "StayTouchScreenOff", "i", "i", dbus_staytouchscreenoff }, - { "LCDPanelOffMode", "i", "i", dbus_lcdpaneloffmode }, - { "ActorControl", "sii", "i", dbus_actorcontrol }, - { "CustomBrightness", NULL, "i", dbus_getcustombrightness }, - { "CurrentBrightness", NULL, "i", dbus_getbrightness }, /* deprecated. It is remained for tizen 2.4 */ - { "LockTimeoutExpired", "s", "i", dbus_locktimeout_expired }, - { "LockTimeoutInput", "si", "i", dbus_locktimeout_input }, - /* Add methods here */ -}; - -static const dbus_interface_u dbus_interface = { - .oh = NULL, - .name = DEVICED_INTERFACE_DISPLAY, - .methods = dbus_methods, - .nr_methods = ARRAY_SIZE(dbus_methods), -}; - -static void homescreen_signal_handler(GDBusConnection *conn, - const gchar *sender, - const gchar *path, - const gchar *iface, - const gchar *name, - GVariant *param, - gpointer data) -{ - char *screen; - pid_t pid; - - g_variant_get(param, "(s)", &screen); - - _D("screen : %s", screen); - - pid = dbus_connection_get_sender_pid(conn, sender); - ambient_set_screen(screen, pid); - g_free(screen); -} - -/* - * Default capability - * api := LCDON | LCDOFF | BRIGHTNESS - * gesture := LCDON - */ -static struct display_actor_ops display_api_actor = { - .id = DISPLAY_ACTOR_API, - .caps = DISPLAY_CAPA_LCDON | - DISPLAY_CAPA_LCDOFF | - DISPLAY_CAPA_BRIGHTNESS, -}; - -static struct display_actor_ops display_gesture_actor = { - .id = DISPLAY_ACTOR_GESTURE, - .caps = DISPLAY_CAPA_LCDON, -}; - -int init_pm_dbus(void) -{ - int ret; - - display_add_actor(&display_api_actor); - display_add_actor(&display_gesture_actor); - - ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_DISPLAY, &dbus_interface); - if (ret < 0) - _E("fail to init dbus method(%d)", ret); - - ret = subscribe_dbus_signal(NULL, - DEVICED_OBJECT_PATH, - DEVICED_INTERFACE_NAME, - SIGNAL_HOMESCREEN, - homescreen_signal_handler, - NULL, NULL); - if (ret <= 0) { - _E("Failed to register signal handler! %d", ret); - return ret; - } - - return 0; -} - diff --git a/plugins/tv/display/display-ops.c b/plugins/tv/display/display-ops.c deleted file mode 100644 index 22b9137..0000000 --- a/plugins/tv/display/display-ops.c +++ /dev/null @@ -1,74 +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 "util.h" -#include "display-ops.h" -#include "core/list.h" -#include "core/common.h" - -static dd_list *disp_head; - -void add_display(const struct display_ops *disp) -{ - DD_LIST_APPEND(disp_head, disp); -} - -void remove_display(const struct display_ops *disp) -{ - DD_LIST_REMOVE(disp_head, disp); -} - -const struct display_ops *find_display_feature(const char *name) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - if (!strcmp(disp->name, name)) - return disp; - } - return NULL; -} - -void display_ops_init(void *data) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - _D("[%s] initialize", disp->name); - if (disp->init) - disp->init(data); - } -} - -void display_ops_exit(void *data) -{ - dd_list *elem; - const struct display_ops *disp; - - DD_LIST_FOREACH(disp_head, elem, disp) { - _D("[%s] deinitialize", disp->name); - if (disp->exit) - disp->exit(data); - } -} - diff --git a/plugins/tv/display/input.c b/plugins/tv/display/input.c deleted file mode 100644 index a986504..0000000 --- a/plugins/tv/display/input.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - * 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 -#include - -#include "util.h" -#include "core.h" -#include "poll.h" - -#define SEAT_NAME "seat0" - -static struct udev *udev; -static struct libinput *li; -static guint efd; - -int (*pm_callback) (int, PMMsg *); - -static inline void process_event(struct libinput_event *ev) -{ - static const struct device_ops *display_device_ops; - struct input_event input; - struct libinput *li; - struct libinput_event_keyboard *k; - unsigned int time; - int fd; - - if (!pm_callback) - return; - - if (!display_device_ops) { - display_device_ops = find_device("display"); - if (!display_device_ops) - return; - } - - /* do not operate when display stops */ - if (device_get_status(display_device_ops) - != DEVICE_OPS_STATUS_START) { - _E("display status is stop"); - return; - } - - switch (libinput_event_get_type(ev)) { - case LIBINPUT_EVENT_DEVICE_ADDED: - return; - case LIBINPUT_EVENT_KEYBOARD_KEY: - k = libinput_event_get_keyboard_event(ev); - time = libinput_event_keyboard_get_time(k); - li = libinput_event_get_context(ev); - - input.time.tv_sec = MSEC_TO_SEC(time); - input.time.tv_usec = MSEC_TO_USEC(time % 1000); - input.type = EV_KEY; - input.code = libinput_event_keyboard_get_key(k); - input.value = libinput_event_keyboard_get_key_state(k); - - fd = libinput_get_fd(li); - _D("time %ld.%06ld type %d code %d value %d fd %d", - input.time.tv_sec, input.time.tv_usec, input.type, - input.code, input.value, fd); - - if (CHECK_OPS(keyfilter_ops, check) && - keyfilter_ops->check(&input, fd) != 0) - return; - break; - case LIBINPUT_EVENT_POINTER_MOTION: - case LIBINPUT_EVENT_POINTER_BUTTON: - case LIBINPUT_EVENT_POINTER_AXIS: - li = libinput_event_get_context(ev); - input.type = EV_REL; - - fd = libinput_get_fd(li); - _D("type %d fd %d", input.type, fd); - - if (CHECK_OPS(keyfilter_ops, check) && - keyfilter_ops->check(&input, fd) != 0) - return; - break; - case LIBINPUT_EVENT_TOUCH_DOWN: - case LIBINPUT_EVENT_TOUCH_UP: - case LIBINPUT_EVENT_TOUCH_MOTION: - case LIBINPUT_EVENT_TOUCH_FRAME: - if (touch_event_blocked()) - return ; - break; - default: - break; - } - - /* lcd on or update lcd timeout */ - (*pm_callback) (INPUT_POLL_EVENT, NULL); -} - -static gboolean input_handler(gint fd, GIOCondition cond, void *data) -{ - struct libinput_event *ev; - struct libinput *input = (struct libinput *)data; - - /* Ignore input during poweroff */ - if (device_poweroff(NULL)) - return G_SOURCE_CONTINUE; - - if (!input) - return G_SOURCE_CONTINUE; - - libinput_dispatch(input); - - while ((ev = libinput_get_event(input))) { - process_event(ev); - - libinput_event_destroy(ev); - libinput_dispatch(input); - } - - return G_SOURCE_CONTINUE; -} - -static int open_restricted(const char *path, int flags, void *user_data) -{ - int fd; - unsigned int clockid = CLOCK_MONOTONIC; - - if (!path) - return -EINVAL; - - fd = open(path, flags); - if (fd >= 0) { - /* TODO Why does fd change the clock? */ - if (ioctl(fd, EVIOCSCLOCKID, &clockid) < 0) - _E("fail to change clock %s", path); - } - - return fd < 0 ? -errno : fd; -} - -static void close_restricted(int fd, void *user_data) -{ - close(fd); -} - -static const struct libinput_interface interface = { - .open_restricted = open_restricted, - .close_restricted = close_restricted, -}; - -int init_input(void) -{ - int ret; - int fd; - - udev = udev_new(); - if (!udev) { - _E("fail to create udev library context"); - return -EPERM; - } - - li = libinput_udev_create_context(&interface, NULL, udev); - if (!li) { - _E("fail to create a new libinput context from udev"); - return -EPERM; - } - - ret = libinput_udev_assign_seat(li, SEAT_NAME); - if (ret < 0) { - _E("fail to assign a seat"); - return -EPERM; - } - - fd = libinput_get_fd(li); - if (fd < 0) { - _E("fail to get file descriptor from libinput context"); - return -EPERM; - } - - /* add to poll handler */ - efd = g_unix_fd_add(fd, G_IO_IN, - input_handler, - (void *)((intptr_t)li)); - if (!efd) { - _E("fail to g_unix_fd_add"); - /* TODO Does it really need close()? */ - close(fd); - return -EPERM; - } - - return 0; -} - -int exit_input(void) -{ - if (efd) { - g_source_remove(efd); - efd = -1; - } - /* todo: close fd */ - - if (li) - libinput_unref(li); - - if (udev) - udev_unref(udev); - - return 0; -} diff --git a/plugins/tv/display/lock-detector.c b/plugins/tv/display/lock-detector.c deleted file mode 100644 index 0560ef4..0000000 --- a/plugins/tv/display/lock-detector.c +++ /dev/null @@ -1,232 +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. - */ - - -/** - * @file lock-detector.c - * @brief - * - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "util.h" -#include "core.h" -#include "core/list.h" - -struct lock_info { - unsigned long hash; - char *name; - int state; - int count; - long locktime; - long unlocktime; - long time; -}; - -#define LIMIT_COUNT 128 - -static dd_list *lock_info_list; - -static long get_time(void) -{ - struct timeval now; - gettimeofday(&now, NULL); - return (long)(now.tv_sec * 1000 + now.tv_usec / 1000); -} - -static void shrink_lock_info_list(void) -{ - dd_list *l, *l_prev; - struct lock_info *info; - unsigned int count; - - count = DD_LIST_LENGTH(lock_info_list); - if (count <= LIMIT_COUNT) - return; - _D("list is shrink : count %d", count); - - DD_LIST_REVERSE_FOREACH_SAFE(lock_info_list, l, l_prev, info) { - if (info->locktime == 0) { - DD_LIST_REMOVE_LIST(lock_info_list, l); - if (info->name) - free(info->name); - free(info); - count--; - } - if (count <= (LIMIT_COUNT / 2)) - break; - } -} - -int set_lock_time(const char *pname, int state) -{ - struct lock_info *info; - dd_list *l; - unsigned long val; - - if (!pname) - return -EINVAL; - - if (state < S_NORMAL || state > S_SLEEP) - return -EINVAL; - - val = g_str_hash(pname); - - 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; - DD_LIST_REMOVE(lock_info_list, info); - DD_LIST_PREPEND(lock_info_list, info); - return 0; - } - - info = malloc(sizeof(struct lock_info)); - if (!info) { - _E("Malloc is failed for lock_info!"); - return -ENOMEM; - } - - info->hash = val; - info->name = strndup(pname, strlen(pname)); - info->state = state; - info->count = 1; - info->locktime = get_time(); - info->unlocktime = 0; - info->time = 0; - - DD_LIST_APPEND(lock_info_list, info); - - return 0; -} - -int set_unlock_time(const char *pname, int state) -{ - bool find = false; - long diff; - struct lock_info *info; - dd_list *l; - unsigned long val; - - if (!pname) - return -EINVAL; - - if (state < S_NORMAL || state > S_SLEEP) - return -EINVAL; - - val = g_str_hash(pname); - - 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; - } - - if (!find) - return -EINVAL; - - if (info->locktime == 0) - return -EINVAL; - - /* update time */ - info->unlocktime = get_time(); - diff = info->unlocktime - info->locktime; - if (diff > 0) - info->time += diff; - info->locktime = 0; - - if (DD_LIST_LENGTH(lock_info_list) > LIMIT_COUNT) - shrink_lock_info_list(); - - return 0; -} - -void free_lock_info_list(void) -{ - dd_list *l, *l_next; - struct lock_info *info; - - if (!lock_info_list) - return; - - 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); - } - lock_info_list = NULL; -} - -void print_lock_info_list(int fd) -{ - struct lock_info *info; - dd_list *l; - char buf[255]; - int ret; - - if (!lock_info_list) - return; - - snprintf(buf, sizeof(buf), - "current time : %ld ms\n", get_time()); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - - snprintf(buf, sizeof(buf), - "[%10s %6s] %6s %10s %10s %10s %s\n", "hash", "state", - "count", "locktime", "unlocktime", "time", "process name"); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - - DD_LIST_FOREACH(lock_info_list, l, info) { - long time = 0; - if (info->locktime != 0 && info->unlocktime == 0) - time = get_time() - info->locktime; - snprintf(buf, sizeof(buf), - "[%10lu %6d] %6d %10ld %10ld %10ld %s\n", - info->hash, - info->state, - info->count, - info->locktime, - info->unlocktime, - info->time + time, - info->name); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed (%d)", errno); - } -} - diff --git a/plugins/tv/display/poll.c b/plugins/tv/display/poll.c deleted file mode 100644 index ee0471d..0000000 --- a/plugins/tv/display/poll.c +++ /dev/null @@ -1,174 +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. - */ - - -/** - * @file poll.c - * @brief Power Manager poll implementation - * - */ - -#include -#include "util.h" -#include "core.h" -#include "poll.h" -#include "display/display-ops.h" - -#define SHIFT_UNLOCK 4 -#define SHIFT_UNLOCK_PARAMETER 12 -#define SHIFT_CHANGE_STATE 8 -#define SHIFT_CHANGE_TIMEOUT 20 -#define LOCK_FLAG_SHIFT 16 -#define __HOLDKEY_BLOCK_BIT 0x1 -#define HOLDKEY_BLOCK_BIT (__HOLDKEY_BLOCK_BIT << LOCK_FLAG_SHIFT) - -static PMMsg recv_data; - -int check_dimstay(int next_state, int flag) -{ - if (next_state != LCD_OFF) - return false; - - if (!(flag & GOTO_STATE_NOW)) - return false; - - if (!(pm_status_flag & DIMSTAY_FLAG)) - return false; - - return true; -} - -static enum state_t get_state(int s_bits) -{ - switch (s_bits) { - case LCD_NORMAL: - return S_NORMAL; - case LCD_DIM: - return S_LCDDIM; - case LCD_OFF: - return S_LCDOFF; - case STANDBY: - return S_STANDBY; - case SUSPEND: - return S_SLEEP; - default: - return -EINVAL; - } -} - -static bool state_supported(enum state_t st) -{ - if (states[st].trans) - return true; - return false; -} - -static int __pm_lock_internal(pid_t pid, int s_bits, int flag, int timeout) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_LOCK); - - if (flag & GOTO_STATE_NOW) - /* if the flag is true, go to the locking state directly */ - cond = SET_COND_FLAG(cond, PM_REQUEST_CHANGE); - - if (flag & HOLD_KEY_BLOCK) - cond = SET_COND_FLAG(cond, PM_FLAG_BLOCK_HOLDKEY); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = timeout; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -static int __pm_unlock_internal(pid_t pid, int s_bits, int flag) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_UNLOCK); - - if (flag & PM_KEEP_TIMER) - cond = SET_COND_FLAG(cond, PM_FLAG_KEEP_TIMER); - - if (flag & PM_RESET_TIMER) - cond = SET_COND_FLAG(cond, PM_FLAG_RESET_TIMER); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = 0; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -static int __pm_change_internal(pid_t pid, int s_bits) -{ - int cond; - - if (!pm_callback) - return -1; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!state_supported(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_CHANGE); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = 0; - - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); - - return 0; -} - -void init_pm_internal() -{ - disp_plgn.pm_lock_internal = __pm_lock_internal; - disp_plgn.pm_unlock_internal = __pm_unlock_internal; - disp_plgn.pm_change_internal = __pm_change_internal; -} diff --git a/plugins/tv/display/setting.c b/plugins/tv/display/setting.c deleted file mode 100644 index b109d8c..0000000 --- a/plugins/tv/display/setting.c +++ /dev/null @@ -1,271 +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 "ambient-mode.h" -#include "core.h" -#include "util.h" -#include "setting.h" -#include "display-ops.h" - -#define LCD_DIM_RATIO 0.3 -#define LCD_MAX_DIM_TIMEOUT 7000 -#define LCD_MIN_DIM_TIMEOUT 500 - -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_POWER_CUSTOM_BRIGHTNESS] = VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, -}; - -static int lock_screen_state = VCONFKEY_IDLE_UNLOCK; -static bool lock_screen_bg_state = false; -static int force_lcdtimeout = 0; -static int custom_on_timeout = 0; -static int custom_normal_timeout = 0; -static int custom_dim_timeout = 0; - -static void display_state_send_system_event(int state) -{ - bundle *b; - const char *str; - - if (state == S_NORMAL) - str = EVT_VAL_DISPLAY_NORMAL; - else if (state == S_LCDDIM) - str = EVT_VAL_DISPLAY_DIM; - else if (state == S_LCDOFF) - str = EVT_VAL_DISPLAY_OFF; - else - return; - - _I("eventsystem (%s)", str); - - b = bundle_create(); - bundle_add_str(b, EVT_KEY_DISPLAY_STATE, str); - eventsystem_send_system_event(SYS_EVENT_DISPLAY_STATE, b); - bundle_free(b); -} - -int set_force_lcdtimeout(int timeout) -{ - if (timeout < 0) - return -EINVAL; - - force_lcdtimeout = timeout; - - return 0; -} - -int __get_lock_screen_state(void) -{ - return lock_screen_state; -} - -void set_lock_screen_state(int state) -{ - switch (state) { - case VCONFKEY_IDLE_LOCK: - case VCONFKEY_IDLE_UNLOCK: - lock_screen_state = state; - break; - default: - lock_screen_state = VCONFKEY_IDLE_UNLOCK; - } -} - -int get_lock_screen_bg_state(void) -{ - return lock_screen_bg_state; -} - -void set_lock_screen_bg_state(bool state) -{ - _I("state is %d", state); - lock_screen_bg_state = state; -} - -int set_setting_pmstate(int val) -{ - static int old = -1; - int ret; - - if (old == val) - return 0; - old = val; - - display_state_send_system_event(val); - ret = vconf_set_int(VCONFKEY_PM_STATE, val); - if (ret < 0) - _E("Failed to set vconf value for pm state: %d", vconf_get_ext_errno()); - - return ret; -} - -int get_setting_brightness(int *level) -{ - int ret; - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, level); - if (ret < 0) - _E("Failed to get vconf value for lcd brightness: %d", vconf_get_ext_errno()); - - return ret; -} - -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; - } - - if (ambient_get_condition() == true) { - *dim_timeout = LCD_MIN_DIM_TIMEOUT; - return; - } - - ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout); - if (ret < 0) { - _E("Failed to get vconf value for setting timeout: %d", vconf_get_ext_errno()); - vconf_timeout = DEFAULT_NORMAL_TIMEOUT; - } - - if (force_lcdtimeout > 0) - on_timeout = SEC_TO_MSEC(force_lcdtimeout); - else - on_timeout = SEC_TO_MSEC(vconf_timeout); - - val = (double)on_timeout * LCD_DIM_RATIO; - if (val > LCD_MAX_DIM_TIMEOUT) - val = LCD_MAX_DIM_TIMEOUT; - - *dim_timeout = val; -} - -void get_run_timeout(int *timeout) -{ - int dim_timeout = -1; - int vconf_timeout = -1; - int on_timeout; - int ret; - - if (custom_normal_timeout > 0) { - *timeout = custom_normal_timeout; - return; - } - - ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout); - if (ret < 0) { - _E("Failed to get vconf value for setting timeout: %d", vconf_get_ext_errno()); - vconf_timeout = DEFAULT_NORMAL_TIMEOUT; - } - - if (force_lcdtimeout > 0) - on_timeout = SEC_TO_MSEC(force_lcdtimeout); - else - on_timeout = SEC_TO_MSEC(vconf_timeout); - - if (on_timeout == 0) { - *timeout = on_timeout; - return; - } - - get_dim_timeout(&dim_timeout); - *timeout = on_timeout - dim_timeout; -} - -int set_custom_lcdon_timeout(int timeout) -{ - int changed = (custom_on_timeout == timeout ? false : true); - - custom_on_timeout = timeout; - - if (timeout <= 0) { - custom_normal_timeout = 0; - custom_dim_timeout = 0; - return changed; - } - - custom_dim_timeout = (double)timeout * LCD_DIM_RATIO; - custom_normal_timeout = timeout - custom_dim_timeout; - - _I("custom normal(%d), dim(%d)", custom_normal_timeout, - custom_dim_timeout); - - return changed; -} - -static int setting_cb(keynode_t *key_nodes, void *data) -{ - keynode_t *tmp = key_nodes; - int index; - - index = (int)((intptr_t)data); - if (index > SETTING_END) { - _E("Unknown setting key: %s, idx=%d", - vconf_keynode_get_name(tmp), index); - return -1; - } - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(index, vconf_keynode_get_int(tmp)); - - return 0; -} - -int init_setting(int (*func) (int key_idx, int val)) -{ - int i; - - if (func != NULL) - disp_plgn.update_pm_setting = func; - - for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) { - /* - * To pass an index data through the vconf infratstructure - * without memory allocation, an index data becomes typecast - * to proper pointer size on each architecture. - */ - vconf_notify_key_changed(setting_keys[i], (void *)setting_cb, - (void *)((intptr_t)i)); - } - - disp_plgn.get_lock_screen_state = __get_lock_screen_state; - - return 0; -} - -int exit_setting(void) -{ - int i; - for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) - vconf_ignore_key_changed(setting_keys[i], (void *)setting_cb); - - return 0; -} - diff --git a/plugins/wearable/display/auto-brightness.c b/plugins/wearable/display/auto-brightness.c deleted file mode 100644 index efc415c..0000000 --- a/plugins/wearable/display/auto-brightness.c +++ /dev/null @@ -1,681 +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 "util.h" -#include "core.h" -#include "display-ops.h" -#include "device-node.h" -#include "setting.h" -#include "core/device-notifier.h" -#include "core/config-parser.h" - -#define METHOD_CHECK_SUPPORTED "CheckSupported" - -#define DISP_FORCE_SHIFT 12 -#define DISP_FORCE_CMD(prop, force) (((force) << DISP_FORCE_SHIFT) | prop) - -#define SAMPLING_INTERVAL 1 /* 1 sec */ -#define MAX_SAMPLING_COUNT 3 -#define MAX_FAULT 5 -#define DEFAULT_AUTOMATIC_BRT 5 -#define AUTOMATIC_DEVIDE_VAL 10 -#define AUTOMATIC_DELAY_TIME 500 /* 0.5 sec */ - -#define RADIAN_VALUE (57.2957) -#define ROTATION_90 90 -#define WORKING_ANGLE_MIN 0 -#define WORKING_ANGLE_MAX 20 - -#define BOARD_CONF_FILE "/etc/deviced/display.conf" - -#define ON_LUX -1 -#define OFF_LUX -1 -#define ON_COUNT 1 -#define OFF_COUNT 1 - -static int (*_default_action) (int); -static guint alc_timeout_id = 0; -static guint update_timeout; -static sensor_listener_h light_listener; -static sensor_listener_h accel_listener; -static int fault_count; -static int automatic_brt = DEFAULT_AUTOMATIC_BRT; -static int min_brightness = PM_MIN_BRIGHTNESS; -static char *min_brightness_name = 0; - -/* light sensor */ -static float lmax, lmin; - -static bool update_working_position(void) -{ - sensor_event_s data; - int ret; - float x, y, z, pitch, realg; - - if (!display_conf.accel_sensor_on) - return false; - - ret = sensor_listener_read_data(accel_listener, &data); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get accelerometer data: %d", ret); - return true; - } - - x = data.values[0]; - y = data.values[1]; - z = data.values[2]; - - realg = (float)sqrt((x * x) + (y * y) + (z * z)); - pitch = ROTATION_90 - abs((int) (asin(z / realg) * RADIAN_VALUE)); - - _D("Accel data x=%f y=%f z=%f pitch=%f", x, y, z, pitch); - - if (pitch >= WORKING_ANGLE_MIN && pitch <= WORKING_ANGLE_MAX) - return true; - return false; -} - -static void alc_set_brightness(int setting, int value, float light) -{ - static float old; - int position, tmp_value = 0, ret; - - ret = backlight_ops.get_brightness(&tmp_value); - if (ret < 0) { - _E("Failed to get display brightness."); - return; - } - - if (value < min_brightness) - value = min_brightness; - - if (tmp_value != value) { - if (!setting && min_brightness == PM_MIN_BRIGHTNESS && - display_conf.accel_sensor_on == true) { - position = update_working_position(); - if (!position && (old > light)) { - _D("It's not working position, " - "LCD isn't getting dark."); - return; - } - } - int diff, step; - - diff = value - tmp_value; - if (abs(diff) < display_conf.brightness_change_step) - step = (diff > 0 ? 1 : -1); - else - step = (int)ceil(diff / - (float)display_conf.brightness_change_step); - - _D("%d", step); - while (tmp_value != value) { - if (step == 0) break; - - tmp_value += step; - if ((step > 0 && tmp_value > value) || - (step < 0 && tmp_value < value)) - tmp_value = value; - - backlight_ops.set_default_brt(tmp_value); - backlight_ops.update(); - } - _I("Load light data(%f). auto brt=%d min brightness=%d " - "brightness=%d", light, automatic_brt, min_brightness, value); - old = light; - } -} - -static bool check_brightness_changed(int value) -{ - int i; - static int values[MAX_SAMPLING_COUNT], count = 0; - - if (count >= MAX_SAMPLING_COUNT || count < 0) - count = 0; - - values[count++] = value; - - for (i = 0; i < MAX_SAMPLING_COUNT - 1; i++) - if (values[i] != values[i+1]) - return false; - return true; -} - -static bool alc_update_brt(bool setting) -{ - int value = 0; - int ret = -1; - sensor_event_s light_data; - int index; - float light; - - ret = sensor_listener_read_data(light_listener, &light_data); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to read light sensor data: %d", ret); - goto out; - } - - index = light_data.value_count - 1; - if (index < 0 || light_data.values[index] < 0) { - _E("Invalid light sensor data."); - goto out; - } - - light = light_data.values[index]; - ret = backlight_ops.get_brightness_by_light_sensor( - lmax, lmin, light, &value); - if (ret == -ENOTSUP) { - _E("Not supported to handle the light data."); - goto out; - } - - if (ret < 0 || value < PM_MIN_BRIGHTNESS || value > PM_MAX_BRIGHTNESS) { - _E("Failed to load light data. light=%f value=%d: %d", light, value, ret); - goto out; - } - - fault_count = 0; - - if (display_conf.continuous_sampling && - !check_brightness_changed(value) && - !setting) - return true; - - alc_set_brightness(setting, value, light); - - return true; - -out: - fault_count++; - - if ((fault_count > MAX_FAULT) && !(pm_status_flag & PWROFF_FLAG)) { - if (alc_timeout_id) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - ret = vconf_set_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - SETTING_BRIGHTNESS_AUTOMATIC_OFF); - if (ret < 0) - _E("Failed to set vconf value for automatic brightness: %d", vconf_get_ext_errno()); - _E("Fault counts is over %d, disable automatic brightness.", MAX_FAULT); - return false; - } - return true; -} - -static gboolean alc_handler(void *data) -{ - if (pm_cur_state != S_NORMAL) { - if (alc_timeout_id > 0) - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - return G_SOURCE_REMOVE; - } - - if (!alc_update_brt(false)) - return G_SOURCE_REMOVE; - - if (alc_timeout_id != 0) - return G_SOURCE_CONTINUE; - - return G_SOURCE_REMOVE; -} - -static int alc_action(int timeout) -{ - /* sampling timer add */ - if (alc_timeout_id == 0 && !(pm_status_flag & PWRSV_FLAG)) { - display_info.update_auto_brightness(true); - - alc_timeout_id = - g_timeout_add_seconds(display_conf.lightsensor_interval, - alc_handler, NULL); - } - - if (_default_action != NULL) - return _default_action(timeout); - - /* unreachable code */ - return -1; -} - -static int connect_sensor(void) -{ - int ret; - sensor_h sensor; - sensor_h *list = NULL; - int cnt = 0; - - _I("Connect with sensor fw."); - /* light sensor */ - ret = sensor_get_sensor_list(SENSOR_LIGHT, &list, &cnt); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor list: %d", ret); - goto error; - } - - /* TODO - * Sensor apis will be fixed - * to provide which sensor is effective among sensors */ - if (cnt == 3) /* three light sensors exist */ - sensor = list[2]; - else - sensor = list[0]; - - free(list); - - ret = sensor_get_min_range(sensor, &lmin); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor min range: %d", ret); - goto error; - } - ret = sensor_get_max_range(sensor, &lmax); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get light sensor max range: %d", ret); - goto error; - } - _I("Light sensor min(%f), max(%f)", lmin, lmax); - - ret = sensor_create_listener(sensor, &light_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to create listener(light)."); - goto error; - } - sensor_listener_set_option(light_listener, SENSOR_OPTION_ALWAYS_ON); - ret = sensor_listener_start(light_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to start light sensor."); - sensor_destroy_listener(light_listener); - light_listener = 0; - goto error; - } - - if (!display_conf.accel_sensor_on) - goto success; - - /* accelerometer sensor */ - ret = sensor_get_default_sensor(SENSOR_ACCELEROMETER, &sensor); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to get default accel sensor."); - goto error; - } - ret = sensor_create_listener(&sensor, &accel_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to create listener(accel)."); - goto error; - } - sensor_listener_set_option(accel_listener, SENSOR_OPTION_ALWAYS_ON); - ret = sensor_listener_start(accel_listener); - if (ret != SENSOR_ERROR_NONE) { - _E("Failed to start accel sensor."); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - goto error; - } - -success: - fault_count = 0; - return 0; - -error: - if (light_listener > 0) { - sensor_listener_stop(light_listener); - sensor_destroy_listener(light_listener); - light_listener = 0; - } - if (display_conf.accel_sensor_on && accel_listener > 0) { - sensor_listener_stop(accel_listener); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - } - return -EIO; -} - -static int disconnect_sensor(void) -{ - _I("Disconnect with sensor fw."); - /* light sensor*/ - if (light_listener > 0) { - sensor_listener_stop(light_listener); - sensor_destroy_listener(light_listener); - light_listener = 0; - } - - /* accelerometer sensor*/ - if (display_conf.accel_sensor_on && accel_listener > 0) { - sensor_listener_stop(accel_listener); - sensor_destroy_listener(accel_listener); - accel_listener = 0; - } - - if (_default_action != NULL) { - states[S_NORMAL].action = _default_action; - _default_action = NULL; - } - if (alc_timeout_id > 0) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - - return 0; -} - -void set_brightness_changed_state(void) -{ - if (pm_status_flag & PWRSV_FLAG) { - pm_status_flag |= BRTCH_FLAG; - _D("Brightness changed in low battery," - "escape dim state (light)."); - } -} - -static int set_autobrightness_state(int status) -{ - int ret = -1; - int brt = -1; - int default_brt = -1; - - if (status == SETTING_BRIGHTNESS_AUTOMATIC_ON) { - if (connect_sensor() < 0) - return -1; - - /* escape dim state if it's in low battery.*/ - set_brightness_changed_state(); - - /* change alc action func */ - if (_default_action == NULL) - _default_action = states[S_NORMAL].action; - states[S_NORMAL].action = alc_action; - - display_info.update_auto_brightness(true); - - alc_timeout_id = - g_timeout_add_seconds(display_conf.lightsensor_interval, - alc_handler, NULL); - } else if (status == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) { - _I("Auto brightness paused."); - disconnect_sensor(); - } else { - disconnect_sensor(); - /* escape dim state if it's in low battery.*/ - set_brightness_changed_state(); - - ret = get_setting_brightness(&default_brt); - if (ret != 0 || (default_brt < PM_MIN_BRIGHTNESS || default_brt > PM_MAX_BRIGHTNESS)) { - _I("Failed to read vconf value for brightness."); - brt = PM_DEFAULT_BRIGHTNESS; - if (default_brt < PM_MIN_BRIGHTNESS || default_brt > PM_MAX_BRIGHTNESS) { - ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); - if (ret < 0) - _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); - } - default_brt = brt; - } - - backlight_ops.set_default_brt(default_brt); - backlight_ops.update(); - } - - return 0; -} - -static void set_alc_function(keynode_t *key_nodes, void *data) -{ - int status, ret; - - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - - status = vconf_keynode_get_int(key_nodes); - - switch (status) { - case SETTING_BRIGHTNESS_AUTOMATIC_OFF: - case SETTING_BRIGHTNESS_AUTOMATIC_ON: - case SETTING_BRIGHTNESS_AUTOMATIC_PAUSE: - ret = set_autobrightness_state(status); - _D("Set auto brightness: %d", ret); - break; - default: - _E("Invalid value(%d)", status); - } -} - -static void set_alc_automatic_brt(keynode_t *key_nodes, void *data) -{ - if (key_nodes == NULL) { - _E("Wrong parameter, key_nodes is null."); - return; - } - automatic_brt = vconf_keynode_get_int(key_nodes) / AUTOMATIC_DEVIDE_VAL; - _D("Automatic brt(%d)", automatic_brt); - - alc_update_brt(true); -} - -static gboolean update_handler(void *data) -{ - int ret, on; - - update_timeout = 0; - - if (pm_cur_state != S_NORMAL) - return G_SOURCE_REMOVE; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &on); - if (ret < 0 || on != SETTING_BRIGHTNESS_AUTOMATIC_ON) { - if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - return G_SOURCE_REMOVE; - } - - _D("Auto brightness is working."); - alc_update_brt(true); - - return G_SOURCE_REMOVE; -} - -static void update_auto_brightness(bool update) -{ - if (update_timeout) { - g_source_remove(update_timeout); - update_timeout = 0; - } - - if (update) { - update_timeout = g_timeout_add(AUTOMATIC_DELAY_TIME, - update_handler, NULL); - } -} - -static int prepare_lsensor(void *data) -{ - int status, ret; - int brt = -1; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &status); - if (ret == 0 && status == SETTING_BRIGHTNESS_AUTOMATIC_ON) - set_autobrightness_state(status); - else if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); - - /* add auto_brt_setting change handler */ - vconf_notify_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - set_alc_function, NULL); - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, &brt); - if (ret < 0) - _E("Failed to get vconf value for automatic lcd brightness: %d", vconf_get_ext_errno()); - - if (brt < PM_MIN_BRIGHTNESS || brt > PM_MAX_BRIGHTNESS) { - _E("Failed to get automatic brightness."); - } else { - automatic_brt = brt / AUTOMATIC_DEVIDE_VAL; - _I("Automatic brt(%d) init success.", automatic_brt); - } - - vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, - set_alc_automatic_brt, NULL); - - return 0; -} - -static void update_brightness_direct(void) -{ - int ret, status; - - ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &status); - if (ret == 0 && status == SETTING_BRIGHTNESS_AUTOMATIC_ON) - alc_update_brt(true); - else if (ret < 0) - _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); -} - -static int set_autobrightness_min(int val, char *name) -{ - if (!name) - return -EINVAL; - - if (val < PM_MIN_BRIGHTNESS || val > PM_MAX_BRIGHTNESS) - return -EINVAL; - - min_brightness = val; - - if (min_brightness_name) { - free(min_brightness_name); - min_brightness_name = 0; - } - min_brightness_name = strndup(name, strlen(name)); - - update_brightness_direct(); - - _I("Auto brightness min value changed. min_brightness=%d min_brightness_name=%s", - min_brightness, min_brightness_name); - - return 0; -} - -static void reset_autobrightness_min(GDBusConnection *conn, - const gchar *sender, - const gchar *unique_name, - gpointer data) -{ - if (!sender) - return; - - if (!min_brightness_name) - return; - - if (strcmp(sender, min_brightness_name)) - return; - - _I("Change to default min brightness. before=%d changed=%d brightness_name=%s", min_brightness, - PM_MIN_BRIGHTNESS, min_brightness_name); - min_brightness = PM_MIN_BRIGHTNESS; - if (min_brightness_name) { - free(min_brightness_name); - min_brightness_name = 0; - } - - update_brightness_direct(); -} - -static int lcd_changed_cb(void *data) -{ - int lcd_state; - - if (!data) - return 0; - lcd_state = *(int *)data; - if (lcd_state == S_LCDOFF && alc_timeout_id > 0) { - g_source_remove(alc_timeout_id); - alc_timeout_id = 0; - } - - return 0; -} - -static int booting_done_cb(void *data) -{ - int state; - - if (!data) - return 0; - - state = *(int *)data; - if (state != true) - return 0; - - /* get light data from sensor fw */ - prepare_lsensor(NULL); - - return 0; -} - -static void exit_lsensor(void) -{ - vconf_ignore_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - set_alc_function); - - vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, - set_alc_automatic_brt); - - set_autobrightness_state(SETTING_BRIGHTNESS_AUTOMATIC_OFF); -} - -static void auto_brightness_init(void *data) -{ - display_info.update_auto_brightness = update_auto_brightness; - display_info.set_autobrightness_min = set_autobrightness_min; - display_info.reset_autobrightness_min = reset_autobrightness_min; - - register_notifier(DEVICE_NOTIFIER_LCD, lcd_changed_cb); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); -} - -static void auto_brightness_exit(void *data) -{ - exit_lsensor(); - - unregister_notifier(DEVICE_NOTIFIER_LCD, lcd_changed_cb); - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); -} - -static const struct display_ops display_autobrightness_ops = { - .name = "auto-brightness", - .init = auto_brightness_init, - .exit = auto_brightness_exit, -}; - -DISPLAY_OPS_REGISTER(&display_autobrightness_ops) - diff --git a/plugins/wearable/display/ambient-mode.c b/src/display/ambient-mode.c similarity index 100% rename from plugins/wearable/display/ambient-mode.c rename to src/display/ambient-mode.c diff --git a/plugins/mobile/display/auto-brightness.c b/src/display/auto-brightness.c similarity index 100% rename from plugins/mobile/display/auto-brightness.c rename to src/display/auto-brightness.c diff --git a/plugins/wearable/display/display-actor.c b/src/display/display-actor.c similarity index 100% rename from plugins/wearable/display/display-actor.c rename to src/display/display-actor.c diff --git a/plugins/wearable/display/display-dbus.c b/src/display/display-dbus.c similarity index 100% rename from plugins/wearable/display/display-dbus.c rename to src/display/display-dbus.c diff --git a/plugins/wearable/display/display-ops.c b/src/display/display-ops.c similarity index 100% rename from plugins/wearable/display/display-ops.c rename to src/display/display-ops.c diff --git a/plugins/wearable/display/input.c b/src/display/input.c similarity index 100% rename from plugins/wearable/display/input.c rename to src/display/input.c diff --git a/plugins/wearable/display/lock-detector.c b/src/display/lock-detector.c similarity index 100% rename from plugins/wearable/display/lock-detector.c rename to src/display/lock-detector.c diff --git a/plugins/wearable/display/poll.c b/src/display/poll.c similarity index 100% rename from plugins/wearable/display/poll.c rename to src/display/poll.c diff --git a/plugins/wearable/display/setting.c b/src/display/setting.c similarity index 100% rename from plugins/wearable/display/setting.c rename to src/display/setting.c -- 2.7.4 From 3b0750f7bd653a394c8bd48ff92389098add32c3 Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Mon, 27 May 2019 15:41:21 +0900 Subject: [PATCH 05/16] dbus-policy: modified to use default deny - allow signal Change-Id: Ic9eeb5a7df8b35dacad0d2a8488efc249cd12104 Signed-off-by: sanghyeok.oh --- conf/org.tizen.system.deviced.conf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/conf/org.tizen.system.deviced.conf b/conf/org.tizen.system.deviced.conf index 49877ee..709c909 100644 --- a/conf/org.tizen.system.deviced.conf +++ b/conf/org.tizen.system.deviced.conf @@ -26,8 +26,7 @@ - - + -- 2.7.4 From 498493b3915e95fa7f78cc26914ffa1dd8b31646 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 11 Jun 2019 18:11:14 +0900 Subject: [PATCH 06/16] Update battery.health_s in check_health_status battery.health_s is not synchronized with battery.health. So, update battery.health_s in check_health_status to synchronize them. Change-Id: I779b1c91e202198be62ef858d2fa774a067a2c7d Signed-off-by: lokilee73 --- src/battery/power-supply.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index c4eb7c8..2b092d6 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -636,6 +636,9 @@ static void check_health_status(const char *env_value) battery.health = HEALTH_GOOD; return; } + + snprintf(battery.health_s, sizeof(battery.health_s), "%s", env_value); + if (strncmp(env_value, OVERHEAT_NAME, sizeof(OVERHEAT_NAME)) == 0) battery.health = HEALTH_HIGH; -- 2.7.4 From b82336785cdd7abda7212b930c72e1521960bed5 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 14 Jun 2019 19:35:24 +0900 Subject: [PATCH 07/16] Initialize dpms_connected in disconnect_interface_with_dpms to protect crash Display can be controlled by devicectl command. ex) devicectl display stop/start After disconnect_interface_with_dpms is called by devicectl command, LCD_ON can be requested via dbus-send. At this time, dpms related functions and variables are initialized. So, crash can occur. Change-Id: I9fdbc0c27e612bbdc9d11309f2a0be6102112d66 Signed-off-by: lokilee73 --- src/display/display-dpms.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) mode change 100644 => 100755 src/display/display-dpms.c diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c old mode 100644 new mode 100755 index 37f5d1b..54127de --- a/src/display/display-dpms.c +++ b/src/display/display-dpms.c @@ -31,6 +31,7 @@ struct wl_output *wl_out; struct tizen_dpms_manager *tz_dpms_mng = NULL; int lcd_state = -1; bool wm_is_ready; +static bool dpms_connected; bool check_wm_ready(void) { @@ -60,6 +61,8 @@ void disconnect_interface_with_dpms(void) wl_display_disconnect(display); display = NULL; } + + dpms_connected = false; } static void dpms_handle_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error) @@ -141,8 +144,6 @@ error: bool dpms_is_available(void) { - static bool dpms_connected; - /* Check window manager */ if (!wm_is_ready) { _E("Window manager is not ready"); -- 2.7.4 From 3ced9b5f3d7f92aa3cf44cdafac51d334907c85b Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 17 Jun 2019 13:33:31 +0900 Subject: [PATCH 08/16] Temporarily allow org.tizen.system.deviced.Board in dbus policy Change-Id: I5ce697624c93a03bc8ae9af5184ec2456c21ee7a Signed-off-by: Hyotaek Shim --- conf/org.tizen.system.deviced.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/org.tizen.system.deviced.conf b/conf/org.tizen.system.deviced.conf index 709c909..58737c0 100644 --- a/conf/org.tizen.system.deviced.conf +++ b/conf/org.tizen.system.deviced.conf @@ -59,5 +59,6 @@ + -- 2.7.4 From 58569a2be3e8a7ac40317160b0700f5a0dc535ac Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 20 Jun 2019 11:46:34 +0900 Subject: [PATCH 09/16] Add display_staydim_check for commonly used code Change-Id: Ib3a5f23b2a93f48eafecb9fe5f1f7a43f19f6bf2 Signed-off-by: lokilee73 --- plugins/iot/display/device-interface.c | 15 +++++++++++---- plugins/mobile/display/device-interface.c | 15 +++++++++++---- plugins/tv/display/device-interface.c | 15 +++++++++++---- plugins/wearable/display/device-interface.c | 15 +++++++++++---- 4 files changed, 44 insertions(+), 16 deletions(-) mode change 100755 => 100644 plugins/iot/display/device-interface.c mode change 100755 => 100644 plugins/mobile/display/device-interface.c mode change 100755 => 100644 plugins/tv/display/device-interface.c mode change 100755 => 100644 plugins/wearable/display/device-interface.c diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c old mode 100755 new mode 100644 index c4c9c7d..764fb47 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -187,14 +187,21 @@ static int get_lcd_power(void) return dpms_get_state(); } +bool display_dimstay_check(void) +{ + if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) + return true; + + return false; +} + void change_brightness(int start, int end, int step) { int diff, val; int ret = -1; int prev; - if ((pm_status_flag & PWRSV_FLAG) && - !(pm_status_flag & BRTCH_FLAG)) + if (display_dimstay_check()) return; ret = backlight_ops.get_brightness(&prev); @@ -315,7 +322,7 @@ static int custom_backlight_update(void) custom_brightness > PM_MAX_BRIGHTNESS) return -EINVAL; - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) { + if (display_dimstay_check()) { ret = backlight_dim(); } else { _I("Custom brightness(%d) restored.", custom_brightness); @@ -343,7 +350,7 @@ static int backlight_update(void) _I("Custom brightness mode. brt no updated."); return 0; } - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) + if (display_dimstay_check()) ret = backlight_dim(); else ret = bl_brt(default_brightness, 0); diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c old mode 100755 new mode 100644 index c4c9c7d..764fb47 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -187,14 +187,21 @@ static int get_lcd_power(void) return dpms_get_state(); } +bool display_dimstay_check(void) +{ + if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) + return true; + + return false; +} + void change_brightness(int start, int end, int step) { int diff, val; int ret = -1; int prev; - if ((pm_status_flag & PWRSV_FLAG) && - !(pm_status_flag & BRTCH_FLAG)) + if (display_dimstay_check()) return; ret = backlight_ops.get_brightness(&prev); @@ -315,7 +322,7 @@ static int custom_backlight_update(void) custom_brightness > PM_MAX_BRIGHTNESS) return -EINVAL; - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) { + if (display_dimstay_check()) { ret = backlight_dim(); } else { _I("Custom brightness(%d) restored.", custom_brightness); @@ -343,7 +350,7 @@ static int backlight_update(void) _I("Custom brightness mode. brt no updated."); return 0; } - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) + if (display_dimstay_check()) ret = backlight_dim(); else ret = bl_brt(default_brightness, 0); diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c old mode 100755 new mode 100644 index c4c9c7d..764fb47 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -187,14 +187,21 @@ static int get_lcd_power(void) return dpms_get_state(); } +bool display_dimstay_check(void) +{ + if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) + return true; + + return false; +} + void change_brightness(int start, int end, int step) { int diff, val; int ret = -1; int prev; - if ((pm_status_flag & PWRSV_FLAG) && - !(pm_status_flag & BRTCH_FLAG)) + if (display_dimstay_check()) return; ret = backlight_ops.get_brightness(&prev); @@ -315,7 +322,7 @@ static int custom_backlight_update(void) custom_brightness > PM_MAX_BRIGHTNESS) return -EINVAL; - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) { + if (display_dimstay_check()) { ret = backlight_dim(); } else { _I("Custom brightness(%d) restored.", custom_brightness); @@ -343,7 +350,7 @@ static int backlight_update(void) _I("Custom brightness mode. brt no updated."); return 0; } - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) + if (display_dimstay_check()) ret = backlight_dim(); else ret = bl_brt(default_brightness, 0); diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c old mode 100755 new mode 100644 index 69fd7d5..5f4717e --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -187,14 +187,21 @@ static int get_lcd_power(void) return dpms_get_state(); } +bool display_dimstay_check(void) +{ + if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) + return true; + + return false; +} + void change_brightness(int start, int end, int step) { int diff, val; int ret = -1; int prev; - if ((pm_status_flag & PWRSV_FLAG) && - !(pm_status_flag & BRTCH_FLAG)) + if (display_dimstay_check()) return; ret = backlight_ops.get_brightness(&prev); @@ -315,7 +322,7 @@ static int custom_backlight_update(void) custom_brightness > PM_MAX_BRIGHTNESS) return -EINVAL; - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) { + if (display_dimstay_check()) { ret = backlight_dim(); } else { _I("Custom brightness(%d) restored.", custom_brightness); @@ -343,7 +350,7 @@ static int backlight_update(void) _I("Custom brightness mode. brt no updated."); return 0; } - if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) + if (display_dimstay_check()) ret = backlight_dim(); else ret = bl_brt(default_brightness, 0); -- 2.7.4 From 38fd26bb86e677e7c428d5ad771ad3647d4d9174 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 30 May 2019 21:13:52 +0900 Subject: [PATCH 10/16] Add battery_health_changed to keep dim in case of bad battery health LCD dim has to be kept for bad battery health like HEALTH_LOW, HEALTH_HIGH, HEALTH_OVP. Battery_health_changed adds DIMSTAY_FLAG to pm_status_flag. It protects LCD change from dim to LCD_OFF by request of other applications or daemons. ex) lockstate, changestate in dbus-send Change-Id: I544259e07eb36967df11c1d709508651c214f079 Signed-off-by: lokilee73 --- plugins/mobile/display/core.c | 23 +++++++++++++++++++++++ plugins/wearable/display/core.c | 23 +++++++++++++++++++++++ src/display/core.h | 3 ++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index fe4d69b..f07c7fd 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -58,6 +58,7 @@ #include "dd-display.h" #include "display/display-dpms.h" #include "battery/battery.h" +#include "battery/power-supply.h" #define PM_STATE_LOG_FILE tzplatform_mkpath(TZ_SYS_ALLLOGS, "pm_state.log") #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -2105,6 +2106,26 @@ static int process_foreground(void *data) return 0; } +static int battery_health_changed(void *data) +{ + int health = DATA_VALUE_INT(data); + + _I("battery health change %d", health); + + if (health == HEALTH_GOOD) { + pm_status_flag &= ~BATTERY_FLAG; + pm_status_flag &= ~DIMSTAY_FLAG; + } else if (health == HEALTH_LOW || health == HEALTH_HIGH || health == HEALTH_OVP) { + pm_status_flag |= BATTERY_FLAG; + pm_status_flag |= DIMSTAY_FLAG; + } + + if (backlight_ops.get_lcd_power() == DPMS_ON) + backlight_ops.update(); + + return 0; +} + static int display_load_config(struct parse_result *result, void *user_data) { struct display_config *c = user_data; @@ -2246,6 +2267,7 @@ static void display_init(void *data) register_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); register_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); register_notifier(DEVICE_NOTIFIER_POWEROFF, device_poweroff); + register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); for (i = INIT_SETTING; i < INIT_END; i++) { switch (i) { @@ -2363,6 +2385,7 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); unregister_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); unregister_notifier(DEVICE_NOTIFIER_POWEROFF, device_poweroff); + unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); exit_input(); break; diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 4823071..776ccf6 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -58,6 +58,7 @@ #include "dd-display.h" #include "display/display-dpms.h" #include "battery/battery.h" +#include "battery/power-supply.h" #define PM_STATE_LOG_FILE tzplatform_mkpath(TZ_SYS_ALLLOGS, "pm_state.log") #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -2093,6 +2094,26 @@ static int process_background(void *data) return 0; } +static int battery_health_changed(void *data) +{ + int health = DATA_VALUE_INT(data); + + _I("battery health change %d", health); + + if (health == HEALTH_GOOD) { + pm_status_flag &= ~BATTERY_FLAG; + pm_status_flag &= ~DIMSTAY_FLAG; + } else if (health == HEALTH_LOW || health == HEALTH_HIGH || health == HEALTH_OVP) { + pm_status_flag |= BATTERY_FLAG; + pm_status_flag |= DIMSTAY_FLAG; + } + + if (backlight_ops.get_lcd_power() == DPMS_ON) + backlight_ops.update(); + + return 0; +} + static int process_foreground(void *data) { pid_t pid; @@ -2250,6 +2271,7 @@ static void display_init(void *data) register_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); register_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); register_notifier(DEVICE_NOTIFIER_POWEROFF, device_poweroff); + register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); for (i = INIT_SETTING; i < INIT_END; i++) { switch (i) { @@ -2367,6 +2389,7 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); unregister_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); unregister_notifier(DEVICE_NOTIFIER_POWEROFF, device_poweroff); + unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); exit_input(); break; diff --git a/src/display/core.h b/src/display/core.h index eb2b1b4..bd83cdc 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -39,7 +39,8 @@ #define PWRSV_FLAG 0x00000400 #define BRTCH_FLAG 0x00002000 #define PWROFF_FLAG 0x00004000 -#define DIMSTAY_FLAG 0x00008000 +#define DIMSTAY_FLAG 0x00008000 +#define BATTERY_FLAG 0x00020000 #define DEFAULT_NORMAL_TIMEOUT 30 -- 2.7.4 From 6a5ed5f88298b9ba95e238bfc5ff3506b8de73c0 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 25 Jun 2019 17:11:24 +0900 Subject: [PATCH 11/16] Change dpms_get_state to use HAL for lcd get state Change-Id: I465f01f4e8b2f4119fc8b2828ea2a909305d4bd2 Signed-off-by: lokilee73 --- plugins/iot/display/device-interface.c | 21 +++++++++++++++++---- plugins/mobile/display/device-interface.c | 21 +++++++++++++++++---- plugins/tv/display/device-interface.c | 21 +++++++++++++++++---- plugins/wearable/display/device-interface.c | 21 +++++++++++++++++---- 4 files changed, 68 insertions(+), 16 deletions(-) diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index 764fb47..d652988 100644 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -176,15 +176,28 @@ out: static int get_lcd_power(void) { + enum display_state val; + int ret; + if (ambient_get_state()) return DPMS_OFF; - if (!dpms_is_available()) { - _E("Dpms is not available."); + ret = display_dev->get_state(&val); + if (ret < 0) + return ret; + + switch (val) { + case DISPLAY_ON: + return DPMS_ON; + case DISPLAY_STANDBY: + return DPMS_STANDBY; + case DISPLAY_SUSPEND: + return DPMS_SUSPEND; + case DISPLAY_OFF: + return DPMS_OFF; + default: return -EINVAL; } - - return dpms_get_state(); } bool display_dimstay_check(void) diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 764fb47..d652988 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -176,15 +176,28 @@ out: static int get_lcd_power(void) { + enum display_state val; + int ret; + if (ambient_get_state()) return DPMS_OFF; - if (!dpms_is_available()) { - _E("Dpms is not available."); + ret = display_dev->get_state(&val); + if (ret < 0) + return ret; + + switch (val) { + case DISPLAY_ON: + return DPMS_ON; + case DISPLAY_STANDBY: + return DPMS_STANDBY; + case DISPLAY_SUSPEND: + return DPMS_SUSPEND; + case DISPLAY_OFF: + return DPMS_OFF; + default: return -EINVAL; } - - return dpms_get_state(); } bool display_dimstay_check(void) diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 764fb47..d652988 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -176,15 +176,28 @@ out: static int get_lcd_power(void) { + enum display_state val; + int ret; + if (ambient_get_state()) return DPMS_OFF; - if (!dpms_is_available()) { - _E("Dpms is not available."); + ret = display_dev->get_state(&val); + if (ret < 0) + return ret; + + switch (val) { + case DISPLAY_ON: + return DPMS_ON; + case DISPLAY_STANDBY: + return DPMS_STANDBY; + case DISPLAY_SUSPEND: + return DPMS_SUSPEND; + case DISPLAY_OFF: + return DPMS_OFF; + default: return -EINVAL; } - - return dpms_get_state(); } bool display_dimstay_check(void) diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 5f4717e..6aa4d48 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -176,15 +176,28 @@ out: static int get_lcd_power(void) { + enum display_state val; + int ret; + if (ambient_get_state()) return DPMS_OFF; - if (!dpms_is_available()) { - _E("Dpms is not available."); + ret = display_dev->get_state(&val); + if (ret < 0) + return ret; + + switch (val) { + case DISPLAY_ON: + return DPMS_ON; + case DISPLAY_STANDBY: + return DPMS_STANDBY; + case DISPLAY_SUSPEND: + return DPMS_SUSPEND; + case DISPLAY_OFF: + return DPMS_OFF; + default: return -EINVAL; } - - return dpms_get_state(); } bool display_dimstay_check(void) -- 2.7.4 From dcb52dce1e081e63ca35484835bdcec9bb35d599 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Tue, 25 Jun 2019 11:51:39 +0900 Subject: [PATCH 12/16] Add display(dpms) reply handling and retry Change-Id: I2a1c8dd3646c6b215b1c95c3fb53e5cf07561136 Signed-off-by: Hyotaek Shim Signed-off-by: lokilee73 Signed-off-by: Hyotaek Shim --- src/display/display-dpms.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) mode change 100755 => 100644 src/display/display-dpms.c diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c old mode 100755 new mode 100644 index 54127de..5a0220e --- a/src/display/display-dpms.c +++ b/src/display/display-dpms.c @@ -27,11 +27,13 @@ #include struct wl_display *display; +static struct wl_event_queue *queue; struct wl_output *wl_out; struct tizen_dpms_manager *tz_dpms_mng = NULL; int lcd_state = -1; bool wm_is_ready; static bool dpms_connected; +static int dpms_retry; bool check_wm_ready(void) { @@ -69,6 +71,7 @@ static void dpms_handle_state(void *data, struct tizen_dpms_manager *tz_dpms, ui { _D("dpms_state_cb - mode:%d, error:%d", mode, error); lcd_state = mode; + dpms_retry = 0; } static const struct tizen_dpms_manager_listener dpms_listener = { @@ -123,8 +126,19 @@ bool connect_interface_with_dpms(void) goto error; } + queue = wl_display_create_queue(display); + if (queue == NULL) { + printf(" failed wl_display_create_queue\n"); + goto error; + } + + wl_proxy_set_queue((struct wl_proxy *)display, queue); + wl_proxy_set_queue((struct wl_proxy *)registry, queue); + wl_registry_add_listener(registry, ®istry_listener, NULL); - wl_display_roundtrip(display); + + wl_display_dispatch_queue(display, queue); + wl_display_roundtrip_queue(display, queue); if (!wl_out || !tz_dpms_mng) { _E("Roundtrip failed."); @@ -161,14 +175,26 @@ bool dpms_is_available(void) void dpms_set_state(int on) { + dpms_retry = 1; + tizen_dpms_manager_set_dpms(tz_dpms_mng, wl_out, on); wl_display_roundtrip(display); + + while (dpms_retry) { + wl_display_dispatch_queue(display, queue); + } } int dpms_get_state(void) { + dpms_retry = 1; + tizen_dpms_manager_get_dpms(tz_dpms_mng, wl_out); wl_display_roundtrip(display); + while (dpms_retry) { + wl_display_dispatch_queue(display, queue); + } + return lcd_state; } -- 2.7.4 From 948b8c053fba45df77a293f1b29c52dc48c38031 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Tue, 25 Jun 2019 17:35:00 +0900 Subject: [PATCH 13/16] Fix build warning Change-Id: Ieb07f2399a87bba41c1f519791cb7172aa8f7764 --- src/usbhost/usb-host.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index 0e419b7..d3d46c2 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -455,7 +455,6 @@ static GVariant *get_device_list(GDBusConnection *conn, GVariant *gvar = NULL; dd_list *elem; struct usbhost_device *usbhost; - const char *str; int baseclass; GVariantBuilder *builder = NULL; const char *error = NULL; -- 2.7.4 From c229e2723ee6f442c8de4007bda994253cfa83d8 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 27 Jun 2019 13:48:23 +0900 Subject: [PATCH 14/16] Add protection code to prevent crash If there are not HAL for display_dev->get_state, crash occurs. So, add protection code for it. Change-Id: Ibe14f9dfa049dfbe3fd7f7cac1ad4b0cfc608ecf Signed-off-by: lokilee73 --- plugins/iot/display/device-interface.c | 5 +++++ plugins/mobile/display/device-interface.c | 5 +++++ plugins/tv/display/device-interface.c | 5 +++++ plugins/wearable/display/device-interface.c | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index d652988..e92582e 100644 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -182,6 +182,11 @@ static int get_lcd_power(void) if (ambient_get_state()) return DPMS_OFF; + if (!display_dev || !display_dev->get_state) { + _E("There is no display device."); + return -ENOENT; + } + ret = display_dev->get_state(&val); if (ret < 0) return ret; diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index d652988..e92582e 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -182,6 +182,11 @@ static int get_lcd_power(void) if (ambient_get_state()) return DPMS_OFF; + if (!display_dev || !display_dev->get_state) { + _E("There is no display device."); + return -ENOENT; + } + ret = display_dev->get_state(&val); if (ret < 0) return ret; diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index d652988..e92582e 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -182,6 +182,11 @@ static int get_lcd_power(void) if (ambient_get_state()) return DPMS_OFF; + if (!display_dev || !display_dev->get_state) { + _E("There is no display device."); + return -ENOENT; + } + ret = display_dev->get_state(&val); if (ret < 0) return ret; diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 6aa4d48..44d5f90 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -182,6 +182,11 @@ static int get_lcd_power(void) if (ambient_get_state()) return DPMS_OFF; + if (!display_dev || !display_dev->get_state) { + _E("There is no display device."); + return -ENOENT; + } + ret = display_dev->get_state(&val); if (ret < 0) return ret; -- 2.7.4 From 81ca7e5c0dc85ff98766ae074db01e15d3f1de36 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Fri, 28 Jun 2019 10:47:45 +0900 Subject: [PATCH 15/16] Add information about the relationship between unit dependencies Change-Id: Ia6f196c854933e5323ef6e7f4011541bd42494c1 --- systemd/deviced.service | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/systemd/deviced.service b/systemd/deviced.service index 3a286d9..69d25d8 100644 --- a/systemd/deviced.service +++ b/systemd/deviced.service @@ -1,6 +1,11 @@ [Unit] Description=System device daemon +# Caution: never uncomment belwo "Wants=" and "After=" entries. +# Just information, deviced internally wait for /run/.wm_ready +# Wants=display-manager.service +# After=display-manager.service + [Service] Type=notify SmackProcessLabel=System::Privileged -- 2.7.4 From 165cba04a67189aa95c78374ea3be355dce70c74 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 27 Jun 2019 20:50:32 +0900 Subject: [PATCH 16/16] Change function names and add lcd_on_procedure for changed ambient mode 1. change function names for unification ex) start_clock -> ambient_start_clock end_clock -> ambient_end_clock 2. add lcd_on_procedure for changed ambient mode Change-Id: I740ea105e41ef1199e40a0f9db70b3ba675df848 Signed-off-by: lokilee73 --- src/display/ambient-mode.c | 18 ++++++++++++------ src/display/core.h | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index b15fd56..f07a34a 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -65,14 +65,20 @@ int ambient_get_state(void) static void ambient_set_condition(keynode_t *key_nodes, void *data) { - int state; + int state, val; if (key_nodes == NULL) { _E("Wrong parameter, key_nodes is null."); return; } - ambient_condition = vconf_keynode_get_bool(key_nodes); + val = vconf_keynode_get_bool(key_nodes); + if (val != ambient_condition) { + if (backlight_ops.get_lcd_power() != DPMS_ON) + lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); + } + + ambient_condition = val; _I("Ambient mode condition is %d.", ambient_condition); state = (ambient_condition == 0 ? 0 : 1); @@ -130,7 +136,7 @@ void ambient_check_invalid_state(pid_t pid) backlight_ops.off(NORMAL_MODE); } -static void start_clock(void) +static void ambient_start_clock(void) { if (pm_cur_state == S_NORMAL || pm_cur_state == S_LCDDIM || @@ -142,7 +148,7 @@ static void start_clock(void) AMBIENT_CLOCK_WAITING_TIME); } -static void end_clock(pid_t pid) +static void ambient_end_clock(pid_t pid) { if (pm_cur_state == S_NORMAL || pm_cur_state == S_LCDDIM || @@ -170,9 +176,9 @@ int ambient_set_screen(char *screen, pid_t pid) return -EINVAL; if (!strncmp(screen, CLOCK_START, strlen(CLOCK_START))) - start_clock(); + ambient_start_clock(); else if (!strncmp(screen, CLOCK_END, strlen(CLOCK_END))) - end_clock(pid); + ambient_end_clock(pid); return 0; } diff --git a/src/display/core.h b/src/display/core.h index bd83cdc..3f656eb 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -193,6 +193,7 @@ int custom_lcdon(int timeout); void set_stay_touchscreen_off(int val); void set_lcd_paneloff_mode(int val); void lcd_on_direct(enum device_flags flags); +void lcd_on_procedure(int state, enum device_flags flag); void lcd_off_procedure(enum device_flags flag); int check_holdkey_block(enum state_t state); bool touch_event_blocked(void); -- 2.7.4