[battery-stats] Add defence code for time change case while booting 48/114548/4
authorSomin Kim <somin926.kim@samsung.com>
Tue, 14 Feb 2017 04:10:29 +0000 (13:10 +0900)
committerSomin Kim <somin926.kim@samsung.com>
Tue, 14 Feb 2017 05:04:00 +0000 (21:04 -0800)
(PLM P170208-07228, P170209-07541)

Change-Id: I035f14640874235ea04fde66fbad676de5a98690
Signed-off-by: Somin Kim <somin926.kim@samsung.com>
src/battery-stats/BatteryMonitor.cpp

index bee0c26..79940a8 100644 (file)
@@ -93,10 +93,16 @@ bool BatteryMonitor::__loadLastInfo()
                records[0].get(NULL, BATTERY_LAST_HEART_ACCESS_TIME, &__lastHeartAccessTime);
        }
 
+       int currentTime = CURRENT_TIME;
        if (__lastFullTime == 0) {
-               __lastFullTime = CURRENT_TIME;
+               __lastFullTime = currentTime;
                _I("Device has not fully charged until now. Start time of recent battery usage will be %d", __lastFullTime);
                __updateLastInfo();
+       } else if (__lastFullTime > currentTime || currentTime - __lastFullTime > LOG_RETENTION_PERIOD) {
+               __lastFullTime = currentTime;
+               __lastHeartAccessTime = currentTime;
+               _I("Last fully charged time changed: %d", __lastFullTime);
+               __updateLastInfo();
        }
 
        return true;
@@ -129,7 +135,7 @@ void BatteryMonitor::__chargerChangeCb(device_callback_e type, void* value, void
                __needSync = true;
 
                instance->__lastFullTime = CURRENT_TIME;
-               _D("Charger is disconnected after fully charged. Last fully charged time: %d", instance->__lastFullTime);
+               _I("Charger is disconnected after fully charged. Last fully charged time: %d", instance->__lastFullTime);
 
                bool ret = instance->__updateLastInfo();
                IF_FAIL_VOID_TAG(ret, _E, "Failed to update last reset time and last percent time");
@@ -141,7 +147,7 @@ void BatteryMonitor::__timeChangeCb(keynode_t* node, void* userData)
        int timeDiff = vconf_keynode_get_int(node);
        IF_FAIL_VOID(timeDiff != 0);
 
-       _D("Time changed. Related timestamps will be modified.");
+       _I("Time changed(diff: %d). Related timestamps will be modified.", timeDiff);
 
        BatteryMonitor* instance = static_cast<BatteryMonitor*>(userData);
        __needSync = true;
@@ -230,6 +236,14 @@ bool BatteryMonitor::__getLastCpuUsageTable(CpuUsageMap* lastHeartCpuLog)
 
 bool BatteryMonitor::__processBatteryUsage()
 {
+       int currentTime = CURRENT_TIME;
+       if (__lastHeartAccessTime > currentTime) {
+               __lastHeartAccessTime = currentTime - DEFAULT_TIME_DIFF;
+               __lastFullTime = currentTime - DEFAULT_TIME_DIFF;
+               __updateLastInfo();
+               _W("Last fully charged time & last heart access time changed(%d)", __lastFullTime);
+       }
+
        // Read from heart cpu table
        bool ret = __heartReader->dbOpen();
        IF_FAIL_RETURN_TAG(ret, true, _E, "Failed to open heart db");