battery: redefine battery level threshold 77/278677/4
authorYoungjae Cho <y0.cho@samsung.com>
Mon, 25 Jul 2022 04:50:00 +0000 (13:50 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Tue, 26 Jul 2022 02:20:37 +0000 (11:20 +0900)
The realoff threshold has been removed and the poweroff level takes
over the role of realoff level.

Change-Id: I887c3a49cd6d251e3c2837b6a123a6d0b190c708
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
conf/battery.conf
src/battery/battery.h
src/battery/config.c
src/battery/config.h
src/battery/lowbat-handler.c
src/battery/power-supply.c
tests/auto-test/battery.c

index d854e14..8b65792 100644 (file)
@@ -3,9 +3,6 @@ Normal=100
 Warning=15
 Critical=5
 PowerOff=1
-RealOff=0
-WarningMethod=warning
-CriticalMethod=critical
 
 # hold wakelock if a charger has been connected, iot-headless only
 [ChargerWakelock]
index 51c73a3..0aa7b8d 100644 (file)
@@ -41,7 +41,6 @@ struct battery_config_info {
        int warning;
        int critical;
        int poweroff;
-       int realoff;
 };
 
 int battery_charge_err_low_act(void *data);
index 1595040..54e3da5 100644 (file)
@@ -58,8 +58,6 @@ static int load_config(struct parse_result *result, void *user_data)
                info->critical = atoi(value);
        else if (MATCH(name, "PowerOff"))
                info->poweroff = atoi(value);
-       else if (MATCH(name, "RealOff"))
-               info->realoff = atoi(value);
 
        return 0;
 }
@@ -78,6 +76,5 @@ void battery_config_load(struct battery_config_info *info)
                info->warning = -1;
                info->critical = -2;
                info->poweroff = -3;
-               info->realoff = -4;
        }
 }
index 77ca856..0e0fa52 100644 (file)
@@ -25,7 +25,6 @@
 #define BATTERY_WARNING  15
 #define BATTERY_CRITICAL 5
 #define BATTERY_POWEROFF 1
-#define BATTERY_REALOFF  0
 
 void battery_config_load(struct battery_config_info *info);
 #endif /* __BATTERY_CONFIG_H__ */
index ecf3430..e3844b4 100644 (file)
@@ -81,7 +81,6 @@ struct battery_config_info battery_info = {
        .warning  = BATTERY_WARNING,
        .critical = BATTERY_CRITICAL,
        .poweroff = BATTERY_POWEROFF,
-       .realoff  = BATTERY_REALOFF,
 };
 
 static GList *lpe;
@@ -291,7 +290,7 @@ static int battery_critical_low_act(void *data)
        return 0;
 }
 
-int battery_power_off_act(void *data)
+static int battery_power_off_act(void *data)
 {
        CRITICAL_LOG("Low battery power off.");
        return power_execute(POWER_STATE_POWEROFF);
@@ -329,17 +328,12 @@ static void lowbat_scenario_init(void)
 
        lowbat_add_scenario(battery_info.normal, battery_info.warning, battery_warning_low_act);
        lowbat_add_scenario(battery_info.normal, battery_info.critical, battery_critical_low_act);
-       lowbat_add_scenario(battery_info.normal, battery_info.poweroff, battery_critical_low_act);
-       lowbat_add_scenario(battery_info.normal, battery_info.realoff, battery_power_off_act);
+       lowbat_add_scenario(battery_info.normal, battery_info.poweroff, battery_power_off_act);
        lowbat_add_scenario(battery_info.warning, battery_info.warning, battery_warning_low_act);
        lowbat_add_scenario(battery_info.warning, battery_info.critical, battery_critical_low_act);
-       lowbat_add_scenario(battery_info.warning, battery_info.poweroff, battery_critical_low_act);
-       lowbat_add_scenario(battery_info.warning, battery_info.realoff, battery_power_off_act);
+       lowbat_add_scenario(battery_info.warning, battery_info.poweroff, battery_power_off_act);
        lowbat_add_scenario(battery_info.critical, battery_info.critical, battery_critical_low_act);
-       lowbat_add_scenario(battery_info.critical, battery_info.realoff, battery_power_off_act);
-       lowbat_add_scenario(battery_info.poweroff, battery_info.poweroff, battery_critical_low_act);
-       lowbat_add_scenario(battery_info.poweroff, battery_info.realoff, battery_power_off_act);
-       lowbat_add_scenario(battery_info.realoff, battery_info.realoff, battery_power_off_act);
+       lowbat_add_scenario(battery_info.poweroff, battery_info.poweroff, battery_power_off_act);
 }
 
 static void battery_level_send_system_event(int bat_percent)
@@ -495,17 +489,7 @@ static int lowbat_process(int bat_percent, void *ad)
                return -EIO;
        }
 
-       if (new_bat_capacity <= battery_info.realoff) {
-               if (battery->charge_now == CHARGER_CHARGING) {
-                       new_bat_state = battery_info.poweroff;
-                       if (vconf_state != VCONFKEY_SYSMAN_BAT_POWER_OFF)
-                               status = VCONFKEY_SYSMAN_BAT_POWER_OFF;
-               } else {
-                       new_bat_state = battery_info.realoff;
-                       if (vconf_state != VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF)
-                               status = VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF;
-               }
-       } else if (new_bat_capacity <= battery_info.poweroff) {
+       if (new_bat_capacity <= battery_info.poweroff) {
                new_bat_state = battery_info.poweroff;
                if (vconf_state != VCONFKEY_SYSMAN_BAT_POWER_OFF)
                        status = VCONFKEY_SYSMAN_BAT_POWER_OFF;
@@ -535,13 +519,10 @@ static int lowbat_process(int bat_percent, void *ad)
 
        /* If the battery continues to run out even though it is being charged
         * for a certain period of time, turn off the device. */
-       if (new_bat_capacity <= battery_info.realoff && battery->charge_now == CHARGER_CHARGING) {
+       if (new_bat_capacity <= battery_info.poweroff && battery->charge_now == CHARGER_CHARGING) {
                if (low_bat_skip_cnt >= RETRY_MAX) {
-                       new_bat_state = battery_info.realoff;
-                       status = VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF;
                        _I("Go to real poweroff inspite of charging (c:%d charge:%d online:%d current_now:%d)",
                                battery->capacity, battery->charge_now, battery->charger_connected, battery->current_now);
-                       low_bat_skip_cnt = 0;
                } else if (battery->current_now <= MIN_INOW_VALUE) {
                        low_bat_skip_cnt++;
                } else {
@@ -572,13 +553,16 @@ static int lowbat_process(int bat_percent, void *ad)
                return result;
        if (cur_bat_state == new_bat_state && online == battery->charger_connected)
                return result;
+       if (new_bat_state <= battery_info.poweroff && battery->charger_connected && low_bat_skip_cnt < RETRY_MAX)
+               return result;
 
-       online = battery->charger_connected;
        if (cur_bat_state == BATTERY_UNKNOWN)
                cur_bat_state = battery_info.normal;
        if (lowbat_scenario(cur_bat_state, new_bat_state, NULL))
                _I("Cur(%d) new(%d) capacity(%d).", cur_bat_state, new_bat_state, bat_percent);
-               cur_bat_state = new_bat_state;
+
+       online = battery->charger_connected;
+       cur_bat_state = new_bat_state;
 
        return result;
 }
@@ -631,8 +615,8 @@ static int lowbat_monitor_init(void *data)
 
        /* load battery configuration file */
        battery_config_load(&battery_info);
-       _I("Battery conf: %d %d %d %d %d", battery_info.normal, battery_info.warning,
-               battery_info.critical, battery_info.poweroff, battery_info.realoff);
+       _I("Battery conf: %d %d %d %d", battery_info.normal, battery_info.warning,
+               battery_info.critical, battery_info.poweroff);
 
        lowbat_scenario_init();
        check_lowbat_percent(&battery->capacity);
@@ -749,8 +733,8 @@ static int lowbat_execute(void *data)
 
        /* Do lowbat_process immediately rather deferring it when poweroff is needed.
         * This prevents poweroff from being delayed infinitely when the uevent continues
-        * to occur shorter than 1.5 seconds on realoff capacity */
-       if (capacity <= battery_info.realoff || !uevent_buffering)
+        * to occur shorter than 1.5 seconds on poweroff capacity */
+       if (capacity <= battery_info.poweroff || !uevent_buffering)
                low_battery_charging_status(data);
        else
                low_batt_sig_timer = g_timeout_add(1500, low_battery_charging_status, data);
index ce4e7fc..197fabe 100644 (file)
@@ -751,13 +751,15 @@ static int battery_state(struct battery_info *info)
        }
 
        if (battery.capacity != 0 && prev_status.capacity == battery.capacity &&
-           prev_status.charging_status == battery.charging_status &&
+               prev_status.charging_status == battery.charging_status &&
                prev_status.online_type == battery.online_type &&
-           prev_status.charge_full == battery.charge_full &&
-           prev_status.charge_now == battery.charge_now &&
-           prev_status.health == battery.health &&
-           prev_status.present == battery.present &&
-           prev_status.charger_connected == battery.charger_connected)
+               prev_status.charge_full == battery.charge_full &&
+               prev_status.charge_now == battery.charge_now &&
+               prev_status.health == battery.health &&
+               prev_status.present == battery.present &&
+               prev_status.current_now == battery.current_now &&
+               prev_status.current_average == battery.current_average &&
+               prev_status.charger_connected == battery.charger_connected)
                return 0;
 
        prev_status.capacity = battery.capacity;
index b21e87d..6e98d98 100644 (file)
@@ -89,7 +89,6 @@
 #define DEFAULT_WARNING                15
 #define DEFAULT_CRITICAL       5
 #define DEFAULT_POWEROFF       1
-#define DEFAULT_REALOFF                0
 
 //Charger Type
 #define CHARGER_WIRELESS_TYPE_BT    10
@@ -532,11 +531,6 @@ static bool compare_vconf(struct power_supply_type list)
 
        if (invalid) {
                temp = -ENODEV;
-       } else if (capacity <= DEFAULT_REALOFF) {
-               if (charging_status == CHARGING_STATUS_CHARGING)
-                       temp = VCONFKEY_SYSMAN_BAT_POWER_OFF;
-               else
-                       temp = VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF;
        } else if (capacity <= DEFAULT_POWEROFF) {
                temp = VCONFKEY_SYSMAN_BAT_POWER_OFF;
        } else if (capacity <= DEFAULT_CRITICAL) {