display: Relocate low_battery_state() to reduce plugin duplication 64/292464/10
authorYunhee Seo <yuni.seo@samsung.com>
Fri, 28 Apr 2023 06:02:46 +0000 (15:02 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Thu, 25 May 2023 01:54:07 +0000 (10:54 +0900)
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 <yuni.seo@samsung.com>
plugins/iot-headed/display/core.c
plugins/mobile/display/core.c
plugins/tv/display/core.c
plugins/wearable/display/core.c
src/display/display-misc.c [new file with mode: 0644]
src/display/display-misc.h [new file with mode: 0644]
src/display/plugin-common/core.h
src/display/plugin-common/display-dbus.c

index 2dfd3d0..5fef73b 100644 (file)
@@ -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);
index 1858eb0..2762b3b 100644 (file)
@@ -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);
index 72f8f91..bb65640 100644 (file)
@@ -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);
index 01ce1dd..f0e71dd 100644 (file)
@@ -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 (file)
index 0000000..eac18f0
--- /dev/null
@@ -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 <vconf-keys.h>
+
+#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 (file)
index 0000000..aabb477
--- /dev/null
@@ -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 <stdbool.h>
+
+bool display_misc_is_low_battery_state(int val);
+
+#endif /* __DISPLAY_MISC_H__ */
\ No newline at end of file
index c112da5..a2a17c7 100644 (file)
@@ -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);
index 3e198ef..bdf0f1b 100644 (file)
@@ -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)