Изменения статуса заряда батареи

From Toshiba AC100 wiki
Jump to navigation Jump to search
  • В реальном времени не обновляется статус батареи
    • Статус меняется только при загрузке системы (и по не проверенной информации иногда обновляется при попытках сна)
      • Статус заряда батареи проживает у нас в обычном месте /sys/class/power_supply/battery, в status дело которое сейчас делает

например Charging или Discharging, в capacity заряд в цифирях

E/BatteryService(  175): usbOnlinePath not found
E/BatteryService(  175): batteryHealthPath not found
E/BatteryService(  175): batteryTemperaturePath not found

* Нашел вот такое упоминание о том как берется процент заряда On the G1, the kernel will push the "Remaining Battery Percentage" to the sysfs entries directly.

        • Инфа конечно старая не факт, что так до сих пор
        • Еще инфо из android-porting гугло группы как андроид забирает статус батареи, видимо более актуальное т.к. похоже на правду
Matthias Kaehlcke 	
Post reply
More message actions
Aug 3 (8 days ago)
Re: [android-porting] Android ICS - How to integrate battery status info with Android
Hi K.U.

El Thu, Aug 02, 2012 at 03:32:16AM -0700 K.U. ha dit:

>    I am working on an Android-ICS porting project onto a custom Android Tab,
>    which uses AM3730 (TI's ARM) processor. The device is based on the
>    BeagleBoard architecture. The device has a fuel guage (BQ27200) and a
>    charger IC (BQ24150) which communicates with a
>    MSP430 micro-controller firmware.
>    My main problem is how to display the battery status through the "battery
>    icon" on the taskbar? Also I am aware that the other battery related
>    operations/status (charging, discharging, battery low, fully charged)
>    could also be read by the Android system and act accordingly. I could not
>    find a clear set of instructions on how to integrate these features with
>    android.
>    Can some one kindly direct me to a link/site where I can find a guide for
>    this task? Or if any of you can take the time to reply this post, it will
>    be greatly appreciated.

Android gets the battery and charger status from the power supply
devices registered in the kernel. whenever the status of a
power supply changes (charging/discharging, battery level, charger
plugged/unplugged, ...), the kernel sends a so called uevent
(userspace event). user processes can register to these uevents, which
is what Androids BatteryService does. when the BatteryService is
notified about a change in a power supply it reads the updated status
of the power supply from sysfs and sends out the corresponding intents
which cause the update of the battery icon and so on

for the BQ27200 fuel gauge you have the bq27x00_battery driver in the
kernel (drivers/power/bq27x00_battery.c), which provides the
battery status through uevents and sysfs as outlined above. if
configured correctly you should see on your running system a power
supply of type battery in /sys/class/power_supply/ with attributes
like the current battery capacity or the charging status

best regards

Matthias Kaehlcke
Embedded Linux Developer

' Надо найти я ядре девайс у которого это есть и перенести в наши дрова (drivers/power/bq27x00_battery.c походящий вроде кандидат

diff --git a/services/java/com/android/server/BatteryService.java b/services/java/com/android/server/BatteryService.java
index 76a4cb0..a54d7ea 100644 (file)
--- a/services/java/com/android/server/BatteryService.java
+++ b/services/java/com/android/server/BatteryService.java
@@ -144,8 +144,18 @@ class BatteryService extends Binder {
-        // set initial status
-        update();
+        // start polling
+        new Thread(new Runnable() {
+            public void run() {
+                while (true) {
+                    update();
+                    try {
+                        Thread.sleep(30);
+                    } catch (InterruptedException e) {
+                    }
+                }
+            }
+        }, "BatteryServiceUpdateThread").start();
     final boolean isPowered() {

Полезный тред в котором рассказывается как это все работает http://e2e.ti.com/support/embedded/android/f/509/t/192462.aspx

    • Найдено правильное решение на уровне драйвера в ядре
diff --git a/drivers/staging/nvec/nvec_power.c b/drivers/staging/nvec/nvec_power.c
index dfa966f..2c9dfcd 100644
--- a/drivers/staging/nvec/nvec_power.c
+++ b/drivers/staging/nvec/nvec_power.c
@@ -216,6 +216,8 @@ static int nvec_power_bat_notifier(struct notifier_block *nb,
                return NOTIFY_STOP;
+       // FIXME Investigate when this call is really needed
+       power_supply_changed(&nvec_bat_psy);
        return NOTIFY_STOP;