This path allows reading the status of any battery reporting uevents
 
I'm not too happy with it  but now my freeruner don't goes to sleep when 
connected (kernel 2.6.39).
I plan to polish it a little more and pressent more info on 
org.freesmartphone.Info.GetInfo dbus call 
like online power supplies but I am not sure if I'll have time this week 
diff --git a/fsodeviced/src/plugins/kernel26_powersupply/plugin.vala b/fsodeviced/src/plugins/kernel26_powersupply/plugin.vala
index 9baa149..357588d 100644
--- a/fsodeviced/src/plugins/kernel26_powersupply/plugin.vala
+++ b/fsodeviced/src/plugins/kernel26_powersupply/plugin.vala
@@ -183,7 +183,9 @@ class PowerSupply : FreeSmartphone.Device.PowerSupply,
 /**
  * Implementation of org.freesmartphone.Device.PowerSupply as aggregated Kernel26 Power-Class Devices
  **/
-class AggregatePowerSupply : FreeSmartphone.Device.PowerSupply, FsoFramework.AbstractObject
+class AggregatePowerSupply : FreeSmartphone.Device.PowerSupply,
+                             FreeSmartphone.Info,
+			     FsoFramework.AbstractObject
 {
     private const uint POWER_SUPPLY_CAPACITY_CHECK_INTERVAL = 5 * 60;
     private const uint POWER_SUPPLY_CAPACITY_CRITICAL = 7;
@@ -201,6 +203,7 @@ class AggregatePowerSupply : FreeSmartphone.Device.PowerSupply, FsoFramework.Abs
         this.sysfsnode = sysfsnode;
 
         subsystem.registerObjectForService<FreeSmartphone.Device.PowerSupply>( FsoFramework.Device.ServiceDBusName, FsoFramework.Device.PowerSupplyServicePath, this );
+        subsystem.registerObjectForService<FreeSmartphone.Info>( FsoFramework.Device.ServiceDBusName, FsoFramework.Device.PowerSupplyServicePath, this );
 
         FsoFramework.BaseKObjectNotifier.addMatch( "change", "power_supply", onPowerSupplyChangeNotification );
 
@@ -250,22 +253,11 @@ class AggregatePowerSupply : FreeSmartphone.Device.PowerSupply, FsoFramework.Abs
             logger.warning( "POWER_SUPPLY_NAME not present, ignoring power supply change notification" );
             return;
         }
-        var technology = properties.lookup( "POWER_SUPPLY_TECHNOLOGY" );
-        var typ = properties.lookup( "POWER_SUPPLY_TYPE" );
-        if ( typ == null )
-        {
-            logger.warning( "POWER_SUPPLY_TYPE not present, checking for POWER_SUPPLY_TECHNOLOGY..." );
-            if ( technology != null )
-            {
-                logger.warning( "Present; treating it like a battery" );
-                typ = "battery";
-            }
-            else
-            {
-                logger.warning( "Not present; treating it like an AC adapter" );
-                typ = "ac";
-            }
-        }
+/*  the only sure  key for a battery is POWER_SUPPLY_STATUS see kernel Documentation/power_supply_class.txt 
+    or Documentation/power/power_supply_class.txt
+*/
+	var stat = properties.lookup( "POWER_SUPPLY_STATUS" );
+	var typ = ( stat == null ) ? "ac" : "battery";
 
         var status = "unknown";
         var present = false;
@@ -275,7 +267,7 @@ class AggregatePowerSupply : FreeSmartphone.Device.PowerSupply, FsoFramework.Abs
             var online = properties.lookup( "POWER_SUPPLY_ONLINE" );
             if ( online == null )
             {
-                logger.warning( "POWER_SUPPLY_ONLY not present, ignoring power supply change notification" );
+                logger.warning( "POWER_SUPPLY_ONLINE not present, ignoring power supply change notification" );
                 return;
             }
             present = ( online.down() == "1" );
@@ -289,12 +281,7 @@ class AggregatePowerSupply : FreeSmartphone.Device.PowerSupply, FsoFramework.Abs
                 logger.warning( "POWER_SUPPLY_PRESENT not present, ignoring power supply change notification" );
                 return;
             }
-            var stat = properties.lookup( "POWER_SUPPLY_STATUS" );
-            if ( stat == null )
-            {
-                logger.warning( "POWER_SUPPLY_STATUS not present, battery might have been removed"  );
-                stat = "unknown";
-            }
+
             present = ( pres.down() == "1" );
             status = stat.down();
 
@@ -361,7 +348,7 @@ class AggregatePowerSupply : FreeSmartphone.Device.PowerSupply, FsoFramework.Abs
     {
         var statusForAll = true;
         PowerSupply battery = null;
-        PowerSupply charger = null;
+        bool charger = false;
 
         // first, check whether we have enough information to compute the status at all
         foreach ( var supply in instances )
@@ -381,8 +368,7 @@ class AggregatePowerSupply : FreeSmartphone.Device.PowerSupply, FsoFramework.Abs
             }
             else
             {
-                if ( supply.status == FreeSmartphone.Device.PowerStatus.ONLINE ) // FIXME: revisit to handle multiple chargers
-                    charger = supply;
+                charger |= (supply.status == FreeSmartphone.Device.PowerStatus.ONLINE ); // FIXME: revisit to handle multiple chargers
             }
         }
 
@@ -393,9 +379,17 @@ class AggregatePowerSupply : FreeSmartphone.Device.PowerSupply, FsoFramework.Abs
         }
 
         // if we have a battery and it is inserted, this is our aggregate status
+        // except when a power supply is online and not charging battery
         if ( battery != null && battery.status != FreeSmartphone.Device.PowerStatus.REMOVED )
         {
-            sendStatusIfChanged( battery.status );
+            if (charger && battery.status != FreeSmartphone.Device.PowerStatus.CHARGING) 
+            {
+                sendStatusIfChanged( FreeSmartphone.Device.PowerStatus.AC );
+            }
+            else
+	    {
+	        sendStatusIfChanged( battery.status );
+	    }
         }
         // if we don't have a battery, we're on AC
         // FIXME: in that case we should give the name of the charger that charges us via get_info
@@ -472,6 +466,7 @@ class AggregatePowerSupply : FreeSmartphone.Device.PowerSupply, FsoFramework.Abs
         var res = new HashTable<string,Variant>( str_hash, str_equal );
         //FIXME: add more infos
         res.insert( "type", "aggregate" );
+	res.insert( "status",status );
         return res;
     }
 
_______________________________________________
Shr-devel mailing list
[email protected]
http://lists.shr-project.org/mailman/listinfo/shr-devel

Reply via email to