display: misc: Relocate battery_health_changed() to reduce plugin duplication 68/292468/11
authorYunhee Seo <yuni.seo@samsung.com>
Thu, 4 May 2023 05:36:50 +0000 (14:36 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Thu, 25 May 2023 01:54:07 +0000 (10:54 +0900)
Remove and redefine battery_health_changed() in plugins/display/core.c
-> This function sets battery/dimstay flag and it is called from battery module.

This function is added to below display-misc.
void display_misc_register_battery_health_notifier(void)
void display_misc_unregister_battery_health_notifier(void)
-> register/unregister notifier is added for above notifier callback.

During display plugins refactoriung, this function will be relocated.

Change-Id: Ib48187458ebfdf0e279c5ea373f401260eb1e597
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
src/display/display-misc.h
src/display/display.c

index a1e9a29..a493e31 100644 (file)
@@ -1732,26 +1732,6 @@ static int delayed_init_done(void *data)
        return done;
 }
 
-static int battery_health_changed(void *data)
-{
-       int health = DATA_VALUE_INT(data);
-
-       _I("battery health change %d", health);
-
-       if (health == HEALTH_GOOD) {
-               clear_pm_status_flag(BATTERY_FLAG);
-               clear_pm_status_flag(DIMSTAY_FLAG);
-       } else if (health == HEALTH_LOW || health == HEALTH_HIGH || health == HEALTH_OVP) {
-               set_pm_status_flag(BATTERY_FLAG);
-               set_pm_status_flag(DIMSTAY_FLAG);
-       }
-
-       if (display_panel_get_dpms_cached_state() == DPMS_ON)
-               display_backlight_update_by_default_brightness();
-
-       return 0;
-}
-
 static gboolean delayed_dpms_init_done(gpointer data)
 {
        int timeout;
@@ -1930,7 +1910,6 @@ static void display_init(void *data)
        register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background);
        register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground);
        register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated);
-       register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
        register_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback);
        register_notifier(DEVICE_NOTIFIER_POWEROFF_TRIGGERED, poweroff_triggered_callback);
 
@@ -2072,7 +2051,6 @@ static void display_exit(void *data)
                        unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background);
                        unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground);
                        unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated);
-                       unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
                        unregister_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback);
 
                        break;
index 9a1f709..e156705 100644 (file)
@@ -1742,26 +1742,6 @@ static int delayed_init_done(void *data)
        return done;
 }
 
-static int battery_health_changed(void *data)
-{
-       int health = DATA_VALUE_INT(data);
-
-       _I("battery health change %d", health);
-
-       if (health == HEALTH_GOOD) {
-               clear_pm_status_flag(BATTERY_FLAG);
-               clear_pm_status_flag(DIMSTAY_FLAG);
-       } else if (health == HEALTH_LOW || health == HEALTH_HIGH || health == HEALTH_OVP) {
-               set_pm_status_flag(BATTERY_FLAG);
-               set_pm_status_flag(DIMSTAY_FLAG);
-       }
-
-       if (display_panel_get_dpms_cached_state() == DPMS_ON)
-               display_backlight_update_by_default_brightness();
-
-       return 0;
-}
-
 static gboolean delayed_dpms_init_done(gpointer data)
 {
        int timeout;
@@ -1936,7 +1916,6 @@ static void display_init(void *data)
        register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background);
        register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground);
        register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated);
-       register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
        register_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback);
        register_notifier(DEVICE_NOTIFIER_POWEROFF_TRIGGERED, poweroff_triggered_callback);
 
@@ -2078,7 +2057,6 @@ static void display_exit(void *data)
                        unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background);
                        unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground);
                        unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated);
-                       unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
                        unregister_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback);
 
                        break;
index e5b1af0..c6e4132 100644 (file)
@@ -1732,26 +1732,6 @@ static int delayed_init_done(void *data)
        return done;
 }
 
-static int battery_health_changed(void *data)
-{
-       int health = DATA_VALUE_INT(data);
-
-       _I("battery health change %d", health);
-
-       if (health == HEALTH_GOOD) {
-               clear_pm_status_flag(BATTERY_FLAG);
-               clear_pm_status_flag(DIMSTAY_FLAG);
-       } else if (health == HEALTH_LOW || health == HEALTH_HIGH || health == HEALTH_OVP) {
-               set_pm_status_flag(BATTERY_FLAG);
-               set_pm_status_flag(DIMSTAY_FLAG);
-       }
-
-       if (display_panel_get_dpms_cached_state() == DPMS_ON)
-               display_backlight_update_by_default_brightness();
-
-       return 0;
-}
-
 static gboolean delayed_dpms_init_done(gpointer data)
 {
        int timeout;
@@ -1927,7 +1907,6 @@ static void display_init(void *data)
        register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background);
        register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground);
        register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated);
-       register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
        register_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback);
        register_notifier(DEVICE_NOTIFIER_POWEROFF_TRIGGERED, poweroff_triggered_callback);
 
@@ -2069,7 +2048,6 @@ static void display_exit(void *data)
                        unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background);
                        unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground);
                        unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated);
-                       unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
                        unregister_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback);
 
                        break;
index d883963..960895c 100644 (file)
@@ -2058,27 +2058,6 @@ static int delayed_init_done(void *data)
        return done;
 }
 
-static int battery_health_changed(void *data)
-{
-       int health = DATA_VALUE_INT(data);
-
-       _I("battery health change %d", health);
-
-       if (health == HEALTH_GOOD) {
-               clear_pm_status_flag(BATTERY_FLAG);
-               clear_pm_status_flag(DIMSTAY_FLAG);
-               if (display_panel_get_dpms_cached_state() == DPMS_ON)
-                       auto_brightness_restore();
-       } else if (health == HEALTH_LOW || health == HEALTH_HIGH || health == HEALTH_OVP) {
-               set_pm_status_flag(BATTERY_FLAG);
-               set_pm_status_flag(DIMSTAY_FLAG);
-               if (display_panel_get_dpms_cached_state() == DPMS_ON)
-                       display_backlight_update_by_default_brightness();
-       }
-
-       return 0;
-}
-
 static int powerlock_load_config(struct parse_result *result, void *user_data)
 {
        char *name = NULL;
@@ -2311,7 +2290,6 @@ static void display_init(void *data)
        register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background);
        register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground);
        register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated);
-       register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
        register_notifier(DEVICE_NOTIFIER_LCD_AUTOBRT_SENSING, display_auto_brightness_sensing);
        register_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback);
        register_notifier(DEVICE_NOTIFIER_POWEROFF_TRIGGERED, poweroff_triggered_callback);
@@ -2455,7 +2433,6 @@ static void display_exit(void *data)
                        unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background);
                        unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground);
                        unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated);
-                       unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed);
                        unregister_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback);
 
                        break;
index d8588f5..c0bb9f8 100644 (file)
  */
 
 #include <stdio.h>
+#include <stdbool.h>
 
 #include <vconf-keys.h>
 
+#include "battery/power-supply.h"
+#include "shared/device-notifier.h"
 #include "shared/log.h"
+#include "display.h"
+#include "display-backlight.h"
 #include "display-misc.h"
+#include "display-panel.h"
 #include "display-plugin.h"
 #include "poll.h"
 
@@ -83,4 +89,35 @@ void display_misc_get_stay_touchscreen_off(bool *on)
        }
 
         *on = stay_touchscreen_off;
+}
+
+/* FIXME: This fucntion should be relocated under the battery module or redefined */
+static int changed_battery_health(void *data)
+{
+       int health = DATA_VALUE_INT(data);
+
+       _I("battery health change %d", health);
+
+       if (health == HEALTH_GOOD) {
+               clear_pm_status_flag(BATTERY_FLAG);
+               clear_pm_status_flag(DIMSTAY_FLAG);
+       } else if (health == HEALTH_LOW || health == HEALTH_HIGH || health == HEALTH_OVP) {
+               set_pm_status_flag(BATTERY_FLAG);
+               set_pm_status_flag(DIMSTAY_FLAG);
+       }
+
+       if (display_panel_get_dpms_cached_state() == DPMS_ON)
+               display_backlight_update_by_default_brightness();
+
+       return 0;
+}
+
+void display_misc_register_battery_health_notifier(void)
+{
+       register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, changed_battery_health);
+}
+
+void display_misc_unregister_battery_health_notifier(void)
+{
+       unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, changed_battery_health);
 }
\ No newline at end of file
index 96518b9..0ddb640 100644 (file)
@@ -31,5 +31,7 @@ bool display_misc_is_low_battery_state(int val);
 void display_misc_get_process_name(pid_t pid, char *pname);
 void display_misc_set_stay_touchscreen_off(bool on);
 void display_misc_get_stay_touchscreen_off(bool *on);
+void display_misc_register_battery_health_notifier(void);
+void display_misc_unregister_battery_health_notifier(void);
 
 #endif /* __DISPLAY_MISC_H__ */
\ No newline at end of file
index 476298f..dd89a24 100644 (file)
@@ -23,6 +23,7 @@
 #include "display.h"
 #include "display-plugin.h"
 #include "display-config.h"
+#include "display-misc.h"
 #include "display-signal.h"
 
 static const struct device_ops *display_plugin_device_ops;
@@ -173,6 +174,7 @@ static void display_init(void *data)
        display_plugin_device_ops->init(data);
 
        display_signal_register_display_brightness_notifier();
+       display_misc_register_battery_health_notifier();
 }
 
 static void display_exit(void *data)
@@ -183,6 +185,7 @@ static void display_exit(void *data)
        display_plugin_device_ops->exit(data);
 
        display_signal_unregister_display_brightness_notifier();
+       display_misc_unregister_battery_health_notifier();
 }
 
 static int display_start(enum device_flags flags)