Blob Blame History Raw
commit 775a99e8bc1e9c5e277ff17a84a406227a5a32fb
Author: Emmanuel Pescosta <emmanuelpescosta099@gmail.com>
Date:   Tue Jun 17 17:35:19 2014 +0200

    Consider additional batteries for power management (when the critical battery timer is running)
    
    After resuming from suspend, all batteries are added
    to powerdevil. When a battery, with charge lower or
    equal than the critical charge percentage is added, the
    critical battery timer will be started.
    
    In the current version the critical battery timeout can
    only be interrupted by plugging in AC.
    
    But if the system has more than one battery, the global
    charge percentage can be greater than the critical charge
    percentage and so the system shouldn't suspend. To achive
    this behaviour, we calculate the global charge percentage
    whenever a new battery was added and if the critical
    battery timer is running and the global charge is high
    enough, we stop the timer.
    
    Also we use the already calculated global charge percentage
    for the battery charge percentage notification instead of
    the charge of each individual battery.
    
    With this patch, the user can not only interrupt the critical
    timer by plugging in the AC but also by plugging in a new or
    additional battery (if the battery has enough charge).
    
    Note: The 30 sec timeout message will still popup.
    
    Tested with a Thinkpad T440s (two batteries)
    
    @Philipp Paris: Thanks for testing!
    
    BUG: 329537
    BUG: 325707
    FIXED-IN: 4.11.11
    REVIEW: 118801

diff --git a/powerdevil/daemon/powerdevilcore.cpp b/powerdevil/daemon/powerdevilcore.cpp
index 76e1b82..d096d74 100644
--- a/powerdevil/daemon/powerdevilcore.cpp
+++ b/powerdevil/daemon/powerdevilcore.cpp
@@ -456,8 +456,20 @@ void Core::onDeviceAdded(const QString& udi)
     }
     m_loadedBatteriesUdi.append(udi);
 
+    // Compute the current global percentage
+    int globalChargePercent = 0;
+    for (QHash<QString,int>::const_iterator i = m_batteriesPercent.constBegin(); i != m_batteriesPercent.constEnd(); ++i) {
+        globalChargePercent += i.value();
+    }
+
+    // If a new battery has been added, let's clear some pending suspend actions if the new global batteries percentage is
+    // higher than the battery low level. (See bug 329537)
+    if (m_criticalBatteryTimer->isActive() && globalChargePercent > PowerDevilSettings::batteryCriticalLevel()) {
+        m_criticalBatteryTimer->stop();
+    }
+
     // So we get a "Battery is low" notification directly on system startup if applicable
-    emitBatteryChargePercentNotification(b->chargePercent(), 100);
+    emitBatteryChargePercentNotification(globalChargePercent, 100);
 }
 
 void Core::onDeviceRemoved(const QString& udi)