using namespace ctx;
+bool __needSync = true;
BatteryMonitor* BatteryMonitor::__instance = NULL;
BatteryMonitor::BatteryMonitor() :
- __bootingTime(0),
__lastFullTime(0),
__lastHeartAccessTime(0),
__heartReader(NULL)
bool BatteryMonitor::__loadLastInfo()
{
- __bootingTime = CURRENT_TIME;
-
std::vector<Json> records;
bool ret = __dbMgr.executeSync(
"SELECT * FROM " BATTERY_LAST_INFO_TABLE \
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;
}
// 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);
IF_FAIL_RETURN_TAG(ret, false, _E, "Failed to update last cpu log");
__removeExpiredLog();
+ __needSync = false;
return true;
}
// 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();