From a94936b68c6f947626fb8142d590ad2689e087f3 Mon Sep 17 00:00:00 2001 From: Somin Kim Date: Mon, 26 Dec 2016 16:22:42 +0900 Subject: [PATCH] [battery-stats] Changed heart sync policy (after rebooting, fully charged ...) & Version 0.9.12 Change-Id: I72136a878c40bcd30942c218bc83c32b4a54e04c Signed-off-by: Somin Kim --- packaging/context-provider.spec | 2 +- src/battery-stats/BatteryMonitor.cpp | 22 ++++++++++++---------- src/battery-stats/BatteryMonitor.h | 1 - 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packaging/context-provider.spec b/packaging/context-provider.spec index d973523..7a22304 100644 --- a/packaging/context-provider.spec +++ b/packaging/context-provider.spec @@ -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 diff --git a/src/battery-stats/BatteryMonitor.cpp b/src/battery-stats/BatteryMonitor.cpp index 4c34e8c..3e1715f 100644 --- a/src/battery-stats/BatteryMonitor.cpp +++ b/src/battery-stats/BatteryMonitor.cpp @@ -30,10 +30,10 @@ 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 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(); diff --git a/src/battery-stats/BatteryMonitor.h b/src/battery-stats/BatteryMonitor.h index 4127b09..f87dc3b 100644 --- a/src/battery-stats/BatteryMonitor.h +++ b/src/battery-stats/BatteryMonitor.h @@ -52,7 +52,6 @@ namespace ctx { static int __timeoutCb(void* data); static BatteryMonitor* __instance; - int __bootingTime; int __lastFullTime; int __lastHeartAccessTime; -- 2.34.1