power: android-battery: leave full/not-charging status when charger re-sensed
authorTodd Poynor <toddpoynor@google.com>
Thu, 4 Oct 2012 23:11:53 +0000 (16:11 -0700)
committerArve Hjønnevåg <arve@android.com>
Mon, 1 Jul 2013 21:16:10 +0000 (14:16 -0700)
If charger was connected and a charge source change event occurs such that
the charger is still connected (or a different charge source connected),
do not overwrite an existing state such as full or not-charging.  Only
switch from discharging to charging on a charge source change event.

Change-Id: I1b841c8f3a92bf15074999e18b17d1d19ce028d7
Signed-off-by: Todd Poynor <toddpoynor@google.com>
drivers/power/android_battery.c

index d6ff01adcd087f6f598c7112643050f525a57116..d7682d69e3abbb39e7c50b9c0cec5b8a14bebb97 100644 (file)
@@ -399,8 +399,18 @@ static void android_bat_charger_work(struct work_struct *work)
                break;
        case CHARGE_SOURCE_USB:
        case CHARGE_SOURCE_AC:
-               battery->charging_status = POWER_SUPPLY_STATUS_CHARGING;
-               android_bat_enable_charging(battery, true);
+               /*
+                * If charging status indicates a charger was already
+                * connected prior to this and a non-charging status is
+                * set, leave the status alone.
+                */
+               if (battery->charging_status ==
+                   POWER_SUPPLY_STATUS_DISCHARGING ||
+                   battery->charging_status == POWER_SUPPLY_STATUS_UNKNOWN) {
+                       battery->charging_status = POWER_SUPPLY_STATUS_CHARGING;
+                       android_bat_enable_charging(battery, true);
+               }
+
                break;
        default:
                pr_err("%s: Invalid charger type\n", __func__);