From 81ca7e5c0dc85ff98766ae074db01e15d3f1de36 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Fri, 28 Jun 2019 10:47:45 +0900 Subject: [PATCH 01/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 02/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 From 1573e8d1cbcc97e0cd2be348264864da001f14fd Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 2 Jul 2019 21:57:11 +0900 Subject: [PATCH 03/16] Apply changes for ambient mode 1. add ambient_lcdoff_signal_handler for signal from clock-viewer 2. change broadcasted signal from integer to string ex) 0, 1 -> ALPMOff, ALPMOn 3. move ambient_check_invalid_state to del_state_cond 4. add lcd_direct_control for lcd control Change-Id: Ice5f37124ad90f49ea21b618b99dade6901b8686 Signed-off-by: lokilee73 --- plugins/wearable/display/core.c | 26 ++++++++++++-- src/display/ambient-mode.c | 79 ++++++++++++++++++++++++++++++++++------- src/display/core.h | 2 ++ src/display/poll.h | 2 +- 4 files changed, 92 insertions(+), 17 deletions(-) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 776ccf6..2c171f6 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -383,6 +383,26 @@ bool touch_event_blocked(void) return touch_blocked; } +void lcd_direct_control(enum dpms_state state, int flags) +{ + const struct device_ops *ops = NULL; + dd_list *l = NULL; + + switch (state) { + case DPMS_ON: + DD_LIST_FOREACH(lcdon_ops, l, ops) + ops->start(flags); + break; + case DPMS_OFF: + DD_LIST_FOREACH(lcdon_ops, l, ops) + ops->stop(flags); + break; + default: + _E("state is wrong value %d", state); + break; + } +} + void lcd_on_procedure(int state, enum device_flags flag) { dd_list *l = NULL; @@ -648,6 +668,9 @@ static void del_state_cond(void *data, enum state_t state) pid = (pid_t)((intptr_t)data); _I("Delete process(%d)'s prohibit dim condition by timeout.", pid); + if (pid == INTERNAL_LOCK_AMBIENT) + ambient_check_invalid_state(pid); + tmp = find_node(state, pid); del_node(state, tmp); get_pname(pid, pname); @@ -1027,9 +1050,6 @@ static void proc_condition_unlock(PMMsg *data) if (state == S_LCDOFF) set_process_active(FALSE, pid); - if (ambient_get_state()) - ambient_check_invalid_state(pid); - _SD("[%s] Unlocked by pid=%d process=%s\n", states[state].name, pid, pname); set_unlock_time(pname, state); diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index f07a34a..4223dc5 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -30,7 +30,10 @@ #define ON "on" #define OFF "off" -#define SIGNAL_AMBIENT_MODE "AmbientMode" +#define SIGNAL_ALPMLCDOFF "ALPMLCDOff" +#define SIGNAL_ALPM_ON "ALPMOn" +#define SIGNAL_ALPM_OFF "ALPMOff" + #define CLOCK_START "clockstart" #define CLOCK_END "clockend" #define TIMEOUT_NONE (-1) @@ -44,13 +47,15 @@ static unsigned int update_count; void broadcast_ambient_state(int state) { int ret; + char *signal; + signal = (state == true ? SIGNAL_ALPM_ON : SIGNAL_ALPM_OFF); ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, - SIGNAL_AMBIENT_MODE, - g_variant_new("(i)", (state == 0 ? 0 : 1))); + signal, + NULL); if (ret < 0) - _E("Failed to send dbus signal(%s)", SIGNAL_AMBIENT_MODE); + _E("Failed to send dbus signal(%s)", signal); } int ambient_get_condition(void) @@ -96,7 +101,17 @@ int ambient_set_state(int on) update_count = 0; - if (!on) + /** + * When display is turned off before going to AOD, Generally pm receives + * clock signal or ALPMLCDOFF signal and decides to go to AOD or not. + * But a specific case, the signal is not received. + * So at that time deviced should turn off display to match the pair. + */ + if (on) { + if (disp_plgn.pm_lock_internal) + disp_plgn.pm_lock_internal(INTERNAL_LOCK_AMBIENT, + LCD_OFF, STAY_CUR_STATE, AMBIENT_CLOCK_WAITING_TIME); + } else ambient_pid = 0; _D("AMBIENT is %s.", (on ? ON : OFF)); @@ -113,9 +128,6 @@ 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) @@ -132,8 +144,11 @@ void ambient_check_invalid_state(pid_t pid) * deviced doesn't get the clock signal. * deviced just turns off lcd in this case. */ + reset_timeout(TIMEOUT_NONE); ambient_set_state(false); - backlight_ops.off(NORMAL_MODE); + lcd_direct_control(DPMS_OFF, NORMAL_MODE); + + broadcast_lcd_off_late(LCD_OFF_LATE_MODE); } static void ambient_start_clock(void) @@ -155,11 +170,14 @@ static void ambient_end_clock(pid_t pid) ambient_state == false) return; - if (update_count == 0) - broadcast_lcd_off_late(LCD_OFF_LATE_MODE); + if (update_count == 0) { + _D("lcd off"); - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, PM_SLEEP_MARGIN); + backlight_ops.off(NORMAL_MODE); + 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) @@ -183,6 +201,32 @@ int ambient_set_screen(char *screen, pid_t pid) return 0; } +static void ambient_lcdoff_signal_handler(GDBusConnection *conn, + const gchar *sender, + const gchar *path, + const gchar *iface, + const gchar *name, + GVariant *param, + gpointer data) +{ + if (ambient_state == false) { + _E("It is not alpm mode"); + return; + } + + if (disp_plgn.pm_lock_internal) + disp_plgn.pm_lock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, GOTO_STATE_NOW, 0); + + _I("Display off in suspend state"); + + ambient_set_state(false); + lcd_direct_control(DPMS_OFF, NORMAL_MODE); + + 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); +} + static void ambient_init(void *data) { int ret; @@ -197,6 +241,15 @@ static void ambient_init(void *data) vconf_notify_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, ambient_set_condition, NULL); + + ret = subscribe_dbus_signal(NULL, + DEVICED_OBJECT_PATH, + DEVICED_INTERFACE_NAME, + SIGNAL_ALPMLCDOFF, + ambient_lcdoff_signal_handler, + NULL, NULL); + if (ret <= 0) + _E("Failed to register signal handler: %d", ret); } static void ambient_exit(void *data) diff --git a/src/display/core.h b/src/display/core.h index 3f656eb..a58543c 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -195,11 +195,13 @@ 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); +void lcd_direct_control(enum dpms_state state, int flags); int check_holdkey_block(enum state_t state); bool touch_event_blocked(void); int device_poweroff(void *data); void broadcast_lcd_off_late(enum device_flags flags); void set_dim_state(bool on); +void reset_timeout(int timeout); /* poll.c */ int check_dimstay(int next_state, int flag); diff --git a/src/display/poll.h b/src/display/poll.h index 736e20f..93afe57 100644 --- a/src/display/poll.h +++ b/src/display/poll.h @@ -42,6 +42,7 @@ enum { enum { INTERNAL_LOCK_BASE = 100000, + INTERNAL_LOCK_AMBIENT, INTERNAL_LOCK_BATTERY, INTERNAL_LOCK_BATTERY_FULL, INTERNAL_LOCK_BOOTING, @@ -61,7 +62,6 @@ enum { INTERNAL_LOCK_POWERKEY, INTERNAL_LOCK_PM, INTERNAL_LOCK_HALLIC, - INTERNAL_LOCK_AMBIENT, INTERNAL_LOCK_SWIM, }; -- 2.7.4 From 9b49485e9fb358f558df6a5642b9781e654d0c63 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 4 Jul 2019 15:30:28 +0900 Subject: [PATCH 04/16] Fix error while loading display.so ex) Failed to open module: /usr/lib/deviced/display.so: undefined symbol: lcd_direct_control Change-Id: I2f9ddc746fea3170bdaeb8faad10233595323733 Signed-off-by: lokilee73 --- plugins/iot/display/core.c | 2 +- plugins/mobile/display/core.c | 2 +- plugins/tv/display/core.c | 2 +- plugins/wearable/display/core.c | 22 +------------------ src/display/ambient-mode.c | 1 + src/display/core.h | 2 +- src/display/display.c | 47 +++++++++++++++++++++++++++++++++++++++++ src/display/display.h | 27 +++++++++++++++++++++++ 8 files changed, 80 insertions(+), 25 deletions(-) create mode 100644 src/display/display.c create mode 100644 src/display/display.h diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index fe4d69b..42ef795 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -103,9 +103,9 @@ static int lock_screen_timeout = LOCK_SCREEN_INPUT_TIMEOUT; static struct timeval lcdon_tv; static int lcd_paneloff_mode = false; static int stay_touchscreen_off = false; -static dd_list *lcdon_ops; static bool lcdon_broadcast = true; static bool touch_blocked = false; +dd_list *lcdon_ops; /* default transition, action fuctions */ static int default_trans(int evt); diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index f07c7fd..d38d9ac 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -104,9 +104,9 @@ static int lock_screen_timeout = LOCK_SCREEN_INPUT_TIMEOUT; static struct timeval lcdon_tv; static int lcd_paneloff_mode = false; static int stay_touchscreen_off = false; -static dd_list *lcdon_ops; static bool lcdon_broadcast = true; static bool touch_blocked = false; +dd_list *lcdon_ops; /* default transition, action fuctions */ static int default_trans(int evt); diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 5bf09f7..7529349 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -105,9 +105,9 @@ static int lock_screen_timeout = LOCK_SCREEN_INPUT_TIMEOUT; static struct timeval lcdon_tv; static int lcd_paneloff_mode = false; static int stay_touchscreen_off = false; -static dd_list *lcdon_ops; static bool lcdon_broadcast = true; static bool touch_blocked = false; +dd_list *lcdon_ops; /* default transition, action fuctions */ static int default_trans(int evt); diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 2c171f6..bf6ff62 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -104,9 +104,9 @@ static int lock_screen_timeout = LOCK_SCREEN_INPUT_TIMEOUT; static struct timeval lcdon_tv; static int lcd_paneloff_mode = false; static int stay_touchscreen_off = false; -static dd_list *lcdon_ops; static bool lcdon_broadcast = true; static bool touch_blocked = false; +dd_list *lcdon_ops; /* default transition, action fuctions */ static int default_trans(int evt); @@ -383,26 +383,6 @@ bool touch_event_blocked(void) return touch_blocked; } -void lcd_direct_control(enum dpms_state state, int flags) -{ - const struct device_ops *ops = NULL; - dd_list *l = NULL; - - switch (state) { - case DPMS_ON: - DD_LIST_FOREACH(lcdon_ops, l, ops) - ops->start(flags); - break; - case DPMS_OFF: - DD_LIST_FOREACH(lcdon_ops, l, ops) - ops->stop(flags); - break; - default: - _E("state is wrong value %d", state); - break; - } -} - void lcd_on_procedure(int state, enum device_flags flag) { dd_list *l = NULL; diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index 4223dc5..9254100 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -23,6 +23,7 @@ #include "util.h" #include "core.h" +#include "display.h" #include "display-ops.h" #include "core/device-notifier.h" #include "core/devices.h" diff --git a/src/display/core.h b/src/display/core.h index a58543c..1bb77df 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -158,6 +158,7 @@ struct display_keyfilter_ops { }; extern const struct display_keyfilter_ops *keyfilter_ops; +extern dd_list *lcdon_ops; /* If the bit in a condition variable is set, * we cannot transit the state until clear this bit. */ @@ -195,7 +196,6 @@ 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); -void lcd_direct_control(enum dpms_state state, int flags); int check_holdkey_block(enum state_t state); bool touch_event_blocked(void); int device_poweroff(void *data); diff --git a/src/display/display.c b/src/display/display.c new file mode 100644 index 0000000..de55369 --- /dev/null +++ b/src/display/display.c @@ -0,0 +1,47 @@ +/* + * deviced + * + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include + +#include "util.h" +#include "core.h" +#include "display-ops.h" +#include "core/list.h" +#include "core/common.h" + +void lcd_direct_control(enum dpms_state state, int flags) +{ + const struct device_ops *ops = NULL; + dd_list *l = NULL; + + switch (state) { + case DPMS_ON: + DD_LIST_FOREACH(lcdon_ops, l, ops) + ops->start(flags); + break; + case DPMS_OFF: + DD_LIST_FOREACH(lcdon_ops, l, ops) + ops->stop(flags); + break; + default: + _E("state is wrong value %d", state); + break; + } +} + diff --git a/src/display/display.h b/src/display/display.h new file mode 100644 index 0000000..3b14241 --- /dev/null +++ b/src/display/display.h @@ -0,0 +1,27 @@ +/* + * deviced + * + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __DISPLAY_H__ +#define __DISPLAY_H__ + +#include "device-interface.h" +#include "core/common.h" + +void lcd_direct_control(enum dpms_state state, int flags); +#endif -- 2.7.4 From 09393e2c3a133c4a3e7a1f54d84918fcb9f32376 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Fri, 5 Jul 2019 14:35:35 +0900 Subject: [PATCH 05/16] Add omitted dependency (zlib) Change-Id: I4b4ec163a271a2da0909dd9e379b016962710367 Signed-off-by: Inkyun Kil --- CMakeLists.txt | 1 + packaging/deviced.spec | 1 + 2 files changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a90dec1..33ca1c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -179,6 +179,7 @@ SET(PKG_MODULES wayland-client tizen-extension-client tizen-dpms-client + zlib ) IF(DISPLAY_MODULE STREQUAL on) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index b895131..fd8a375 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -40,6 +40,7 @@ BuildRequires: pkgconfig(capi-system-device) BuildRequires: pkgconfig(wayland-client) BuildRequires: pkgconfig(tizen-extension-client) BuildRequires: pkgconfig(tizen-dpms-client) +BuildRequires: pkgconfig(zlib) Requires: %{name}-tools = %{version}-%{release} %{?systemd_requires} -- 2.7.4 From 140d39399ef70fe38eb55a408c2e317cf35bd9f8 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Mon, 8 Jul 2019 20:11:20 +0900 Subject: [PATCH 06/16] Fix memory leak Change-Id: Ie34f039aeab698ba33f8edb9611a82b22ffc6de6 Signed-off-by: lokilee73 --- src/core/launch.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/launch.c b/src/core/launch.c index 0f97efd..136ed47 100644 --- a/src/core/launch.c +++ b/src/core/launch.c @@ -47,10 +47,11 @@ static int set_current_lang(void) } ret = setenv("LANG", lang, 1); + free(lang); if (ret < 0) return -1; - free(lang); - return 0; + else + return 0; } -- 2.7.4 From ed64d48ff1bdfbbbbee0515dadaa7acebb8b696e Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 5 Jul 2019 10:46:34 +0900 Subject: [PATCH 07/16] Apply async for dpms change communication method with dpms, from sync to async. Change-Id: I50894dc5b2b3420d0fb9335e298601a400eb120a 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 - src/display/display-dpms.c | 374 ++++++++++++++++++++++------ 5 files changed, 291 insertions(+), 103 deletions(-) diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index e92582e..01b98ac 100644 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -74,11 +74,6 @@ static struct display_device *display_dev; static int bl_onoff(int on) { - if (!dpms_is_available()) { - _E("Dpms is not available."); - return -EINVAL; - } - dpms_set_state(on); return 0; } diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index e92582e..01b98ac 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -74,11 +74,6 @@ static struct display_device *display_dev; static int bl_onoff(int on) { - if (!dpms_is_available()) { - _E("Dpms is not available."); - return -EINVAL; - } - dpms_set_state(on); return 0; } diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index e92582e..01b98ac 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -74,11 +74,6 @@ static struct display_device *display_dev; static int bl_onoff(int on) { - if (!dpms_is_available()) { - _E("Dpms is not available."); - return -EINVAL; - } - dpms_set_state(on); return 0; } diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 44d5f90..f44c51a 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -74,11 +74,6 @@ static struct display_device *display_dev; static int bl_onoff(int on) { - if (!dpms_is_available()) { - _E("Dpms is not available."); - return -EINVAL; - } - dpms_set_state(on); return 0; } diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c index 5a0220e..b1a6221 100644 --- a/src/display/display-dpms.c +++ b/src/display/display-dpms.c @@ -20,58 +20,71 @@ #include #include #include -#include "core/log.h" -#include "display/util.h" +#include #include #include #include +#include "core/log.h" +#include "display/util.h" + +typedef struct { + GSource gsource; + GPollFD gfd; + gboolean prepared; + + struct wl_display *wl_disp; + struct wl_registry *wl_registry; + struct wl_output *wl_output; + struct tizen_dpms_manager *tz_dpms_mng; + + uint32_t dpms_mode; +} wl_glib_info; + +wl_glib_info *info = NULL; -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; +static GSource *wl_glib_data = NULL; -bool check_wm_ready(void) +static void dpms_handle_state(void *data, struct tizen_dpms_manager *tz_dpms, uint32_t mode, uint32_t error) { - 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; + _D("Dpms_state_cb - mode:%u, error:%u", mode, error); + info->dpms_mode = mode; } void disconnect_interface_with_dpms(void) { - if (tz_dpms_mng) { - tizen_dpms_manager_destroy(tz_dpms_mng); - tz_dpms_mng = NULL; + if (!info) { + _E("Info is NULL."); + return; } - if (wl_out) { - wl_output_destroy(wl_out); - wl_out = NULL; + if (info->tz_dpms_mng) { + tizen_dpms_manager_destroy(info->tz_dpms_mng); + info->tz_dpms_mng = NULL; } - if (display) { - wl_display_disconnect(display); - display = NULL; + if (info->wl_output) { + wl_output_destroy(info->wl_output); + info->wl_output = NULL; } - dpms_connected = false; -} + if (info->wl_registry) { + wl_registry_destroy(info->wl_registry); + info->wl_registry= 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; - dpms_retry = 0; + if (info->wl_disp) { + wl_display_disconnect(info->wl_disp); + info->wl_disp= NULL; + } + + if (wl_glib_data) { + g_source_destroy(wl_glib_data); + wl_glib_data = NULL; + } + + dpms_connected = false; } static const struct tizen_dpms_manager_listener dpms_listener = { @@ -81,20 +94,26 @@ static const struct tizen_dpms_manager_listener dpms_listener = { static void handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { + if (!data) { + _E("Data is NULL."); + return; + } + info = (wl_glib_info *)data; + 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."); + info->wl_output= wl_registry_bind(registry, name, &wl_output_interface, 2); + if (!info->wl_output) { + _E("Failed to bind registry."); 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."); + info->tz_dpms_mng = wl_registry_bind(registry, name, &tizen_dpms_manager_interface, 1); + if (!info->tz_dpms_mng) { + _E("Failed to bind registry."); disconnect_interface_with_dpms(); - } - tizen_dpms_manager_add_listener(tz_dpms_mng, &dpms_listener, NULL); + } else + tizen_dpms_manager_add_listener(info->tz_dpms_mng, &dpms_listener, info); _D("Get dpms manager."); } @@ -110,52 +129,240 @@ static const struct wl_registry_listener registry_listener = { handle_global_remove }; -bool connect_interface_with_dpms(void) +static int +wl_glib_wayland_init(wl_glib_info *info) { - struct wl_registry *registry = NULL; + int ret; - display = wl_display_connect(NULL); - if (display == NULL) { - _E("Display is NULL."); - goto error; + info->wl_disp = wl_display_connect(NULL); + if (info->wl_disp == NULL) { + _E("Failed to connect display."); + goto err; } - registry = wl_display_get_registry(display); - if (registry == NULL) { - _E("Registry is NULL."); - goto error; + info->wl_registry = wl_display_get_registry(info->wl_disp); + if (info->wl_registry == NULL) { + _E("Failed to get display registry."); + goto err; } - queue = wl_display_create_queue(display); - if (queue == NULL) { - printf(" failed wl_display_create_queue\n"); - goto error; + ret = wl_registry_add_listener(info->wl_registry, ®istry_listener, info); + if (ret) { + _E("Failed to add registry listener."); + goto err; } - wl_proxy_set_queue((struct wl_proxy *)display, queue); - wl_proxy_set_queue((struct wl_proxy *)registry, queue); + ret = wl_display_roundtrip(info->wl_disp); + if (ret < 0 || info->wl_output == NULL) { + _E("Failed to roundtrip display."); + goto err; + } - wl_registry_add_listener(registry, ®istry_listener, NULL); + return 0; - wl_display_dispatch_queue(display, queue); - wl_display_roundtrip_queue(display, queue); +err: + return -1; +} - if (!wl_out || !tz_dpms_mng) { - _E("Roundtrip failed."); - goto error; +static gboolean +wl_glib_client_prepare(GSource *source, gint *time) +{ + if (!source) { + _E("Source is NULL."); + return FALSE; } + info = (wl_glib_info *)source; - wl_registry_destroy(registry); - _D("Setup with dpms is done."); - return true; + /* If info is already prepared, do nothing in this function. */ + if (info->prepared == TRUE) + return FALSE; + + while (wl_display_prepare_read(info->wl_disp) != 0) { + if (wl_display_dispatch_pending(info->wl_disp) == -1) + _E("Failed to dispatch display pending."); + } + + info->prepared = TRUE; + + wl_display_flush(info->wl_disp); + *time = -1; + + return FALSE; +} + +static gboolean +wl_glib_client_check(GSource *source) +{ + gboolean ret = FALSE; + int wl_ret = 0; + + if (!source) { + _E("Source is NULL."); + return FALSE; + } + info = (wl_glib_info *)source; + if (g_source_is_destroyed(source)) { + if (info && info->wl_disp && info->prepared) + wl_display_cancel_read(info->wl_disp); + _E("Display source(%p) already destroyed.", source); + return ret; + } + + if (!info->prepared) + return ret; + + if (info->gfd.revents & (G_IO_HUP|G_IO_ERR)) { + wl_display_cancel_read(info->wl_disp); + goto err; + } + + if (info->gfd.revents & G_IO_IN) { + wl_ret = wl_display_read_events(info->wl_disp); + if (wl_ret < 0) { + _E("Failed to read display events: %d", wl_ret); + goto err; + } + ret = TRUE; + } else + wl_display_cancel_read(info->wl_disp); + + info->prepared = FALSE; + + return ret; + +err: + _E("Get ERROR in check: revent:0x%x, wl_err:%d", info->gfd.revents, wl_ret); + + info->prepared = FALSE; + g_source_destroy(source); + + return FALSE; +} + +static gboolean +wl_glib_client_dispatch(GSource *source, GSourceFunc cb, gpointer data) +{ + int ret = 0; + + if (!source) { + _E("Source is NULL."); + return G_SOURCE_REMOVE; + } + info = (wl_glib_info *)source; + + if (g_source_is_destroyed(source)) { + _E("Display source(%p) already destroyed.", source); + return G_SOURCE_REMOVE; + } + + if (info->gfd.revents & (G_IO_HUP|G_IO_ERR)) + goto err; + + if (info->gfd.revents & G_IO_IN) { + ret = wl_display_dispatch_pending(info->wl_disp); + if (ret == -1) { + _E("Failed to dispatch display pending: %d", ret); + goto err; + } + } + + ret = wl_display_flush(info->wl_disp); + if (ret == -1) { + _E("Failed to flush display: %d", ret); + goto err; + } + + return G_SOURCE_CONTINUE; + +err: + _E("Err in dispatch: revent:0x%x, wl_err:%d", info->gfd.revents, ret); + + return G_SOURCE_REMOVE; +} + +static void +wl_glib_client_finalize(GSource *source) +{ + if (!source) { + _E("Source is NULL."); + return; + } + info = (wl_glib_info *)source; -error: - if (registry) - wl_registry_destroy(registry); disconnect_interface_with_dpms(); + return; +} + +static GSourceFuncs wl_glib_client_funcs = { + .prepare = wl_glib_client_prepare, + .check = wl_glib_client_check, + .dispatch = wl_glib_client_dispatch, + .finalize = wl_glib_client_finalize, +}; + +GSource* wl_glib_client_init(void) +{ + int ret; + + info = (wl_glib_info *)g_source_new(&wl_glib_client_funcs, sizeof(wl_glib_info)); + if (info == NULL) { + _E("Failed to make g_source_new."); + goto err; + } + + ret = wl_glib_wayland_init(info); + if (ret < 0) { + _E("Failed to init wayland."); + goto err; + } + + info->gfd.fd = wl_display_get_fd(info->wl_disp); + if (info->gfd.fd < 0) { + _E("Failed to get display fd"); + goto err; + } + + info->gfd.events = G_IO_IN | G_IO_ERR; + info->gfd.revents = 0; + + g_source_add_poll(&info->gsource, &info->gfd); + g_source_attach(&info->gsource, NULL); + g_source_unref(&info->gsource); + + return &info->gsource; + +err: + if (info) { + disconnect_interface_with_dpms(); + g_source_unref(&info->gsource); + } + + return NULL; +} + +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; } +bool connect_interface_with_dpms(void) +{ + wl_glib_data = wl_glib_client_init(); + if (!wl_glib_data) { + _E("Failed to init client."); + return false; + } + + return true; +} + bool dpms_is_available(void) { /* Check window manager */ @@ -175,26 +382,27 @@ bool dpms_is_available(void) void dpms_set_state(int on) { - dpms_retry = 1; + uint32_t mode; - tizen_dpms_manager_set_dpms(tz_dpms_mng, wl_out, on); - wl_display_roundtrip(display); - - while (dpms_retry) { - wl_display_dispatch_queue(display, queue); + if (!dpms_is_available()) { + _E("Dpms is not available."); + return; } + + mode = (uint32_t)on; + tizen_dpms_manager_set_dpms(info->tz_dpms_mng, info->wl_output, mode); + wl_display_flush(info->wl_disp); } 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); + if (!dpms_is_available()) { + _E("Dpms is not available."); + return -EINVAL; } - return lcd_state; + tizen_dpms_manager_get_dpms(info->tz_dpms_mng, info->wl_output); + wl_display_flush(info->wl_disp); + + return (int)info->dpms_mode; } -- 2.7.4 From 6e436233f52d835e3f3d7961a1ca4f5471a979d9 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Tue, 9 Jul 2019 18:23:59 +0900 Subject: [PATCH 08/16] usb-host-test: ignore failure module load/unload when it is built-in Even though dummy_hcd and usb_f_fs are kernel built-in module, module load failure blocks usb-host-test. Just ignore the failure of module load/unload when it is built-in. Change-Id: I3bd7084cf2ce4b5806d272662ecd16f7b97cc11c Signed-off-by: Seung-Woo Kim Signed-off-by: Hyotaek Shim --- src/usb-host-test/usb-host-test.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/usb-host-test/usb-host-test.c b/src/usb-host-test/usb-host-test.c index fc687da..5ba6d91 100644 --- a/src/usb-host-test/usb-host-test.c +++ b/src/usb-host-test/usb-host-test.c @@ -32,6 +32,8 @@ #include "core/devices.h" #include "core/list.h" +#define SYS_DUMMY_HCD_PATH "/sys/module/dummy_hcd" +#define SYS_USB_FFS_PATH "/sys/kernel/config/usb_gadget/hal-gadget/functions/ffs.sdb.default" #define FFS_PATH "/run/usb-host-test-ffs" #define GADGET_SCHEME_PATH "/etc/deviced/usb-host-test/test_gadget.gs" #define FFS_INSTANCE_NAME "usb-host-test" @@ -338,8 +340,7 @@ static void service_stopped_handler(GDBusConnection *conn, ret = unload_module("dummy_hcd"); if (ret < 0) { - _E("Error unloading module: %d", ret); - goto out1; + _I("Unable to unload module: %d", ret); } if (using_legacy) { @@ -351,8 +352,7 @@ static void service_stopped_handler(GDBusConnection *conn, } else { ret = unload_module("usb_f_fs"); if (ret < 0) { - _E("Error unloading module: %d", ret); - goto out; + _I("Unable to unload module: %d", ret); } } @@ -378,8 +378,11 @@ int start() ret = load_module("dummy_hcd", NULL); if (ret < 0) { - _E("Error loading module: %d", ret); - return ret; + /* if dummy_hcd is built-in, then just ignore */ + if (stat(SYS_DUMMY_HCD_PATH, &st) < 0) { + _E("Error loading module: %d", ret); + return ret; + } } /* If you need to setup vid, pid or other data use module parameters */ @@ -398,8 +401,11 @@ int start() ret = load_module("usb_f_fs", NULL); if (ret < 0) { - _E("Error loading module: %d", ret); - return ret; + /* if usb_f_fs is already used, then just ignore */ + if (stat(SYS_USB_FFS_PATH, &st) < 0) { + _E("Error loading module: %d", ret); + return ret; + } } ret = load_gadget(); -- 2.7.4 From 6b026c8384af059dc44ed1a8bb2779f64faac62e Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Mon, 8 Jul 2019 20:26:40 +0900 Subject: [PATCH 09/16] Delete meaningless configuration Change-Id: Ifb04e88ce3b75fe4aa3f379af3532c7f0f4ec513 --- systemd/org.tizen.system.deviced.service | 1 - 1 file changed, 1 deletion(-) diff --git a/systemd/org.tizen.system.deviced.service b/systemd/org.tizen.system.deviced.service index 3a592cc..1a2aa14 100644 --- a/systemd/org.tizen.system.deviced.service +++ b/systemd/org.tizen.system.deviced.service @@ -1,5 +1,4 @@ [D-BUS Service] Name=org.tizen.system.deviced Exec=/bin/false -User=root SystemdService=deviced.service -- 2.7.4 From b7467a226bf389bac65bd925939697c9e04ad4a6 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 16 Jul 2019 14:20:35 +0900 Subject: [PATCH 10/16] Add exception code for tz_dpms_mng If tz_dpms_mng is NULL, it means deviced cannot use internal APIs supported by enlightenment. So, if it is NULL, we have to disconnect interface with dpms Change-Id: If8b78c96301c3b45b95d08a1bc5fafe90c1088ec Signed-off-by: lokilee73 --- src/display/display-dpms.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c index b1a6221..ef62f03 100644 --- a/src/display/display-dpms.c +++ b/src/display/display-dpms.c @@ -153,11 +153,21 @@ wl_glib_wayland_init(wl_glib_info *info) } ret = wl_display_roundtrip(info->wl_disp); - if (ret < 0 || info->wl_output == NULL) { + if (ret < 0) { _E("Failed to roundtrip display."); goto err; } + if (!info->wl_output) { + _E("Failed to get wl_output."); + goto err; + } + + if (!info->tz_dpms_mng) { + _E("Failed to get dpms protocol."); + goto err; + } + return 0; err: @@ -370,6 +380,7 @@ bool dpms_is_available(void) _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()"); -- 2.7.4 From 4d5ff920166526210223c2ec892ae5e1f731b863 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 19 Jul 2019 11:26:03 +0900 Subject: [PATCH 11/16] Change strcmp to strcasecmp to detect lower case and upper case as well Change-Id: Ib0bd7e475ea5046e628000c84e499e9d87b6b5c0 Signed-off-by: lokilee73 --- src/extcon/extcon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extcon/extcon.c b/src/extcon/extcon.c index 3afb4ce..145eeda 100644 --- a/src/extcon/extcon.c +++ b/src/extcon/extcon.c @@ -60,7 +60,7 @@ static struct extcon_ops *find_extcon(const char *name) return NULL; DD_LIST_FOREACH(extcon_list, l, dev) { - if (!strcmp(dev->name, name)) + if (!strcasecmp(dev->name, name)) return dev; } -- 2.7.4 From d0dcb3988b932d11e0d8151ddf92c4f31a6c0322 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 30 May 2019 17:40:53 +0900 Subject: [PATCH 12/16] Apply new algorithm for battery health When battery health is bad such as high, low or ovp, we have to alarm users. Expecially, in case of wearable device, it can hurt users by heat. So, to protect it, apply a new algorithm to warn users periodically. A new concept about bad bttery health: 1. Launch popup when battery.health is HEALTH_LOW or HEALTH_HIGH 2. Keep LCD_NORMAL for 10 seconds 3. Set relaunch timer to 3.6 seconds, When lcd state is LCD_OFF 4. Set lcd state to LCD_NORMAL 5. go to 1 step newly added functions for it - update_health_pm_status(): LCD OFF and unlock LCD_DIM - change_health_popup_timer(): set health_poup_timer - health_popup_timer_init(): initialize health_popup_timer - launch_health_popup(): launch popup in case of HEALTH_HIGH and HEALTH_LOW do_not_disturb() - apply a new function to check if it is in do_not_disturb mode - remove memory/shealth/sleep/do_not_disturb because it is not used anymore battery_pm_change_internal() - apply a new function to check battery_do_not_disturb() reorganize update_health(), update_ovp() display_changed() - change to return current state, when input is NULL - add launch popup in case of HEALTH_LOW and HEALTH_HIGH check_abnormal_status() - change name from check_battery_status(), because it only deals with abnormal status - modify to refer to old_battery Change-Id: I328588e8805f8b4a2790036cbd2a8c8cbc6a7831 Signed-off-by: lokilee73 --- src/battery/battery.h | 2 +- src/battery/lowbat-handler.c | 23 +--- src/battery/power-supply.c | 312 +++++++++++++++++++++++++++++++------------ 3 files changed, 233 insertions(+), 104 deletions(-) diff --git a/src/battery/battery.h b/src/battery/battery.h index 5c38207..8dc15a1 100644 --- a/src/battery/battery.h +++ b/src/battery/battery.h @@ -40,5 +40,5 @@ struct battery_config_info { int battery_charge_err_low_act(void *data); int battery_charge_err_high_act(void *data); - +bool battery_do_not_disturb(void); #endif /* __BATTERY_H__ */ diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 0ba1ae1..f952633 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -293,7 +293,6 @@ int lowbat_popup(char *option) static int lowbat_popup_option; int ret; int power_source = 1; - int r_disturb, s_disturb, r_block, s_block; static char *value; char *active_noti = NULL, *event_noti = NULL; char temp[10] = {0,}; @@ -329,25 +328,17 @@ int lowbat_popup(char *option) direct_launch: _D("Popup value=%s", value); if (booting_done(NULL)) { - if (battery.charge_now) { + + if (battery.charge_now && + (lowbat_popup_option == LOWBAT_OPT_CHECK || + lowbat_popup_option == LOWBAT_OPT_WARNING)) { _I("Skip low battery popup during charging."); return 0; } - r_disturb = vconf_get_int("memory/shealth/sleep/do_not_disturb", &s_disturb); - if (r_disturb < 0) - _E("Failed to get vconf value for do not disturb: %d", vconf_get_ext_errno()); - r_block = vconf_get_bool("db/setting/blockmode_wearable", &s_block); - if (r_block < 0) - _E("Failed to get vconf value for blockmode wearable: %d", vconf_get_ext_errno()); - - if ((r_disturb != 0 && r_block != 0) || - (s_disturb == 0 && s_block == 0) || - lowbat_popup_option == LOWBAT_OPT_CHARGEERR) { - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_LOWBAT, LCD_NORMAL); - } else { - _I("Block LCD."); + if (battery_do_not_disturb()) { + _I("block LCD and %s Popup", value); + return 0; } if (lowbat_popup_option == LOWBAT_OPT_CHECK || diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 2b092d6..1099556 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -32,6 +32,7 @@ #include "core/config-parser.h" #include "display/poll.h" #include "display/setting.h" +#include "display/core.h" #include "display/display-ops.h" #include "apps/apps.h" #include "power-supply.h" @@ -55,6 +56,9 @@ #define SIGNAL_TEMP_GOOD "TempGood" #define ABNORMAL_CHECK_TIMER_INTERVAL 60 +#define LCD_DIM_TIME_IN_BATTERY_HEALTH 10000 /* ms */ +#define HEALTH_POPUP_TERMINATE_TIMEOUT 10 +#define HEALTH_POPUP_RELAUNCH_TIMEOUT 3600 #define METHOD_FULL_NOTI_ON "BatteryFullNotiOn" #define METHOD_FULL_NOTI_OFF "BatteryFullNotiOff" @@ -73,6 +77,21 @@ struct battery_status old_battery; static int noti_id; static guint power_timer; +#ifdef TIZEN_FEATURE_BATTERY_OVER_TEMPERATURE +static guint health_popup_timer; +static struct timespec health_relaunch_start_st; +static struct timespec health_relaunch_end_st; +#endif /* TIZEN_FEATURE_BATTERY_OVER_TEMPERATURE */ + +bool battery_do_not_disturb(void); + +static int battery_pm_change_internal(int pid, int s_bits); +static int display_changed(void *data); +#ifdef TIZEN_FEATURE_BATTERY_OVER_TEMPERATURE +static void health_popup_timer_init(const char *func); +static void update_health_popup_relaunch_time(int timeout); +static void change_health_popup_timer(enum battery_noti_status status); +#endif /* TIZEN_FEATURE_BATTERY_OVER_TEMPERATURE */ static int booting_done(void *data); static struct battery_device *battery_dev; @@ -91,9 +110,9 @@ static void pm_check_and_change(int bInserted) if (old == bInserted) return; + old = bInserted; - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); + battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); } static int changed_battery_cf(enum present_type status) @@ -109,13 +128,13 @@ static int changed_battery_cf(enum present_type status) 2, APP_KEY_TYPE, value); } +#ifdef TIZEN_FEATURE_BATTERY_OVER_TEMPERATURE static void health_status_broadcast(void) { dbus_handle_broadcast_dbus_signal(DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, SIGNAL_TEMP_GOOD, NULL, NULL); } -#ifdef TIZEN_FEATURE_BATTERY_OVER_TEMPERATURE static guint abnormal_timer; static void abnormal_popup_timer_init(void) @@ -142,8 +161,9 @@ static gboolean health_timer_cb(void *data) _I("Popup: Battery health status is not good."); device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)&battery.health); - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); + battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_DIM); + if (disp_plgn.pm_unlock_internal) + disp_plgn.pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); if (disp_plgn.pm_lock_internal) disp_plgn.pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, 0); if (battery.health == HEALTH_LOW) @@ -291,6 +311,9 @@ static int send_charge_noti(void) int ret = 0; int retry; + if (battery_do_not_disturb()) + return ret; + for (retry = RETRY_MAX; retry > 0; retry--) { ret = dbus_handle_method_async_with_reply(POPUP_BUS_NAME, POPUP_PATH_NOTI, @@ -378,12 +401,11 @@ static void noti_batt_full(void) bat_full_noti = 1; /* turn on LCD, if battery is full charged */ noti = check_power_supply_noti(); - if (noti) { - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_BATTERY_FULL, LCD_NORMAL); - } else { + if (noti) + battery_pm_change_internal(INTERNAL_LOCK_BATTERY_FULL, LCD_NORMAL); + else _I("Block LCD."); - } + /* on the full charge state */ device_notify(DEVICE_NOTIFIER_FULLBAT, (void *)&bat_full_noti); } @@ -430,121 +452,106 @@ static void charger_state_send_system_event(int state) static void update_present(enum battery_noti_status status) { - static int old = DEVICE_NOTI_OFF; - enum present_type present; - - if (old == status) - return; _I("charge=%d present=%d", battery.charge_now, battery.present); - old = status; - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); + if (status == DEVICE_NOTI_ON) { - present = PRESENT_ABNORMAL; - device_notify(DEVICE_NOTIFIER_BATTERY_PRESENT, (void *)&present); + battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_DIM); + device_notify(DEVICE_NOTIFIER_BATTERY_PRESENT, (void *)&battery.present); if (disp_plgn.pm_lock_internal) disp_plgn.pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, 0); } else { - present = PRESENT_NORMAL; - device_notify(DEVICE_NOTIFIER_BATTERY_PRESENT, (void *)&present); + battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); + device_notify(DEVICE_NOTIFIER_BATTERY_PRESENT, (void *)&battery.present); if (disp_plgn.pm_unlock_internal) disp_plgn.pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, PM_SLEEP_MARGIN); } - changed_battery_cf(present); + changed_battery_cf(battery.present); } #ifdef TIZEN_FEATURE_BATTERY_OVER_TEMPERATURE static void update_health(enum battery_noti_status status) { - static int old = DEVICE_NOTI_OFF; - - if (old == status) - return; _I("charge=%d health=%d", battery.charge_now, battery.health); - old = status; - - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); if (status == DEVICE_NOTI_ON) { _I("Popup: Battery health status is not good."); - + battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_DIM); + device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)&battery.health); + if (disp_plgn.pm_unlock_internal) + disp_plgn.pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); if (disp_plgn.pm_lock_internal) disp_plgn.pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, 0); + change_health_popup_timer(status); if (battery.health == HEALTH_LOW) battery_charge_err_low_act(NULL); else if (battery.health == HEALTH_HIGH) battery_charge_err_high_act(NULL); } else { - if (disp_plgn.pm_unlock_internal) + battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); + device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)&battery.health); + if (disp_plgn.pm_unlock_internal) { disp_plgn.pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, PM_SLEEP_MARGIN); + disp_plgn.pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); + } + change_health_popup_timer(status); + health_status_broadcast(); abnormal_popup_timer_init(); launch_system_app(APP_DEFAULT, 2, APP_KEY_TYPE, REMOVE_POPUP); } } -#endif /* TIZEN_FEATURE_BATTERY_OVER_TEMPERATURE */ -static void update_ovp(enum battery_noti_status status) +void update_health_popup_relaunch(void) { - static int old = DEVICE_NOTI_OFF; - int value; + int delta; - if (old == status) + _D("update_health_popup_relaunch()"); + clock_gettime(CLOCK_REALTIME, &health_relaunch_end_st); + delta = health_relaunch_end_st.tv_sec - health_relaunch_start_st.tv_sec; + if (delta <= 0 || delta >= HEALTH_POPUP_RELAUNCH_TIMEOUT) return; - _I("charge=%d ovp=%d", battery.charge_now, battery.health); - old = status; - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); - if (status == DEVICE_NOTI_ON) - value = HEALTH_OVP; - else - value = HEALTH_GOOD; - device_notify(DEVICE_NOTIFIER_BATTERY_OVP, (void *)&value); + + update_health_popup_relaunch_time((HEALTH_POPUP_RELAUNCH_TIMEOUT - delta)); } +#endif /* TIZEN_FEATURE_BATTERY_OVER_TEMPERATURE */ -static void check_battery_status(void) +static void update_ovp(enum battery_noti_status status) { - static int old = DEVICE_CHANGE_NORMAL; - int status; - - if (battery.charge_now == CHARGER_ABNORMAL && - (battery.health == HEALTH_DEAD || battery.present == PRESENT_ABNORMAL)) - status = DEVICE_CHANGE_ABNORMAL; - else if (battery.health == HEALTH_OVP) - status = DEVICE_CHANGE_ABNORMAL; - else - status = DEVICE_CHANGE_NORMAL; + static int old = DEVICE_NOTI_OFF; + if (old == status) return; + old = status; + _I("charge %d ovp %d with lcd %s", battery.charge_now, battery.health, + (status == DEVICE_NOTI_ON) ? "dim" : "normal"); - if (battery.charge_now == CHARGER_ABNORMAL) { - if (battery.health == HEALTH_DEAD) { - device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)&battery.health); -#ifdef TIZEN_FEATURE_BATTERY_OVER_TEMPERATURE - update_health(DEVICE_NOTI_ON); -#endif /* TIZEN_FEATURE_BATTERY_OVER_TEMPERATURE */ - return; - } else if (battery.present == PRESENT_ABNORMAL) { - update_present(DEVICE_NOTI_ON); - return; - } - } - if (battery.health == HEALTH_OVP) { - update_ovp(DEVICE_NOTI_ON); - return; - } + device_notify(DEVICE_NOTIFIER_BATTERY_OVP, (void *)&battery.health); + battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); +} - if (battery.charge_now != CHARGER_ABNORMAL && - status == DEVICE_CHANGE_NORMAL) { - device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)&battery.health); - health_status_broadcast(); +static void check_abnormal_status(void) +{ #ifdef TIZEN_FEATURE_BATTERY_OVER_TEMPERATURE + if (battery.health == HEALTH_LOW || battery.health == HEALTH_HIGH) + update_health_popup_relaunch(); + + if (old_battery.health != HEALTH_LOW && old_battery.health != HEALTH_HIGH && + (battery.health == HEALTH_LOW || battery.health == HEALTH_HIGH)) + update_health(DEVICE_NOTI_ON); + else if ((old_battery.health == HEALTH_LOW || old_battery.health == HEALTH_HIGH) && + battery.health != HEALTH_LOW && battery.health != HEALTH_HIGH) update_health(DEVICE_NOTI_OFF); #endif /* TIZEN_FEATURE_BATTERY_OVER_TEMPERATURE */ - update_ovp(DEVICE_NOTI_OFF); + + if (old_battery.present != PRESENT_ABNORMAL && battery.present == PRESENT_ABNORMAL) + update_present(DEVICE_NOTI_ON); + else if (battery.present != PRESENT_ABNORMAL && old_battery.present == PRESENT_ABNORMAL) update_present(DEVICE_NOTI_OFF); - } + + if (old_battery.health != HEALTH_OVP && battery.health == HEALTH_OVP) + update_ovp(DEVICE_NOTI_ON); + else if (battery.health != HEALTH_OVP && old_battery.health == HEALTH_OVP) + update_ovp(DEVICE_NOTI_OFF); } static void check_online(void) @@ -709,7 +716,11 @@ static void process_power_supply(void *data) old_battery.charge_now = battery.charge_now; old_battery.charge_full = battery.charge_full; - check_battery_status(); + check_abnormal_status(); + + old_battery.health = battery.health; + old_battery.present = battery.present; + snprintf(old_battery.health_s, sizeof(old_battery.health_s), "%s", battery.health_s); device_notify(DEVICE_NOTIFIER_POWER_SUPPLY, NULL); device_notify(DEVICE_NOTIFIER_BATTERY_CHARGING, &battery.charge_now); } @@ -792,6 +803,10 @@ static void battery_changed(struct battery_info *info, void *data) else power_supply_noti(DEVICE_NOTI_BATT_CHARGE, DEVICE_NOTI_OFF); } + if (ret == 0) { + battery.health = HEALTH_GOOD; + battery.present = PRESENT_NORMAL; + } process_power_supply(&battery.capacity); @@ -1070,15 +1085,138 @@ static int booting_done(void *data) return done; } -static int display_changed(void *data) +#ifdef TIZEN_FEATURE_BATTERY_OVER_TEMPERATURE +static gboolean update_health_pm_status(void *data) { - if (battery.charge_now != CHARGER_ABNORMAL) - return 0; - if (battery.health != HEALTH_DEAD && battery.present != PRESENT_ABNORMAL) - return 0; + battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_OFF); + if (disp_plgn.pm_unlock_internal) { + disp_plgn.pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, PM_SLEEP_MARGIN); + disp_plgn.pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); + } + + return G_SOURCE_REMOVE; +} +static void change_health_popup_timer(enum battery_noti_status status) +{ + if (status == DEVICE_NOTI_ON) { + health_popup_timer = g_timeout_add_seconds(HEALTH_POPUP_TERMINATE_TIMEOUT, update_health_pm_status, NULL); + if (health_popup_timer == 0) + _E("fail to add battery init timer during booting"); + else + _I("turn off after %d sec by abnormal health condition", HEALTH_POPUP_TERMINATE_TIMEOUT); + return; + } + health_popup_timer_init(__func__); +} + +static void launch_health_popup(void) +{ + _I("popup - Health is not good(health %s)", (battery.health == HEALTH_HIGH) ? "TempHigh" : "TempLow"); + health_popup_timer_init(__func__); + device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)&battery.health); + battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); + battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_DIM); + if (disp_plgn.pm_unlock_internal) + disp_plgn.pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, 0); + disp_plgn.pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, LCD_DIM_TIME_IN_BATTERY_HEALTH); + change_health_popup_timer(DEVICE_NOTI_ON); + if (battery.health == HEALTH_LOW) + battery_charge_err_low_act(NULL); + else if (battery.health == HEALTH_HIGH) + battery_charge_err_high_act(NULL); +} +#endif /* TIZEN_FEATURE_BATTERY_OVER_TEMPERATURE */ + +bool battery_do_not_disturb(void) +{ + int block = 0; + int r; + + if (display_changed(NULL) == S_LCDOFF) { + r = vconf_get_bool(VCONFKEY_SETAPPL_BLOCKMODE_WEARABLE_BOOL, &block); + if (r < 0) + _E("Failed to set vconf value for charger status: %d", vconf_get_ext_errno()); + } + + if (block != 0) { + _I("Skip lcd and popup(block %d)", block); + return true; + } + + return false; +} + +static int battery_pm_change_internal(int pid, int s_bits) +{ + if (battery_do_not_disturb()) + return 0; + + if (disp_plgn.pm_change_internal) + disp_plgn.pm_change_internal(pid, s_bits); + + return 0; +} + +#ifdef TIZEN_FEATURE_BATTERY_OVER_TEMPERATURE +static gboolean change_health_pm_normal(void *data) +{ + battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); + return G_SOURCE_REMOVE; +} + +static void update_health_popup_relaunch_time(int timeout) +{ + if (timeout <= 0) + return; + + health_popup_timer_init(__func__); + health_popup_timer = g_timeout_add(timeout, change_health_pm_normal, NULL); + if (health_popup_timer == 0) + _E("Failed to add battery init timer during booting."); + else + _D("Relaunch timeout with %d sec", timeout); +} + +static void health_popup_timer_init(const char *func) +{ + if (health_popup_timer == 0) + return; + + g_source_remove(health_popup_timer); + health_popup_timer = 0; + _D("init by %s", func); +} +#endif /* TIZEN_FEATURE_BATTERY_OVER_TEMPERATURE */ + +static int display_changed(void *data) +{ + static enum state_t old; + static enum state_t state; + + if (!data) + return state; + + state = *(int *)data; + +#ifdef TIZEN_FEATURE_BATTERY_OVER_TEMPERATURE + if (battery.health != HEALTH_LOW && battery.health != HEALTH_HIGH) + goto out; + + if (old != S_LCDOFF || state != S_LCDON) { + if (state == S_LCDOFF) { + health_popup_timer_init(__func__); + clock_gettime(CLOCK_REALTIME, &health_relaunch_start_st); + update_health_popup_relaunch_time(HEALTH_POPUP_RELAUNCH_TIMEOUT); + } + goto out; + } + launch_health_popup(); +#endif /* TIZEN_FEATURE_BATTERY_OVER_TEMPERATURE */ + +out: + old = state; return 0; } -- 2.7.4 From 7d7dd28dca001d30018e4c39871fd8505534b2cd Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Mon, 29 Jul 2019 18:09:06 +0900 Subject: [PATCH 13/16] Change log level for failed AOD mode to avoid confusion Change-Id: I3647f7db0a07c3d29219ecef7f9d1a5899dde5cd Signed-off-by: lokilee73 --- src/display/ambient-mode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index 9254100..fdec29b 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -138,7 +138,7 @@ void ambient_check_invalid_state(pid_t pid) if (ambient_get_state() == false) return; - _E("Invalid state. Ambient state is change to off."); + _I("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, -- 2.7.4 From 5ea7e1f6b1d76522c9beb34065512e17b25e068a Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 30 Jul 2019 16:17:48 +0900 Subject: [PATCH 14/16] Remove power off popup from power off type Change-Id: I16ed1f64ba7a26340975796071f1736bd6470ba9 Signed-off-by: lokilee73 --- plugins/iot/display/core.c | 1 - plugins/iot/display/key-filter.c | 19 +++++++++++-------- plugins/mobile/display/core.c | 1 - plugins/mobile/display/key-filter.c | 19 +++++++++++-------- plugins/tv/display/core.c | 1 - plugins/tv/display/key-filter.c | 19 +++++++++++-------- plugins/wearable/display/core.c | 1 - plugins/wearable/display/key-filter.c | 19 +++++++++++-------- src/power/power-handler.c | 13 ------------- src/power/power-handler.h | 1 - 10 files changed, 44 insertions(+), 50 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 42ef795..b9d7d14 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -1849,7 +1849,6 @@ static int update_setting(int key_idx, int val) case SETTING_POWEROFF: switch (val) { case POWEROFF_TYPE_NONE: - case POWEROFF_TYPE_POPUP: pm_status_flag &= ~PWROFF_FLAG; break; case POWEROFF_TYPE_DIRECT: diff --git a/plugins/iot/display/key-filter.c b/plugins/iot/display/key-filter.c index 6ef373c..0baf72a 100644 --- a/plugins/iot/display/key-filter.c +++ b/plugins/iot/display/key-filter.c @@ -38,6 +38,7 @@ #include "core/device-notifier.h" #include "power/power-handler.h" #include "led/touch-key.h" +#include "apps/apps.h" #include #ifndef KEY_SCREENLOCK @@ -49,7 +50,6 @@ #define PREDEF_LEAVESLEEP "leavesleep" #define POWEROFF_ACT "poweroff" -#define PWROFF_POPUP_ACT "pwroff-popup" #define USEC_PER_SEC 1000000 #define CAPTURE_COMBINATION_INTERVAL 0.5 /* 0.5 second */ @@ -118,18 +118,22 @@ static inline void restore_custom_brightness(void) backlight_ops.custom_update(); } -static int power_execute(void *data) +static void pwroff_popup(void) { - static const struct device_ops *ops = NULL; + int ret; - FIND_DEVICE_INT(ops, POWER_OPS_NAME); + ret = vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, VCONFKEY_SYSMAN_POWER_OFF_POPUP); + if (ret < 0) + _E("Failed to set vconf value for power off status: %d", vconf_get_ext_errno()); - return ops->execute(data); + pm_status_flag &= ~PWROFF_FLAG; + ret = launch_system_app(APP_POWERKEY, 2, APP_KEY_TYPE, APP_POWERKEY); + if (ret < 0) + _E("Failed to launch power off popup."); } static void longkey_pressed() { - char *opt; unsigned int caps; _I("Power key long pressed!"); @@ -149,8 +153,7 @@ static void longkey_pressed() return; } - opt = POWEROFF_ACT; - power_execute(opt); + pwroff_popup(); } static gboolean longkey_pressed_cb(void *data) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index d38d9ac..f252e4e 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -1850,7 +1850,6 @@ static int update_setting(int key_idx, int val) case SETTING_POWEROFF: switch (val) { case POWEROFF_TYPE_NONE: - case POWEROFF_TYPE_POPUP: pm_status_flag &= ~PWROFF_FLAG; break; case POWEROFF_TYPE_DIRECT: diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index 6789e71..7f060d0 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -38,6 +38,7 @@ #include "core/device-notifier.h" #include "power/power-handler.h" #include "led/touch-key.h" +#include "apps/apps.h" #include #ifndef KEY_SCREENLOCK @@ -49,7 +50,6 @@ #define PREDEF_LEAVESLEEP "leavesleep" #define POWEROFF_ACT "poweroff" -#define PWROFF_POPUP_ACT "pwroff-popup" #define USEC_PER_SEC 1000000 #define CAPTURE_COMBINATION_INTERVAL 0.5 /* 0.5 second */ @@ -118,18 +118,22 @@ static inline void restore_custom_brightness(void) backlight_ops.custom_update(); } -static int power_execute(void *data) +static void pwroff_popup(void) { - static const struct device_ops *ops = NULL; + int ret; - FIND_DEVICE_INT(ops, POWER_OPS_NAME); + ret = vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, VCONFKEY_SYSMAN_POWER_OFF_POPUP); + if (ret < 0) + _E("Failed to set vconf value for power off status: %d", vconf_get_ext_errno()); - return ops->execute(data); + pm_status_flag &= ~PWROFF_FLAG; + ret = launch_system_app(APP_POWERKEY, 2, APP_KEY_TYPE, APP_POWERKEY); + if (ret < 0) + _E("Failed to launch power off popup."); } static void longkey_pressed() { - char *opt; unsigned int caps; _I("Power key long pressed!"); @@ -149,8 +153,7 @@ static void longkey_pressed() return; } - opt = PWROFF_POPUP_ACT; - power_execute(opt); + pwroff_popup(); } static gboolean longkey_pressed_cb(void *data) diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 7529349..5f07dde 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -1851,7 +1851,6 @@ static int update_setting(int key_idx, int val) case SETTING_POWEROFF: switch (val) { case POWEROFF_TYPE_NONE: - case POWEROFF_TYPE_POPUP: pm_status_flag &= ~PWROFF_FLAG; break; case POWEROFF_TYPE_DIRECT: diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index 6ef373c..0baf72a 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -38,6 +38,7 @@ #include "core/device-notifier.h" #include "power/power-handler.h" #include "led/touch-key.h" +#include "apps/apps.h" #include #ifndef KEY_SCREENLOCK @@ -49,7 +50,6 @@ #define PREDEF_LEAVESLEEP "leavesleep" #define POWEROFF_ACT "poweroff" -#define PWROFF_POPUP_ACT "pwroff-popup" #define USEC_PER_SEC 1000000 #define CAPTURE_COMBINATION_INTERVAL 0.5 /* 0.5 second */ @@ -118,18 +118,22 @@ static inline void restore_custom_brightness(void) backlight_ops.custom_update(); } -static int power_execute(void *data) +static void pwroff_popup(void) { - static const struct device_ops *ops = NULL; + int ret; - FIND_DEVICE_INT(ops, POWER_OPS_NAME); + ret = vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, VCONFKEY_SYSMAN_POWER_OFF_POPUP); + if (ret < 0) + _E("Failed to set vconf value for power off status: %d", vconf_get_ext_errno()); - return ops->execute(data); + pm_status_flag &= ~PWROFF_FLAG; + ret = launch_system_app(APP_POWERKEY, 2, APP_KEY_TYPE, APP_POWERKEY); + if (ret < 0) + _E("Failed to launch power off popup."); } static void longkey_pressed() { - char *opt; unsigned int caps; _I("Power key long pressed!"); @@ -149,8 +153,7 @@ static void longkey_pressed() return; } - opt = POWEROFF_ACT; - power_execute(opt); + pwroff_popup(); } static gboolean longkey_pressed_cb(void *data) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index bf6ff62..d5e35f9 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -1850,7 +1850,6 @@ static int update_setting(int key_idx, int val) case SETTING_POWEROFF: switch (val) { case POWEROFF_TYPE_NONE: - case POWEROFF_TYPE_POPUP: pm_status_flag &= ~PWROFF_FLAG; break; case POWEROFF_TYPE_DIRECT: diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index a6cb3fc..d66fa9d 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -38,6 +38,7 @@ #include "core/device-notifier.h" #include "power/power-handler.h" #include "led/touch-key.h" +#include "apps/apps.h" #include #ifndef KEY_SCREENLOCK @@ -49,7 +50,6 @@ #define PREDEF_LEAVESLEEP "leavesleep" #define POWEROFF_ACT "poweroff" -#define PWROFF_POPUP_ACT "pwroff-popup" #define USEC_PER_SEC 1000000 #define CAPTURE_COMBINATION_INTERVAL 0.5 /* 0.5 second */ @@ -129,18 +129,22 @@ static inline void restore_custom_brightness(void) backlight_ops.custom_update(); } -static int power_execute(void *data) +static void pwroff_popup(void) { - static const struct device_ops *ops = NULL; + int ret; - FIND_DEVICE_INT(ops, POWER_OPS_NAME); + ret = vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, VCONFKEY_SYSMAN_POWER_OFF_POPUP); + if (ret < 0) + _E("Failed to set vconf value for power off status: %d", vconf_get_ext_errno()); - return ops->execute(data); + pm_status_flag &= ~PWROFF_FLAG; + ret = launch_system_app(APP_POWERKEY, 2, APP_KEY_TYPE, APP_POWERKEY); + if (ret < 0) + _E("Failed to launch power off popup."); } static void longkey_pressed() { - char *opt; unsigned int caps; _I("Power key long pressed!"); @@ -160,8 +164,7 @@ static void longkey_pressed() return; } - opt = PWROFF_POPUP_ACT; - power_execute(opt); + pwroff_popup(); } static gboolean longkey_restore_cb(void *data) diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 222eeeb..41aac63 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -77,7 +77,6 @@ static const char *poweroff_type_flagpaths[] = { // index denotes type static const char *poweroff_type_names[] = { // index denotes type [POWEROFF_TYPE_POWEROFF] = POWER_POWEROFF, - [POWEROFF_TYPE_POPUP] = POWER_OFF_POPUP, [POWEROFF_TYPE_REBOOT] = POWER_REBOOT, [POWEROFF_TYPE_EXIT] = POWER_EXIT, }; @@ -414,11 +413,6 @@ static void system_shutdown_send_system_event(void) bundle_free(b); } -static int pwroff_popup(void) -{ - return launch_system_app(APP_POWERKEY, 2, APP_KEY_TYPE, APP_POWERKEY); -} - static int poweroff_option_valid(enum poweroff_type type_e, const char *option) { dd_list *l; @@ -493,12 +487,6 @@ static int power_execute_pid(const char *typename, const char *option) if (ret < 0) _E("Failed to set vconf value for power off status: %d", vconf_get_ext_errno()); - if (poweroff_opt.type == POWEROFF_TYPE_POPUP) { - _D("Request popup."); - pwroff_popup(); - return 0; - } - during_poweroff = true; /* Poweroff event broadcasting */ @@ -756,7 +744,6 @@ static void power_init(void *data) add_poweroff_option(POWEROFF_TYPE_POWEROFF, NULL); add_poweroff_option(POWEROFF_TYPE_RESTART, NULL); - add_poweroff_option(POWEROFF_TYPE_POPUP, NULL); add_poweroff_option(POWEROFF_TYPE_EXIT, NULL); ret = config_parse(POWER_CONF_FILE, load_config, NULL); diff --git a/src/power/power-handler.h b/src/power/power-handler.h index 5ef317d..608a9a2 100644 --- a/src/power/power-handler.h +++ b/src/power/power-handler.h @@ -33,7 +33,6 @@ enum poweroff_type { POWEROFF_TYPE_INVALID = 0, POWEROFF_TYPE_NONE = POWEROFF_TYPE_INVALID, // compat only - POWEROFF_TYPE_POPUP, POWEROFF_TYPE_POWEROFF, /* replaces POWEROFF_TYPE_DIRECT */ POWEROFF_TYPE_DIRECT = POWEROFF_TYPE_POWEROFF, // compat only POWEROFF_TYPE_REBOOT, -- 2.7.4 From 09e4e1757d17cce60540d0056bb5739b3af63152 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 30 Jul 2019 10:18:37 +0900 Subject: [PATCH 15/16] Add a board info module Change-Id: I89309dec1f198a5fbac3e4fbbbee484bcb6f5bf2 Signed-off-by: Youngjae Cho Signed-off-by: lokilee73 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 5 ++ packaging/deviced.spec | 1 + src/board/board-info.c | 173 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 179 insertions(+) create mode 100644 src/board/board-info.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 33ca1c4..b28ba3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,6 +155,11 @@ IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on) DESTINATION /etc/deviced/usb-host-test/) ENDIF() +IF(DEVICE_BOARD_MODULE STREQUAL on) + ADD_SOURCE(src/board PRODUCT_BOARD_SRCS) + SET(SRCS ${SRCS} ${PRODUCT_BOARD_SRCS}) +ENDIF() + INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/deviced) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index fd8a375..e2da603 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -163,6 +163,7 @@ Plugin libraries for IoT devices -DTIZEN_FEATURE_BATTERY_OVER_TEMPERATURE=on \ -DTOUCH_SENSITIVITY_MODULE=on \ -DDUMP_MODULE=on \ + -DDEVICE_BOARD_MODULE=on \ #eol %build diff --git a/src/board/board-info.c b/src/board/board-info.c new file mode 100644 index 0000000..2af9fd9 --- /dev/null +++ b/src/board/board-info.c @@ -0,0 +1,173 @@ +/* + * deviced + * + * Copyright (c) 2019 - 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 "core/log.h" +#include "core/common.h" +#include "core/devices.h" +#include "core/config-parser.h" + +struct board_info { + char *serial; + char *num; + int revision; +}; + +static struct board_info info; +static struct hw_board *board_dev; + +static GVariant *dbus_revision_handler(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + int ret; + if (!board_dev->get_device_revision) { + _E("GetHWRev not supported."); + ret = -ENOTSUP; + goto revision_fail; + } + ret = board_dev->get_device_revision(&info.revision); + if (ret < 0) { + _E("Fail to get revision."); + goto revision_fail; + } + _D("Revision: %d", info.revision); + return g_variant_new("(i)", info.revision); + +revision_fail: + return g_variant_new("(i)", ret); +} + +static GVariant *dbus_serial_handler(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + int ret; + if (!board_dev->get_device_serial) { + _E("GetSerial not supported."); + ret = -ENOTSUP; + goto serial_out; + } + ret = board_dev->get_device_serial(&info.serial); + if (ret < 0) { + _E("Failed to get serial."); + goto serial_out; + } + _D("Serial(%s) len(%d).", info.serial, strlen(info.serial)); + +serial_out: + return g_variant_new("(si)", info.serial, ret); +} + +static GVariant *dbus_num_handler(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + int ret; + char *p; + if (!board_dev->get_device_serial) { + _E("GetNum not supported."); + ret = -ENOTSUP; + goto num_out; + } + ret = board_dev->get_device_serial(&info.num); + if (ret < 0) { + _E("Failed to get num."); + goto num_out; + } + + p = strchr(info.num, ','); + if (p) { + ++p; + strcpy(info.num, p); + } + _D("Num(%s) len(%d).", info.num, strlen(info.num)); + +num_out: + return g_variant_new("(si)", info.num, ret); +} + +static const dbus_method_s dbus_methods[] = { + { "GetSerial", NULL, "si", dbus_serial_handler }, + { "GetHWRev", NULL, "i", dbus_revision_handler }, + { "GetNum", NULL, "si", dbus_num_handler}, +}; + +static const dbus_interface_u dbus_interface = { + .oh = NULL, + .name = DEVICED_INTERFACE_BOARD, + .methods = dbus_methods, + .nr_methods = ARRAY_SIZE(dbus_methods), +}; + +static int board_probe(void *data) +{ + struct hw_info *info; + int ret; + + if (board_dev) + return 0; + + ret = hw_get_info(BOARD_HARDWARE_DEVICE_ID, + (const struct hw_info**)&info); + if (ret < 0) { + _E("Failed to load board shared library: %d", ret); + return -ENODEV; + } + + if (!info->open) { + _E("Failed to open board device: open(NULL)"); + return -ENODEV; + } + + ret = info->open(info, NULL, (struct hw_common**)&board_dev); + if (ret < 0) { + _E("Failed to get board device structure: %d", ret); + return -ENODEV; + } + + _I("Board device structure load success."); + return 0; +} + +static void board_init(void *data) +{ + int ret; + + ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_BOARD, &dbus_interface); + if (ret < 0) + _E("Failed to init dbus method: %d", ret); + ret = board_dev->get_device_serial(&info.serial); + if (ret < 0) + _E("Failed to get serial info: %d", ret); +} + +static const struct device_ops board_device_ops = { + .name = "board", + .probe = board_probe, + .init = board_init, +}; + +DEVICE_OPS_REGISTER(&board_device_ops) -- 2.7.4 From 4dba2d36d847d3736accf912ae302e91007c6fbf Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 1 Aug 2019 16:52:55 +0900 Subject: [PATCH 16/16] Add exception handle, fix log format specifier Change-Id: I0f3f230501ba46c345dcd20d2b737fbb5722dfa1 Signed-off-by: Youngjae Cho --- src/board/board-info.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/board/board-info.c b/src/board/board-info.c index 2af9fd9..6f72ca8 100644 --- a/src/board/board-info.c +++ b/src/board/board-info.c @@ -43,7 +43,7 @@ static GVariant *dbus_revision_handler(GDBusConnection *conn, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) { int ret; - if (!board_dev->get_device_revision) { + if (!board_dev || !board_dev->get_device_revision) { _E("GetHWRev not supported."); ret = -ENOTSUP; goto revision_fail; @@ -65,7 +65,7 @@ static GVariant *dbus_serial_handler(GDBusConnection *conn, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) { int ret; - if (!board_dev->get_device_serial) { + if (!board_dev || !board_dev->get_device_serial) { _E("GetSerial not supported."); ret = -ENOTSUP; goto serial_out; @@ -75,7 +75,7 @@ static GVariant *dbus_serial_handler(GDBusConnection *conn, _E("Failed to get serial."); goto serial_out; } - _D("Serial(%s) len(%d).", info.serial, strlen(info.serial)); + _D("Serial(%s) len(%zu).", info.serial, strlen(info.serial)); serial_out: return g_variant_new("(si)", info.serial, ret); @@ -87,7 +87,7 @@ static GVariant *dbus_num_handler(GDBusConnection *conn, { int ret; char *p; - if (!board_dev->get_device_serial) { + if (!board_dev || !board_dev->get_device_serial) { _E("GetNum not supported."); ret = -ENOTSUP; goto num_out; @@ -103,7 +103,7 @@ static GVariant *dbus_num_handler(GDBusConnection *conn, ++p; strcpy(info.num, p); } - _D("Num(%s) len(%d).", info.num, strlen(info.num)); + _D("Num(%s) len(%zu).", info.num, strlen(info.num)); num_out: return g_variant_new("(si)", info.num, ret); @@ -159,9 +159,6 @@ static void board_init(void *data) ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_BOARD, &dbus_interface); if (ret < 0) _E("Failed to init dbus method: %d", ret); - ret = board_dev->get_device_serial(&info.serial); - if (ret < 0) - _E("Failed to get serial info: %d", ret); } static const struct device_ops board_device_ops = { -- 2.7.4