ctx::AppUseMonitor::AppUseMonitor() :
__signalId(-1),
__lastCleanupTime(0),
- __dbusWatcher(DBusType::SYSTEM)
+ __dbusWatcher(DBusType::SYSTEM),
+ __timeDiff(0)
{
__startLogging();
+ vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, __timeChangeCb, this);
}
ctx::AppUseMonitor::~AppUseMonitor()
{
__stopLogging();
+ vconf_ignore_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, __timeChangeCb);
}
bool ctx::AppUseMonitor::__startLogging()
} else if (STR_EQ(status, "bg")) {
__finishRecord(appId);
__removeExpired();
+ __timeDiff = 0;
}
}
std::stringstream query;
query <<
"UPDATE " APP_TABLE_USAGE_LOG \
- " SET " KEY_DURATION " = strftime('%s', 'now') - " KEY_UNIV_TIME \
+ " SET " KEY_DURATION " = strftime('%s', 'now') - (" KEY_UNIV_TIME " + " << __timeDiff << ")" \
" WHERE " KEY_COL_ROW_ID " = (" \
"SELECT MAX(" KEY_COL_ROW_ID ") FROM " APP_TABLE_USAGE_LOG \
" WHERE " KEY_APP_ID " = '" << appId << "'" \
KEY_UNIV_TIME " < strftime('%s', 'now') - " << LOG_RETENTION_PERIOD;
__dbManager.execute(0, query.str().c_str(), NULL);
}
+
+void ctx::AppUseMonitor::__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.");
+
+ AppUseMonitor* instance = static_cast<AppUseMonitor*>(userData);
+ instance->__timeDiff = instance->__timeDiff + timeDiff;
+}
}
}
+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.");
+
+ BatteryMonitor* instance = static_cast<BatteryMonitor*>(userData);
+ __needSync = true;
+ instance->__lastFullTime = instance->__lastFullTime + timeDiff;
+ instance->__lastHeartAccessTime = instance->__lastHeartAccessTime + timeDiff;
+
+ bool ret = instance->__updateLastInfo();
+ IF_FAIL_VOID_TAG(ret, _E, "Failed to update last reset time and last percent time");
+
+ __instance->__modifyLastCpuUsage(timeDiff);
+}
+
gboolean BatteryMonitor::__timeoutCb(gpointer data)
{
BatteryMonitor* instance = static_cast<BatteryMonitor*>(data);
int error = device_add_callback(DEVICE_CALLBACK_BATTERY_CHARGING, __chargerChangeCb, this);
IF_FAIL_RETURN_TAG(error == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED, _E, "Failed to set battery charging change cb");
+ error = vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, __timeChangeCb, this);
+ IF_FAIL_RETURN_TAG(error == VCONF_OK, ERR_OPERATION_FAILED, _E, "Failed to set time changed cb");
+
_D("Start timer to request HEART data");
g_timeout_add(HEART_DB_QUERY_INTERVAL, __timeoutCb, this);
int error = device_remove_callback(DEVICE_CALLBACK_BATTERY_CHARGING, __chargerChangeCb);
IF_FAIL_RETURN_TAG(error == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED, _E, "Failed to remove callback for charger status");
+ error = vconf_ignore_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, __timeChangeCb);
+ IF_FAIL_RETURN_TAG(error == VCONF_OK, ERR_OPERATION_FAILED, _E, "Failed to remove callback for time changed");
+
return ERR_NONE;
}
bool BatteryMonitor::__processBatteryUsage()
{
- if (__lastHeartAccessTime > CURRENT_TIME) {
- __lastHeartAccessTime = CURRENT_TIME - DEFAULT_TIME_DIFF;
- __lastFullTime = CURRENT_TIME - DEFAULT_TIME_DIFF;
- __updateLastInfo();
- __dbMgr.executeSync("DELETE FROM " BATTERY_LAST_CPU_USAGE_TABLE, NULL);
- }
-
// Read from heart cpu table
bool ret = __heartReader->dbOpen();
IF_FAIL_RETURN_TAG(ret, true, _E, "Failed to open heart db");
bool BatteryMonitor::__updateLastCpuUsageLog(CpuUsageMap& usage)
{
- _D("Delete all rows from app last times table");
+ _D("Delete all rows from last cpu usage table");
__dbMgr.executeSync("DELETE FROM " BATTERY_LAST_CPU_USAGE_TABLE, NULL);
IF_FAIL_RETURN_TAG(usage.size(), true, _W, "No data");
__processBatteryUsage();
}
+
+void BatteryMonitor::__modifyLastCpuUsage(int timeDiff)
+{
+ char *query = sqlite3_mprintf("UPDATE Temp_LastCpuUsagePerApp SET Timestamp = Timestamp + (%d)", timeDiff);
+ __dbMgr.executeSync(query, NULL);
+ sqlite3_free(query);
+
+ _D("Modified timestamp of LastCpuUsage");
+}
#define _CONTEXT_BATTERY_MONITOR_H_
#include <device/callback.h>
+#include <vconf.h>
#include <DatabaseManager.h>
#include "BatteryUsageAnalyzer.h"
#include "HeartDbReader.h"
bool __updateLastCpuUsageLog(CpuUsageMap& usage);
bool __getLastCpuUsageTable(CpuUsageMap* lastCpuUsage);
void __removeExpiredLog();
+ void __modifyLastCpuUsage(int timeDiff);
static void __chargerChangeCb(device_callback_e type, void* value, void* userData);
+ static void __timeChangeCb(keynode_t* node, void* userData);
static int __timeoutCb(void* data);
static BatteryMonitor* __instance;