From: Somin Kim Date: Tue, 14 Feb 2017 04:10:29 +0000 (+0900) Subject: [battery-stats] Add defence code for time change case while booting X-Git-Tag: accepted/tizen/3.0/common/20170215.121215~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=57b9f8838edf277f42a06f5b694cb98d168cc7d7;p=platform%2Fcore%2Fcontext%2Fcontext-provider.git [battery-stats] Add defence code for time change case while booting (PLM P170208-07228, P170209-07541) Change-Id: I035f14640874235ea04fde66fbad676de5a98690 Signed-off-by: Somin Kim --- diff --git a/src/battery-stats/BatteryMonitor.cpp b/src/battery-stats/BatteryMonitor.cpp index bee0c26..79940a8 100644 --- a/src/battery-stats/BatteryMonitor.cpp +++ b/src/battery-stats/BatteryMonitor.cpp @@ -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(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");