battery: Divide "display_changed" plugin interface 50/291850/10
authorTaeminYeom <taemin.yeom@samsung.com>
Mon, 24 Apr 2023 01:23:25 +0000 (10:23 +0900)
committerTaeminYeom <taemin.yeom@samsung.com>
Tue, 16 May 2023 09:05:36 +0000 (18:05 +0900)
In battery notificaion plugin, there was a function "display_changed"
used as a getter and setter duplicated about display state in
mobile and wearable battery plugin.
To divide the role of getting and setting display state
and they can be used in common devices, it is moved to core.

The role of setting display state in battery moudle is included in
new function "handle_display_state_changed", and it calls plugin interface
"launch_health_popup_by_display_state".

Previous "display_changed" is deleted from mobile battery plugin.
In wearable, the role of "display_changed" is moved to new function
"launch_health_popup_by_display_state". And it consists of the action
when display state is changed.

Change-Id: I1f63502ba36f10fcf93c99987c9ce132295397aa
Signed-off-by: TaeminYeom <taemin.yeom@samsung.com>
plugins/mobile/battery/battery-notification.c
plugins/wearable/battery/battery-notification.c
src/battery/battery-ops.h
src/battery/power-supply.c

index 09675eb..e91b7e3 100644 (file)
@@ -358,18 +358,6 @@ static void abnormal_popup_dbus_signal_handler(GDBusConnection  *conn,
                _E("Failed to add abnormal check timer.");
 }
 
-static int display_changed(void *data)
-{
-       static enum state_t state;
-
-       if (!data)
-               return state;
-
-       state = *(int *)data;
-
-       return state;
-}
-
 static void battery_notification_init(void *data)
 {
        struct battery_plugin *plugin = (struct battery_plugin *)data;
@@ -387,14 +375,10 @@ static void battery_notification_init(void *data)
        plugin->check_power_supply_noti = check_power_supply_noti;
        plugin->update_ovp = update_ovp;
 
-       plugin->display_changed = display_changed;
-
        ret = gdbus_signal_subscribe(NULL, DEVICED_PATH_SYSNOTI,
                DEVICED_INTERFACE_SYSNOTI, SIGNAL_CHARGEERR_RESPONSE, abnormal_popup_dbus_signal_handler, NULL, NULL);
        if (ret <= 0)
                _E("Failed to init dbus signal: %d", ret);
-
-       register_notifier(DEVICE_NOTIFIER_LCD, display_changed);
 }
 
 static const struct battery_ops battery_notification_ops = {
index 666aada..19701ca 100644 (file)
 
 static struct battery_status *battery;
 
-static int display_changed(void *data)
+static void launch_health_popup_by_display_state(int display_state)
 {
-       static enum state_t old;
-       static enum state_t state;
+       static enum state_t old = S_START;
 
-       if (!data)
-               return state;
-
-       old = state;
-       state = *(int *)data;
-
-       if (battery->health != HEALTH_LOW && battery->health != HEALTH_HIGH)
-               return state;
+       if (battery->health != HEALTH_LOW && battery->health != HEALTH_HIGH) {
+               old = display_state;
+               return;
+       }
 
        /* relaunch health popup on LCDON */
-       if ((old == S_SLEEP || old == S_LCDOFF)
-               && (state == S_LCDDIM || state == S_NORMAL))
+       if ((old == S_SLEEP || old == S_LCDOFF || old == S_START)
+               && (display_state == S_LCDDIM || display_state == S_NORMAL))
                relaunch_health_popup();
-
-       return state;
+       old = display_state;
 }
 
 static int check_power_supply_noti(void)
@@ -77,9 +71,8 @@ static void battery_notification_init(void *data)
        _D("Add plugins for battery notification.");
        plugin->check_power_supply_noti = check_power_supply_noti;
        plugin->update_ovp = update_ovp;
-       plugin->display_changed = display_changed;
-
-       register_notifier(DEVICE_NOTIFIER_LCD, display_changed);
+       plugin->launch_health_popup_by_display_state =
+               launch_health_popup_by_display_state;
 }
 
 static const struct battery_ops battery_notification_ops = {
index faee811..37efd0d 100644 (file)
@@ -41,7 +41,7 @@ struct battery_plugin {
        int (*changed_battery_cf) (int status);
        void (*remove_health_popup) (void);
 
-       int (*display_changed) (void *);
+       void (*launch_health_popup_by_display_state) (int display_state);
        int (*check_power_supply_noti) (void);
        void (*update_ovp) (enum battery_noti_status status);
        /* Add plugins here */
index d6d210e..fb65178 100644 (file)
@@ -94,6 +94,8 @@ static bool launching_health_popup;
 static guint power_timer;
 static device_notifier_state_e old_state = -1;
 
+static enum state_t g_display_state = S_NORMAL;
+
 bool battery_initialized;
 
 bool battery_do_not_disturb(void);
@@ -1291,23 +1293,40 @@ static int delayed_init_done(void *data)
        return done;
 }
 
+/**
+ * FIXME: Getting display state shoule be done by display module function.
+ * After refactoring display module, it should be changed to use getter in display module.
+ */
+static int handle_display_state_changed(void *data)
+{
+       if (!data) {
+               _E("Invalid parameter");
+               return -EINVAL;
+       }
+
+       g_display_state = *(int *)data;
+
+       if (battery_plgn->launch_health_popup_by_display_state)
+               battery_plgn->launch_health_popup_by_display_state(g_display_state);
+
+       return 0;
+}
+
 bool battery_do_not_disturb(void)
 {
        int block = 0, theater = 0, night = 0;
        int r;
 
-       if (battery_plgn->display_changed) {
-               if (battery_plgn->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 blockmode wearable: %d", vconf_get_ext_errno());
-                       r = vconf_get_bool(VCONFKEY_SETAPPL_THEATER_MODE_ENABLE, &theater);
-                       if (r < 0)
-                               _E("Failed to set vconf value for theator mode enable: %d", vconf_get_ext_errno());
-                       r = vconf_get_bool(VCONFKEY_SETAPPL_GOODNIGHT_MODE_ENABLE, &night);
-                       if (r < 0)
-                               _E("Failed to set vconf value for goodnight mode enable: %d", vconf_get_ext_errno());
-               }
+       if (g_display_state == S_LCDOFF) {
+               r = vconf_get_bool(VCONFKEY_SETAPPL_BLOCKMODE_WEARABLE_BOOL, &block);
+               if (r < 0)
+                       _E("Failed to set vconf value for blockmode wearable: %d", vconf_get_ext_errno());
+               r = vconf_get_bool(VCONFKEY_SETAPPL_THEATER_MODE_ENABLE, &theater);
+               if (r < 0)
+                       _E("Failed to set vconf value for theator mode enable: %d", vconf_get_ext_errno());
+               r = vconf_get_bool(VCONFKEY_SETAPPL_GOODNIGHT_MODE_ENABLE, &night);
+               if (r < 0)
+                       _E("Failed to set vconf value for goodnight mode enable: %d", vconf_get_ext_errno());
        }
 
        if (block != 0 || theater != 0 || night != 0) {
@@ -1449,6 +1468,7 @@ static void power_supply_init(void *data)
 
        register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done);
        register_notifier(DEVICE_NOTIFIER_EVENT_HANDLER, event_handler_state_changed);
+       register_notifier(DEVICE_NOTIFIER_LCD, handle_display_state_changed);
 
        ret_dbus = gdbus_add_object(NULL, DEVICED_PATH_BATTERY, &dbus_interface);
        if (ret_dbus < 0)