From d4023b019395e803237d345ee1eac3855ab6c936 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Fri, 28 Apr 2023 15:02:46 +0900 Subject: [PATCH] display: Relocate low_battery_state() to reduce plugin duplication Remove and redefine low_battery_state function in plugins/display/core.c This function is added to below display-misc. bool display_misc_is_low_battery_state(int val) -> This function checks that val parameter is low battery status or not. Actually, this function should be located under the battery module. During refactoring, this function will be relocated. Change-Id: I2c5d1ddb5df7bba56c4ac88ddcb92b8d0e3a9335 Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 18 ++++------------- plugins/mobile/display/core.c | 18 ++++------------- plugins/tv/display/core.c | 18 ++++------------- plugins/wearable/display/core.c | 18 ++++------------- src/display/display-misc.c | 34 ++++++++++++++++++++++++++++++++ src/display/display-misc.h | 31 +++++++++++++++++++++++++++++ src/display/plugin-common/core.h | 1 - src/display/plugin-common/display-dbus.c | 3 ++- 8 files changed, 83 insertions(+), 58 deletions(-) create mode 100644 src/display/display-misc.c create mode 100644 src/display/display-misc.h diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 2dfd3d0..5fef73b 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -66,6 +66,7 @@ #include "display-signal.h" #include "display-lock.h" #include "display-backlight.h" +#include "display-misc.h" #include "display-panel.h" #include "display-config.h" #include "shared/plugin.h" @@ -376,17 +377,6 @@ void set_lcd_paneloff_mode(int val) disp_plgn->pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } -int low_battery_state(int val) -{ - switch (val) { - case VCONFKEY_SYSMAN_BAT_POWER_OFF: - case VCONFKEY_SYSMAN_BAT_CRITICAL_LOW: - case VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF: - return true; - } - return false; -} - void get_pname(pid_t pid, char *pname) { char buf[PATH_MAX]; @@ -1511,7 +1501,7 @@ static int update_setting(int key_idx, int val) states[get_pm_cur_state()].trans(EVENT_INPUT); break; case SETTING_LOW_BATT: - if (low_battery_state(val)) { + if (display_misc_is_low_battery_state(val)) { if (!(get_pm_status_flag() & CHRGR_FLAG)) power_saving_func(true); set_pm_status_flag(LOWBT_FLAG); @@ -1540,7 +1530,7 @@ static int update_setting(int key_idx, int val) bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); } - if (low_battery_state(bat_state)) { + if (display_misc_is_low_battery_state(bat_state)) { power_saving_func(true); set_pm_status_flag(LOWBT_FLAG); } @@ -1627,7 +1617,7 @@ static void check_seed_status(void) bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); } - if (low_battery_state(bat_state)) { + if (display_misc_is_low_battery_state(bat_state)) { if (!(get_pm_status_flag() & CHRGR_FLAG)) { power_saving_func(true); set_pm_status_flag(LOWBT_FLAG); diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 1858eb0..2762b3b 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -67,6 +67,7 @@ #include "display-signal.h" #include "display-lock.h" #include "display-backlight.h" +#include "display-misc.h" #include "display-panel.h" #include "display-config.h" #include "shared/plugin.h" @@ -383,17 +384,6 @@ void set_lcd_paneloff_mode(int val) disp_plgn->pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } -int low_battery_state(int val) -{ - switch (val) { - case VCONFKEY_SYSMAN_BAT_POWER_OFF: - case VCONFKEY_SYSMAN_BAT_CRITICAL_LOW: - case VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF: - return true; - } - return false; -} - void get_pname(pid_t pid, char *pname) { char buf[PATH_MAX]; @@ -1521,7 +1511,7 @@ static int update_setting(int key_idx, int val) states[get_pm_cur_state()].trans(EVENT_INPUT); break; case SETTING_LOW_BATT: - if (low_battery_state(val)) { + if (display_misc_is_low_battery_state(val)) { if (!(get_pm_status_flag() & CHRGR_FLAG)) power_saving_func(true); set_pm_status_flag(LOWBT_FLAG); @@ -1550,7 +1540,7 @@ static int update_setting(int key_idx, int val) bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); } - if (low_battery_state(bat_state)) { + if (display_misc_is_low_battery_state(bat_state)) { power_saving_func(true); set_pm_status_flag(LOWBT_FLAG); } @@ -1637,7 +1627,7 @@ static void check_seed_status(void) bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); } - if (low_battery_state(bat_state)) { + if (display_misc_is_low_battery_state(bat_state)) { if (!(get_pm_status_flag() & CHRGR_FLAG)) { power_saving_func(true); set_pm_status_flag(LOWBT_FLAG); diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 72f8f91..bb65640 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -65,6 +65,7 @@ #include "display-signal.h" #include "display-lock.h" #include "display-backlight.h" +#include "display-misc.h" #include "display-panel.h" #include "display-config.h" #include "shared/plugin.h" @@ -376,17 +377,6 @@ void set_lcd_paneloff_mode(int val) disp_plgn->pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } -int low_battery_state(int val) -{ - switch (val) { - case VCONFKEY_SYSMAN_BAT_POWER_OFF: - case VCONFKEY_SYSMAN_BAT_CRITICAL_LOW: - case VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF: - return true; - } - return false; -} - void get_pname(pid_t pid, char *pname) { char buf[PATH_MAX]; @@ -1511,7 +1501,7 @@ static int update_setting(int key_idx, int val) states[get_pm_cur_state()].trans(EVENT_INPUT); break; case SETTING_LOW_BATT: - if (low_battery_state(val)) { + if (display_misc_is_low_battery_state(val)) { if (!(get_pm_status_flag() & CHRGR_FLAG)) power_saving_func(true); set_pm_status_flag(LOWBT_FLAG); @@ -1540,7 +1530,7 @@ static int update_setting(int key_idx, int val) bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); } - if (low_battery_state(bat_state)) { + if (display_misc_is_low_battery_state(bat_state)) { power_saving_func(true); set_pm_status_flag(LOWBT_FLAG); } @@ -1627,7 +1617,7 @@ static void check_seed_status(void) bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); } - if (low_battery_state(bat_state)) { + if (display_misc_is_low_battery_state(bat_state)) { if (!(get_pm_status_flag() & CHRGR_FLAG)) { power_saving_func(true); set_pm_status_flag(LOWBT_FLAG); diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 01ce1dd..f0e71dd 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -68,6 +68,7 @@ #include "display-signal.h" #include "display-lock.h" #include "display-backlight.h" +#include "display-misc.h" #include "display-panel.h" #include "display-config.h" #include "shared/plugin.h" @@ -653,17 +654,6 @@ void set_lcd_paneloff_mode(int val) disp_plgn->pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } -int low_battery_state(int val) -{ - switch (val) { - case VCONFKEY_SYSMAN_BAT_POWER_OFF: - case VCONFKEY_SYSMAN_BAT_CRITICAL_LOW: - case VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF: - return true; - } - return false; -} - void get_pname(pid_t pid, char *pname) { char buf[PATH_MAX]; @@ -1841,7 +1831,7 @@ static int update_setting(int key_idx, int val) states[get_pm_cur_state()].trans(EVENT_INPUT); break; case SETTING_LOW_BATT: - if (low_battery_state(val)) { + if (display_misc_is_low_battery_state(val)) { if (!(get_pm_status_flag() & CHRGR_FLAG)) power_saving_func(true); set_pm_status_flag(LOWBT_FLAG); @@ -1870,7 +1860,7 @@ static int update_setting(int key_idx, int val) bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); } - if (low_battery_state(bat_state)) { + if (display_misc_is_low_battery_state(bat_state)) { power_saving_func(true); set_pm_status_flag(LOWBT_FLAG); } @@ -1953,7 +1943,7 @@ static void check_seed_status(void) bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); } - if (low_battery_state(bat_state)) { + if (display_misc_is_low_battery_state(bat_state)) { if (!(get_pm_status_flag() & CHRGR_FLAG)) { power_saving_func(true); set_pm_status_flag(LOWBT_FLAG); diff --git a/src/display/display-misc.c b/src/display/display-misc.c new file mode 100644 index 0000000..eac18f0 --- /dev/null +++ b/src/display/display-misc.c @@ -0,0 +1,34 @@ +/* + * deviced + * + * Copyright (c) 2023 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 "display-misc.h" + +/* FIXME: This fucntion should be relocated under the battery module */ +bool display_misc_is_low_battery_state(int val) +{ + switch (val) { + case VCONFKEY_SYSMAN_BAT_CRITICAL_LOW: + case VCONFKEY_SYSMAN_BAT_POWER_OFF: + case VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF: + return true; + } + + return false; +} diff --git a/src/display/display-misc.h b/src/display/display-misc.h new file mode 100644 index 0000000..aabb477 --- /dev/null +++ b/src/display/display-misc.h @@ -0,0 +1,31 @@ +/* + * deviced + * + * Copyright (c) 2023 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-misc.h + * @brief This is temporary header to devide plugin and core display module. + * After refactoring, this file will be removed. + */ +#ifndef __DISPLAY_MISC_H__ +#define __DISPLAY_MISC_H__ + +#include + +bool display_misc_is_low_battery_state(int val); + +#endif /* __DISPLAY_MISC_H__ */ \ No newline at end of file diff --git a/src/display/plugin-common/core.h b/src/display/plugin-common/core.h index c112da5..a2a17c7 100644 --- a/src/display/plugin-common/core.h +++ b/src/display/plugin-common/core.h @@ -138,7 +138,6 @@ int custom_lcdoff(enum device_flags flag); int display_on_by_reason(const char *reason, int timeout); int display_off_by_reason(const char *reason); void update_lcdoff_source(int source); -int low_battery_state(int val); int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name); void save_display_log(const char *path); int custom_lcdon(int timeout); diff --git a/src/display/plugin-common/display-dbus.c b/src/display/plugin-common/display-dbus.c index 3e198ef..bdf0f1b 100644 --- a/src/display/plugin-common/display-dbus.c +++ b/src/display/plugin-common/display-dbus.c @@ -48,6 +48,7 @@ #include "display-config.h" //#include "display/display.h" #include "display-backlight.h" +#include "display-misc.h" #define AUL_APPSTATUS_PATH "/Org/Tizen/Aul/AppStatus" #define AUL_APPSTATUS_INTERFACE "org.tizen.aul.AppStatus" @@ -617,7 +618,7 @@ static GVariant *dbus_releasebrightness(GDBusConnection *conn, brt = ret; // check dim state - if (!disp_plgn->auto_brightness_control && low_battery_state(bat) && + if (!disp_plgn->auto_brightness_control && display_misc_is_low_battery_state(bat) && charger == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED && !changed) { _D("batt warning low : brightness is not changed!"); if (brt != 0) -- 2.7.4