[battery-stats] Changed heart sync policy (after rebooting, fully charged ...) &... 29/107029/3
authorSomin Kim <somin926.kim@samsung.com>
Mon, 26 Dec 2016 07:22:42 +0000 (16:22 +0900)
committerSomin Kim <somin926.kim@samsung.com>
Mon, 26 Dec 2016 08:20:27 +0000 (17:20 +0900)
Change-Id: I72136a878c40bcd30942c218bc83c32b4a54e04c
Signed-off-by: Somin Kim <somin926.kim@samsung.com>
packaging/context-provider.spec
src/battery-stats/BatteryMonitor.cpp
src/battery-stats/BatteryMonitor.h

index d9735235d9f37c7447a13f8ac06a2914cb7446d9..7a223042c391d7cafac8454ddeb22f392eb6b44e 100644 (file)
@@ -1,6 +1,6 @@
 Name:       context-provider
 Summary:    Context Provider
-Version:    0.9.11
+Version:    0.9.12
 Release:    1
 Group:      Service/Context
 License:    Apache-2.0
index 4c34e8cec434f71e74c5cabb7fabf786f87e7d23..3e1715fb2c9336e769dbca20db835e60faa4d7ae 100644 (file)
 
 using namespace ctx;
 
+bool __needSync = true;
 BatteryMonitor* BatteryMonitor::__instance = NULL;
 
 BatteryMonitor::BatteryMonitor() :
-       __bootingTime(0),
        __lastFullTime(0),
        __lastHeartAccessTime(0),
        __heartReader(NULL)
@@ -80,8 +80,6 @@ void BatteryMonitor::initialize()
 
 bool BatteryMonitor::__loadLastInfo()
 {
-       __bootingTime = CURRENT_TIME;
-
        std::vector<Json> records;
        bool ret = __dbMgr.executeSync(
                        "SELECT * FROM " BATTERY_LAST_INFO_TABLE \
@@ -93,6 +91,12 @@ bool BatteryMonitor::__loadLastInfo()
                records[0].get(NULL, BATTERY_LAST_HEART_ACCESS_TIME, &__lastHeartAccessTime);
        }
 
+       if (__lastFullTime == 0) {
+               __lastFullTime = CURRENT_TIME;
+               _I("Device has not fully charged until now. Start time of recent battery usage will be %d", __lastFullTime);
+               __updateLastInfo();
+       }
+
        return true;
 }
 
@@ -120,6 +124,8 @@ void BatteryMonitor::__chargerChangeCb(device_callback_e type, void* value, void
 
        // If charger is disconnected after 100% charged
        if (percent == 100) {
+               __needSync = true;
+
                instance->__lastFullTime = CURRENT_TIME;
                _D("Charger is disconnected after fully charged. Last fully charged time: %d", instance->__lastFullTime);
 
@@ -230,6 +236,7 @@ bool BatteryMonitor::__processBatteryUsage()
        IF_FAIL_RETURN_TAG(ret, false, _E, "Failed to update last cpu log");
 
        __removeExpiredLog();
+       __needSync = false;
 
        return true;
 }
@@ -318,19 +325,14 @@ bool BatteryMonitor::__updateLastCpuUsageLog(CpuUsageMap& usage)
 // Used for Recent Battery Usage
 int BatteryMonitor::getLastFullTime()
 {
-       if (__lastFullTime == 0) {
-               _I("Device has not fully charged until now. Start time of recent battery usage will be booting time: %d", __bootingTime);
-               return __bootingTime;
-       }
-
        return __lastFullTime;
 }
 
 void BatteryMonitor::prepareData()
 {
        int timeDiff = CURRENT_TIME - __lastHeartAccessTime;
-       IF_FAIL_VOID_TAG(timeDiff >= 5 * 60 * 1000,
-               _D, "Battery usage was updated %d minutes ago", timeDiff / 60000);
+       IF_FAIL_VOID_TAG(__needSync || timeDiff >= 5 * 60,
+               _D, "Battery usage was updated %d minutes ago", timeDiff / 60);
 
        _D("Request to sync heart cpu data");
        bool ret = __heartReader->requestSync();
index 4127b09065c3cd89ed7e6e456c5518e2ac7d2c84..f87dc3ba00774610b3142befae0dd1e47955a295 100644 (file)
@@ -52,7 +52,6 @@ namespace ctx {
                static int __timeoutCb(void* data);
 
                static BatteryMonitor* __instance;
-               int __bootingTime;
                int __lastFullTime;
                int __lastHeartAccessTime;