battery : read fails /sys/class/power_supply/battery/capacity at the first access... 66/135366/2 accepted/tizen_4.0_unified tizen_4.0 accepted/tizen/4.0/unified/20170816.012212 accepted/tizen/4.0/unified/20170828.224128 accepted/tizen/unified/20170626.011735 submit/tizen/20170623.065932 submit/tizen_4.0/20170811.094300 submit/tizen_4.0/20170828.110001 tizen_4.0.IoT.p1_release tizen_4.0.IoT.p2_release tizen_4.0.m2_release
authorINSUN PYO <insun.pyo@samsung.com>
Thu, 22 Jun 2017 05:24:58 +0000 (14:24 +0900)
committerINSUN PYO <insun.pyo@samsung.com>
Thu, 22 Jun 2017 05:53:20 +0000 (14:53 +0900)
When the TW emulator first accesses /sys/class/power_supply/battery/capacity,
it sometimes returns an empty string.

So, lowbat_monitor() is called with 0 parameter.
"0" means that battery level is 0.
When deviced detects battery level 0, it creates a 30 second power off timer.
So the emulator automatically powers off intermittently after 35 seconds.

If an empty string is returned, we modify it to read /sys/clas/power_supply/battery/capacity again.

Signed-off-by: INSUN PYO <insun.pyo@samsung.com>
Change-Id: Ieefd950fe175ef138814624f6a3957ac7432cc74

hw/battery/battery.c

index 5f16019..583a5c3 100644 (file)
@@ -176,6 +176,18 @@ static int battery_get_current_state(
                _E("Failed to get value of (%s, %d)", FILE_BATTERY_CAPACITY, ret);
                return ret;
        }
+
+        /* When the TW emulator first accesses /sys/class/power_supply/battery/capacity,
+           it sometimes returns an empty string. */
+        if (capacity_str[0] == 0) {
+                _E("/sys/class/power_supply/battery/capacity returns null string, retry read it again");
+                ret = sys_get_str(FILE_BATTERY_CAPACITY, capacity_str, sizeof(capacity_str));
+                if (ret < 0) {
+                         _E("Failed to get value of (%s, %d)", FILE_BATTERY_CAPACITY, ret);
+                         return ret;
+                }
+        }
+
        ret = sys_get_str(FILE_BATTERY_CHARGER_ONLINE, charger_str, sizeof(charger_str));
        if (ret < 0) {
                _E("Failed to get value of (%s, %d)", FILE_BATTERY_CHARGER_ONLINE, ret);