void bm_engine_set_req_flag_handle(bm_plugin_id_e req_plugin_id, bool value);
+/* Get functions for fixed duration queries used in % */
int bm_engine_get_usage_by_app_id_for_resource_id(const gchar *app_id, gint resource_id, gint duration, int *b_usage);
int bm_engine_get_total_usage_by_app_id(const gchar *app_id, gint duration, int *b_usage);
int bm_engine_get_all_resource_usage(const gchar *app_id, gint duration, bm_total_consumption_h data);
+/* Get functions for custome interval queries used in mAs */
+int bm_engine_get_mah_usage_by_app_id_for_resource_id_ci(const gchar* app_id, gint resource_id, gint64 start_time, gint64 end_time, double* battery_usage);
+
+int bm_engine_get_total_mah_usage_by_app_id_ci(const gchar* app_id, gint64 start_time, gint64 end_time, double* battery_usage);
+
+int bm_engine_get_total_mah_usage_by_resource_id_ci(gint resource_id, gint64 start_time, gint64 end_time, double* battery_usage);
+
+int bm_engine_get_all_resource_usage_handle_ci(const gchar* app_id, gint64 start_time, gint64 end_time, bm_total_consumption_h battery_data);
+
/* power consumption calculation & Db commit functions*/
int bm_ble_calc_power_and_commit(bm_bluetooth_st *handle, bool mode);
gboolean bm_get_usage_by_app_id_for_resource_id(BatteryMonitor *obj, GDBusMethodInvocation *invocation,
- const gchar *app_id, gint resource_id, gint duration, gint uid);
+ const gchar *app_id, gint resource_id, gint duration, gint uid);
+
+gboolean bm_get_mah_usage_by_app_id_for_resource_id_custom_interval(BatteryMonitor *obj, GDBusMethodInvocation *invocation,
+ const gchar *app_id, gint resource_id, gint64 start_time, gint64 end_time, gint uid);
gboolean bm_get_total_usage_by_app_id(BatteryMonitor *obj, GDBusMethodInvocation *invocation, const gchar *app_id,
- gint duration, gint uid);
+ gint duration, gint uid);
+
+gboolean bm_get_total_mah_usage_by_app_id_custom_interval(BatteryMonitor *obj, GDBusMethodInvocation *invocation,
+ const gchar *app_id, gint64 start_time, gint64 end_time, gint uid);
gboolean bm_get_total_usage_by_resource_id(BatteryMonitor *obj, GDBusMethodInvocation *invocation, gint resource_id,
- gint duration, gint uid);
+ gint duration, gint uid);
+
+gboolean bm_get_total_mah_usage_by_resource_id_custom_interval(BatteryMonitor *obj, GDBusMethodInvocation *invocation,
+ gint resource_id, gint64 start_time, gint64 end_time, gint uid);
gboolean bm_get_all_resource_usage(BatteryMonitor *obj, GDBusMethodInvocation *invocation, const gchar *app_id,
- gint duration, gint uid);
+ gint duration, gint uid);
+gboolean bm_get_usage_handle_by_app_id_for_all_resource_id_custom_interval(BatteryMonitor *obj, GDBusMethodInvocation *invocation,
+ const gchar *app_id, gint64 start_time, gint64 end_time, gint uid);
#ifdef __cplusplus
}
appid_usage_s *bm_server_query_app_usage_by_appid(const char *app_id, int period_type, int *error_code);
+appid_usage_s *bm_server_query_app_usage_by_appid_ci(const char *app_id, long long s_time, long long e_time, int *error_code);
+
int bm_server_app_usage_insert_to_db(appid_usage_s *bm_app_type);
resourceid_usage_s *bm_server_query_resource_usage_resourceid(const char *resource_id, int period_type, int *error_code);
+resourceid_usage_s *bm_server_query_resource_usage_resourceid_ci(const char *resource_id, long long s_time, long long e_time, int *error_code);
+
int bm_server_resource_usage_insert_to_db(resourceid_usage_s *bm_resource_type);
int bm_server_battery_dump_insert_to_db(void* str_data, int type);
int bm_calc_individual_consumption(int resource_val, int total_consumption);
+double bm_calc_individual_mah_consumption(int resource_val, double mah_c);
+
GVariant* bm_marshal_serialized_data(const bm_total_consumption_h data);
const char *bm_get_resource_id_string(gint resource_id);
<arg type="i" name="uid" direction="in" />
<arg type="i" name="battery_usage" direction="out" />
</method>
+ <method name="get_mah_usage_by_app_id_for_resource_id_custom_interval">
+ <arg type="s" name="app_id" direction="in" />
+ <arg type="i" name="resource_id" direction="in" />
+ <arg type="x" name="start_time" direction="in" />
+ <arg type="x" name="end_time" direction="in" />
+ <arg type="i" name="uid" direction="in" />
+ <arg type="d" name="battery_usage" direction="out" />
+ </method>
<method name="get_total_usage_by_app_id">
<arg type="s" name="app_id" direction="in" />
<arg type="i" name="duration" direction="in" />
<arg type="i" name="uid" direction="in" />
<arg type="i" name="battery_usage" direction="out" />
</method>
+ <method name="get_total_mah_usage_by_app_id_custom_interval">
+ <arg type="s" name="app_id" direction="in" />
+ <arg type="x" name="start_time" direction="in" />
+ <arg type="x" name="end_time" direction="in" />
+ <arg type="i" name="uid" direction="in" />
+ <arg type="d" name="battery_usage" direction="out" />
+ </method>
<method name="get_total_usage_by_resource_id">
<arg type="i" name="resource_id" direction="in" />
<arg type="i" name="duration" direction="in" />
<arg type="i" name="uid" direction="in" />
<arg type="i" name="battery_usage" direction="out" />
</method>
+ <method name="get_total_mah_usage_by_resource_id_custom_interval">
+ <arg type="i" name="resource_id" direction="in" />
+ <arg type="x" name="start_time" direction="in" />
+ <arg type="x" name="end_time" direction="in" />
+ <arg type="i" name="uid" direction="in" />
+ <arg type="d" name="battery_usage" direction="out" />
+ </method>
<method name="get_all_resource_usage">
<arg type="s" name="app_id" direction="in" />
<arg type="i" name="duration" direction="in" />
<arg type="i" name="uid" direction="in" />
<arg type="a{sv}" name="battery_data" direction="out" />
</method>
+ <method name="get_usage_handle_by_app_id_for_all_resource_id_custom_interval">
+ <arg type="s" name="app_id" direction="in" />
+ <arg type="x" name="start_time" direction="in" />
+ <arg type="x" name="end_time" direction="in" />
+ <arg type="i" name="uid" direction="in" />
+ <arg type="a{sv}" name="battery_data" direction="out" />
+ </method>
</interface>
</node>
-
<check send_destination="org.tizen.battery.monitor" send_interface="org.tizen.battery.monitor"
send_member="get_usage_by_app_id_for_resource_id" privilege="http://tizen.org/privilege/systemmonitor"/>
<check send_destination="org.tizen.battery.monitor" send_interface="org.tizen.battery.monitor"
+ send_member="get_mah_usage_by_app_id_for_resource_id_custom_interval" privilege="http://tizen.org/privilege/systemmonitor"/>
+ <check send_destination="org.tizen.battery.monitor" send_interface="org.tizen.battery.monitor"
send_member="get_total_usage_by_app_id" privilege="http://tizen.org/privilege/systemmonitor"/>
<check send_destination="org.tizen.battery.monitor" send_interface="org.tizen.battery.monitor"
+ send_member="get_total_mah_usage_by_app_id_custom_interval" privilege="http://tizen.org/privilege/systemmonitor"/>
+ <check send_destination="org.tizen.battery.monitor" send_interface="org.tizen.battery.monitor"
send_member="get_total_usage_by_resource_id" privilege="http://tizen.org/privilege/systemmonitor"/>
<check send_destination="org.tizen.battery.monitor" send_interface="org.tizen.battery.monitor"
+ send_member="get_total_mah_usage_by_resource_id_custom_interval" privilege="http://tizen.org/privilege/systemmonitor"/>
+ <check send_destination="org.tizen.battery.monitor" send_interface="org.tizen.battery.monitor"
send_member="get_all_resource_usage" privilege="http://tizen.org/privilege/systemmonitor"/>
+ <check send_destination="org.tizen.battery.monitor" send_interface="org.tizen.battery.monitor"
+ send_member="get_usage_handle_by_app_id_for_all_resource_id_custom_interval" privilege="http://tizen.org/privilege/systemmonitor"/>
</policy>
</busconfig>
bm_feature_data_h bm_data_handle = NULL;
GHashTable *gl_hash = NULL;
static struct bm_req_feature_data_handle_flag_s *bm_req_flag_h = NULL;
-const int mahp = 3600;
+const double cmah = 3600;
int battery_capacity = 500;
int gtimeo_id[2];
return BATTERY_MONITOR_ERROR_NONE;
}
+int bm_engine_get_mah_usage_by_app_id_for_resource_id_ci(const gchar* app_id, gint resource_id, gint64 start_time, gint64 end_time, double *battery_usage)
+{
+ ENTER;
+ BM_CHECK_INPUT_PARAM(app_id);
+ BM_RETURN_VAL((resource_id < BM_PLUGIN_ID_MAX), {},
+ BATTERY_MONITOR_ERROR_INVALID_PARAMETER, "invalid resource-id param");
+ _DBG("usage requested - app-id[%s], resource_id[%d], start_time [%lld] end_time[%lld]",
+ app_id, resource_id, start_time, end_time);
+
+ int error = BATTERY_MONITOR_ERROR_NONE;
+ appid_usage_s *app_usage = bm_server_query_app_usage_by_appid_ci(app_id, start_time, end_time, &error);
+ if (!app_usage) {
+ _ERR("battery usage data for app_id(%s) is not available", app_id);
+ return BATTERY_MONITOR_ERROR_INTERNAL;
+ }
+ if (error != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("error reported, error = %d", error);
+ return BATTERY_MONITOR_ERROR_INTERNAL;
+ }
+
+ if (resource_id == BM_PLUGIN_ID_BLE)
+ *battery_usage = bm_calc_individual_mah_consumption(app_usage->rId_ble, cmah);
+ else if (resource_id == BM_PLUGIN_ID_WIFI)
+ *battery_usage = bm_calc_individual_mah_consumption(app_usage->rId_wifi, cmah);
+ else if (resource_id == BM_PLUGIN_ID_CPU)
+ *battery_usage = bm_calc_individual_mah_consumption(app_usage->rId_cpu, cmah);
+ else if (resource_id == BM_PLUGIN_ID_DISPLAY)
+ *battery_usage = bm_calc_individual_mah_consumption(app_usage->rId_display, cmah);
+ else if (resource_id == BM_PLUGIN_ID_DEVICE_NETWORK)
+ *battery_usage = bm_calc_individual_mah_consumption(app_usage->rId_device_network, cmah);
+#ifdef DISABLE_FEATURE_DATA_FROM_GPS_HRM_PLUGIN
+ else if (resource_id == BM_PLUGIN_ID_GPS_SENSOR)
+ *battery_usage = bm_calc_individual_mah_consumption(app_usage->rId_gps, cmah);
+ else if (resource_id == BM_PLUGIN_ID_HRM_SENSOR)
+ *battery_usage = bm_calc_individual_mah_consumption(app_usage->rId_hrm, cmah);
+ else
+ *battery_usage = -1;
+#endif /* DISABLE_FEATURE_DATA_FROM_GPS_HRM_PLUGIN */
+
+ bm_appid_usage_free(app_usage);
+
+ EXIT;
+ return BATTERY_MONITOR_ERROR_NONE;
+}
+
int bm_engine_get_total_usage_by_app_id(const gchar *app_id, gint duration, int *b_usage)
{
ENTER;
return BATTERY_MONITOR_ERROR_NONE;
}
+int bm_engine_get_total_mah_usage_by_app_id_ci(const gchar* app_id, gint64 start_time, gint64 end_time, double *battery_usage)
+{
+ ENTER;
+
+ BM_CHECK_INPUT_PARAM(app_id);
+
+ _DBG("usage requested - app-id[%s], start_time [%lld] end_time[%lld]",
+ app_id, start_time, end_time);
+ int error = BATTERY_MONITOR_ERROR_NONE;
+ appid_usage_s *app_usage = bm_server_query_app_usage_by_appid_ci(app_id, start_time, end_time, &error);
+ if (!app_usage) {
+ _ERR("battery usage data for app_id(%s) is not available", app_id);
+ return BATTERY_MONITOR_ERROR_INTERNAL;
+ }
+ if (error != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("error reported, error = %d", error);
+ return BATTERY_MONITOR_ERROR_INTERNAL;
+ }
+ int total_consumption = (app_usage->rId_ble + app_usage->rId_wifi + app_usage->rId_cpu + \
+ app_usage->rId_display + app_usage->rId_device_network);
+#ifdef DISABLE_FEATURE_DATA_FROM_GPS_HRM_PLUGIN
+ total_consumption += (app_usage->rId_gps + app_usage->rId_hrm);
+#endif /* DISABLE_FEATURE_DATA_FROM_GPS_HRM_PLUGIN */
+ *battery_usage = bm_calc_individual_mah_consumption(total_consumption, cmah);
+ _INFO("total battery consumption is [%lf] for app-id[%s]", *battery_usage, app_id);
+
+ bm_appid_usage_free(app_usage);
+ EXIT;
+ return BATTERY_MONITOR_ERROR_NONE;
+}
+
int bm_engine_get_total_usage_by_resource_id(gint resource_id, gint duration, int *b_usage)
{
ENTER;
return BATTERY_MONITOR_ERROR_NONE;
}
+int bm_engine_get_total_mah_usage_by_resource_id_ci(gint resource_id, gint64 start_time, gint64 end_time, double *battery_usage)
+{
+ ENTER;
+
+ BM_RETURN_VAL((resource_id < BM_PLUGIN_ID_MAX), {},
+ BATTERY_MONITOR_ERROR_INVALID_PARAMETER, "invalid resource-id");
+ _DBG("usage requested - resource_id[%d], start_time [%lld] end_time[%lld]",
+ resource_id, start_time, end_time);
+
+ int error = BATTERY_MONITOR_ERROR_NONE;
+ const char *resource_id_str = NULL;
+ resource_id_str = bm_get_resource_id_string(resource_id);
+ if (g_strcmp0(resource_id_str, "UNKNOWN RESOURCE-ID") == 0) {
+ _ERR("invalid resource-id");
+ return BATTERY_MONITOR_ERROR_INTERNAL;
+ }
+ _INFO("resource string - [%s]", resource_id_str);
+ resourceid_usage_s *resource_usage = bm_server_query_resource_usage_resourceid_ci(resource_id_str, start_time, end_time, &error);
+ if (!resource_usage) {
+ _ERR("battery usage data for resource-id(%s) is not available", resource_id_str);
+ return BATTERY_MONITOR_ERROR_INTERNAL;
+ }
+ if (error != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("error reported, error = %d", error);
+ return BATTERY_MONITOR_ERROR_INTERNAL;
+ }
+ *battery_usage = bm_calc_individual_mah_consumption(resource_usage->usage, cmah);
+ bm_resourceid_usage_free(resource_usage);
+
+ EXIT;
+ return BATTERY_MONITOR_ERROR_NONE;
+}
+
int bm_engine_get_all_resource_usage(const gchar *app_id, gint duration, bm_total_consumption_h data)
{
ENTER;
int error = BATTERY_MONITOR_ERROR_NONE;
appid_usage_s *app_usage = bm_server_query_app_usage_by_appid(app_id, duration, &error);
-
if (!app_usage) {
_ERR("battery usage data for app_id(%s) is not available", app_id);
return BATTERY_MONITOR_ERROR_INTERNAL;
}
-
if (error != BATTERY_MONITOR_ERROR_NONE) {
_ERR("error reported, error = %d", error);
return BATTERY_MONITOR_ERROR_INTERNAL;
return BATTERY_MONITOR_ERROR_NONE;
}
+int bm_engine_get_all_resource_usage_handle_ci(const gchar* app_id, gint64 start_time, gint64 end_time, bm_total_consumption_h battery_data)
+{
+ ENTER;
+ BM_CHECK_INPUT_PARAM(app_id);
+ BM_CHECK_INPUT_PARAM(battery_data);
+ _DBG("usage requested - app-id[%s], start_time[%lld] end_time[%lld]", app_id, start_time, end_time);
+ int error = BATTERY_MONITOR_ERROR_NONE;
+ appid_usage_s *app_usage = bm_server_query_app_usage_by_appid_ci(app_id, start_time, end_time, &error);
+ if (!app_usage) {
+ _ERR("battery usage data for app_id(%s) is not available", app_id);
+ return BATTERY_MONITOR_ERROR_INTERNAL;
+ }
+ if (error != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("error reported, error = %d", error);
+ return BATTERY_MONITOR_ERROR_INTERNAL;
+ }
+ battery_data->ble_val = app_usage->rId_ble; battery_data->wifi_val = app_usage->rId_wifi;
+ battery_data->cpu_val = app_usage->rId_cpu; battery_data->dp_val = app_usage->rId_display;
+ battery_data->dn_val = app_usage->rId_device_network;
+#ifdef DISABLE_FEATURE_DATA_FROM_GPS_HRM_PLUGIN
+ battery_data->gps_val = app_usage->rId_gps; battery_data->hrm_val = app_usage->rId_hrm;
+ battery_data->bat_val = app_usage->rId_battery;
+#endif /* DISABLE_FEATURE_DATA_FROM_GPS_HRM_PLUGIN */
+
+ bm_appid_usage_free(app_usage);
+
+ EXIT;
+ return BATTERY_MONITOR_ERROR_NONE;
+ EXIT;
+}
+
void bm_engine_set_req_flag_handle(bm_plugin_id_e req_plugin_id, bool value)
{
ENTER;
_ERR("memory allocation failed");
return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
}
- gbst_st->time_s = ret_time; gbst_st->off_time = BATTERY_MONITOR_GET_DATA_JOB_PERIOD;
+ gbst_st->time_s = ret_time; gbst_st->off_time = BATTERY_MONITOR_GET_DATA_JOB_PERIOD/1000;
gbst_st->off_time -= sesTime; gbst_st->low_time = 0/*(sesTime - (scTime + conTime))*/;
gbst_st->med_time = 0/*scTime*/; gbst_st->high_time = 0/*conTime*/;
ret_val = bm_server_battery_dump_insert_to_db(gbst_st, 6);
/* creating hash-map with (key, value) = (app-id, data) */
GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, bm_data_free, bm_atm_st1_free);
- long int uTime = 0, sTime = 0;
+ long int uTime = 0, sTime = 0;
double onTime = 0;
/* iterating over list for data accumulation */
for (cpu_data_iterator = handle->cpu_data_list; cpu_data_iterator; cpu_data_iterator = cpu_data_iterator->next) {
ret_val = bm_get_battery_power_params(&battery_capacity);
if (ret_val != BATTERY_MONITOR_ERROR_NONE)
_ERR("unable ro read battery capacity");
- battery_capacity *= mahp; //Battery Capacity in mAs
+ battery_capacity *= cmah; //Battery Capacity in mAs
EXIT;
return ret_val;
}
gboolean
+bm_get_mah_usage_by_app_id_for_resource_id_custom_interval(BatteryMonitor *obj, GDBusMethodInvocation *invocation, const gchar *app_id,
+ gint resource_id, gint64 start_time, gint64 end_time, gint uid)
+{
+ ENTER;
+
+ _INFO("app_id [%s], resource_id [%d], start_time [%lld] end_time [%lld]", app_id, resource_id, start_time, end_time);
+
+ if (!app_id || (resource_id >= BM_PLUGIN_ID_MAX)) {
+ _ERR("invalid function param");
+ return false;
+ }
+
+ int ret_val = bm_check_privilege_battery(invocation);
+ if (ret_val != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("privilege check failed, ret-val - %d", ret_val);
+ goto RETURN;
+ }
+
+ double battery_usage = 0;
+ ret_val = bm_engine_get_mah_usage_by_app_id_for_resource_id_ci(app_id, resource_id, start_time, end_time, &battery_usage);
+ if (ret_val != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("failed to get battery usage");
+ goto RETURN;
+ }
+// battery_usage = 22.50;
+
+ _INFO("battery usage - %lf", battery_usage);
+
+RETURN:
+ if (ret_val != BATTERY_MONITOR_ERROR_NONE) {
+ GError* error = g_error_new(bm_error_quark(), ret_val, "info not available");
+ g_dbus_method_invocation_return_gerror(invocation, error);
+ g_error_free(error);
+ } else {
+ battery_monitor_complete_get_mah_usage_by_app_id_for_resource_id_custom_interval(obj, invocation, battery_usage);
+ }
+
+ EXIT;
+ return true;
+}
+
+gboolean
bm_get_total_usage_by_app_id(BatteryMonitor *obj, GDBusMethodInvocation *invocation,
const gchar *app_id, gint duration, gint uid)
{
}
gboolean
+bm_get_total_mah_usage_by_app_id_custom_interval(BatteryMonitor *obj, GDBusMethodInvocation *invocation,
+ const gchar *app_id, gint64 start_time, gint64 end_time, gint uid)
+{
+ ENTER;
+
+ _INFO("app_id(%s), start_time (%lld), end_time (%lld)", app_id, start_time, end_time);
+
+ if (!app_id) {
+ _ERR("invalid function param");
+ return false;
+ }
+
+ int ret_val = bm_check_privilege_battery(invocation);
+ if (ret_val != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("privilege check failed, ret-val - %d", ret_val);
+ goto RETURN;
+ }
+
+ double battery_usage = 0;
+ ret_val = bm_engine_get_total_mah_usage_by_app_id_ci(app_id, start_time, end_time, &battery_usage);
+ if (ret_val != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("failed to get battery usage");
+ goto RETURN;
+ }
+// battery_usage = 90.35;
+
+ _DBG("Battery Usage %lf ", battery_usage);
+
+RETURN:
+ if (ret_val != BATTERY_MONITOR_ERROR_NONE) {
+ GError* error = g_error_new(bm_error_quark(), ret_val, "info not available");
+ g_dbus_method_invocation_return_gerror(invocation, error);
+ g_error_free(error);
+ } else {
+ battery_monitor_complete_get_total_mah_usage_by_app_id_custom_interval(obj, invocation, battery_usage);
+ }
+
+ EXIT;
+ return true;
+}
+
+gboolean
bm_get_total_usage_by_resource_id(BatteryMonitor *obj, GDBusMethodInvocation *invocation,
gint resource_id, gint duration, gint uid)
{
}
gboolean
+bm_get_total_mah_usage_by_resource_id_custom_interval(BatteryMonitor *obj, GDBusMethodInvocation *invocation,
+ gint resource_id, gint64 start_time, gint64 end_time, gint uid)
+{
+ ENTER;
+
+ _INFO("resource_id [%d], start_time [%lld] end_time [%lld]", resource_id, start_time, end_time);
+
+ if (resource_id >= BM_PLUGIN_ID_MAX) {
+ _ERR("invalid function param");
+ return false;
+ }
+
+ int ret_val = bm_check_privilege_battery(invocation);
+ if (ret_val != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("privilege check failed, ret-val - %d", ret_val);
+ goto RETURN;
+ }
+
+ double battery_usage = 0;
+ ret_val = bm_engine_get_total_mah_usage_by_resource_id_ci(resource_id, start_time, end_time, &battery_usage);
+ if (ret_val != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("failed to get battery usage");
+ goto RETURN;
+ }
+// battery_usage = 30.55;
+
+ _INFO("battery usage - %lf", battery_usage);
+
+RETURN:
+ if (ret_val != BATTERY_MONITOR_ERROR_NONE) {
+ GError* error = g_error_new(bm_error_quark(), ret_val, "info not available");
+ g_dbus_method_invocation_return_gerror(invocation, error);
+ g_error_free(error);
+ } else {
+ battery_monitor_complete_get_total_mah_usage_by_resource_id_custom_interval(obj, invocation, battery_usage);
+ }
+
+ EXIT;
+ return true;
+}
+
+gboolean
bm_get_all_resource_usage(BatteryMonitor *obj, GDBusMethodInvocation *invocation,
const gchar *app_id, gint duration, gint uid)
{
return true;
}
+gboolean
+bm_get_usage_handle_by_app_id_for_all_resource_id_custom_interval(BatteryMonitor *obj, GDBusMethodInvocation *invocation,
+ const gchar *app_id, gint64 start_time, gint64 end_time, gint uid)
+{
+ ENTER;
+
+ _INFO("app_id [%s], start_time [%lld] end_time [%lld]", app_id, start_time, end_time);
+
+ if (!app_id) {
+ _ERR("invalid function param");
+ return false;
+ }
+
+ bm_total_consumption_h battery_data = NULL;
+ int ret_val = bm_check_privilege_battery(invocation);
+ if (ret_val != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("privilege check failed, ret-val - %d", ret_val);
+ goto RETURN;
+ }
+
+ GVariant *battery_variant = NULL;
+ // Need to replace with double type structures
+ battery_data = (bm_total_consumption_h)calloc(1, sizeof(struct battery_total_consumption_s));
+ if (battery_data == NULL) {
+ ret_val = BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
+ _ERR("memory allocation failed");
+ goto RETURN;
+ }
+
+ _INFO("before request to engine");
+ ret_val = bm_engine_get_all_resource_usage_handle_ci(app_id, start_time, end_time, battery_data);
+ if (ret_val != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("failed to get battery data");
+ goto RETURN;
+ }
+ _INFO("after request to engine");
+
+ _INFO("data received in mAs - bt[%d], wifi[%d], cpu[%d], dp[%d], dn[%d], bat[%d]",
+ battery_data->ble_val, battery_data->wifi_val, battery_data->cpu_val, battery_data->dp_val,
+ battery_data->dn_val, battery_data->bat_val);
+
+ if (ret_val == BATTERY_MONITOR_ERROR_NONE)
+ battery_variant = bm_marshal_serialized_data(battery_data);
+
+RETURN:
+ if (ret_val != BATTERY_MONITOR_ERROR_NONE) {
+ GError* error = g_error_new(bm_error_quark(), ret_val, "info not available");
+ g_dbus_method_invocation_return_gerror(invocation, error);
+ g_error_free(error);
+ } else {
+ battery_monitor_complete_get_usage_handle_by_app_id_for_all_resource_id_custom_interval(obj, invocation, battery_variant);
+ }
+
+ BM_FREE(battery_data);
+
+ EXIT;
+ return true;
+}
+
static int bm_set_dbus_interface_handles(BatteryMonitorIface *iface)
{
ENTER;
iface->handle_get_usage_by_app_id_for_resource_id = &bm_get_usage_by_app_id_for_resource_id;
+ iface->handle_get_mah_usage_by_app_id_for_resource_id_custom_interval = &bm_get_mah_usage_by_app_id_for_resource_id_custom_interval;
+
iface->handle_get_total_usage_by_app_id = &bm_get_total_usage_by_app_id;
+ iface->handle_get_total_mah_usage_by_app_id_custom_interval = &bm_get_total_mah_usage_by_app_id_custom_interval;
+
iface->handle_get_total_usage_by_resource_id = &bm_get_total_usage_by_resource_id;
+ iface->handle_get_total_mah_usage_by_resource_id_custom_interval = &bm_get_total_mah_usage_by_resource_id_custom_interval;
+
iface->handle_get_all_resource_usage = &bm_get_all_resource_usage;
+ iface->handle_get_usage_handle_by_app_id_for_all_resource_id_custom_interval = &bm_get_usage_handle_by_app_id_for_all_resource_id_custom_interval;
+
EXIT;
return BATTERY_MONITOR_ERROR_NONE;
}
return NULL;
}
+static appid_usage_s* bm_query_usage_by_appid_ci(sqlite3 *bm_db_handle, const char *app_id, long long s_time, long long e_time, int *error_code)
+{
+ ENTER;
+
+ bm_stmt hstmt = NULL;
+ int rc = 0;
+ *error_code = BATTERY_MONITOR_ERROR_NONE;
+
+ long int s_t = (long)s_time;
+ long int e_t = (long)e_time;
+ char query[BATTERY_MONITOR_SQL_LEN_MAX] = {0, };
+ BM_MEMSET(query, 0x00, BATTERY_MONITOR_SQL_LEN_MAX);
+#ifdef DISABLE_FEATURE_DATA_FROM_GPS_HRM_PLUGIN
+ BM_SNPRINTF(query, sizeof(query), "SELECT AppId, sum(rId_ble), sum(rId_wifi), sum(rId_cpu), \
+ sum(rId_display), sum(rId_device_network), sum(rId_gps), sum(rId_hrm) FROM %s WHERE \
+ AppId = '%s' AND log_time > %ld AND log_time < %ld", BATTERY_MONITOR_APP_ID_USAGE_TABLE,
+ app_id, s_t, e_t);
+#else
+ BM_SNPRINTF(query, sizeof(query), "SELECT AppId, sum(rId_ble), sum(rId_wifi), sum(rId_cpu), \
+ sum(rId_display), sum(rId_device_network) FROM %s WHERE AppId = '%s' AND \
+ log_time > %ld AND log_time < %ld", BATTERY_MONITOR_APP_ID_USAGE_TABLE, app_id, s_t, e_t);
+#endif
+ hstmt = bm_prepare_query(bm_db_handle, query);
+ if (bm_db_err_code(bm_db_handle) == SQLITE_PERM) {
+ _ERR("Access failed(%s)", bm_db_err_msg(bm_db_handle));
+ *error_code = BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
+ return NULL;
+ }
+
+ appid_usage_s *bm_app_type = NULL;
+ rc = bm_query_step(hstmt);
+ BM_CATCH_ERROR_P(rc == SQLITE_ROW, {}, BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND,
+ ("The record isn't found.(%s)\n", app_id));
+ bm_app_type = (appid_usage_s *)calloc(1, sizeof(appid_usage_s));
+ if (bm_app_type == NULL) {
+ _ERR("memory allocation failed");
+ if (hstmt != NULL) {
+ rc = bm_query_finalize(hstmt);
+ BM_RETURN_VAL((rc == BATTERY_MONITOR_ERROR_NONE), { *error_code = rc; },
+ NULL, ("finalize error"));
+ hstmt = NULL;
+ }
+ *error_code = BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
+ return NULL;
+ }
+ bm_convert_column_to_appid_usage(hstmt, bm_app_type);
+ rc = bm_query_finalize(hstmt);
+ BM_CATCH_ERROR_P((rc == BATTERY_MONITOR_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
+ *error_code = BATTERY_MONITOR_ERROR_NONE;
+
+CATCH:
+ if (hstmt != NULL) {
+ rc = bm_query_finalize(hstmt);
+ if (rc != BATTERY_MONITOR_ERROR_NONE) {
+ *error_code = rc;
+ _ERR("finalize error");
+ }
+ hstmt = NULL;
+ }
+ if ((*error_code != BATTERY_MONITOR_ERROR_NONE) && bm_app_type) {
+ BM_FREE(bm_app_type);
+ bm_app_type = NULL;
+ }
+ if ((*error_code == BATTERY_MONITOR_ERROR_NONE) && bm_app_type != NULL) {
+ _INFO("Returning appid usage");
+ return bm_app_type;
+ }
+
+ EXIT;
+ return NULL;
+}
+
static int bm_battery_stat_query_from_db(sqlite3 *bm_db_handle, void* str_data, int type, long int duration)
{
ENTER;
return NULL;
}
+static resourceid_usage_s* bm_query_usage_by_resourceid_ci(sqlite3 *bm_db_handle, const char *resource_id, long long s_time, long long e_time, int *error_code)
+{
+ ENTER;
+ bm_stmt hstmt = NULL;
+ int rc = 0;
+ *error_code = BATTERY_MONITOR_ERROR_NONE;
+ long int s_t = (long)s_time;
+ long int e_t = (long)e_time;
+ char query[BATTERY_MONITOR_SQL_LEN_MAX] = {0, };
+ BM_MEMSET(query, 0x00, BATTERY_MONITOR_SQL_LEN_MAX);
+ BM_SNPRINTF(query, sizeof(query), "SELECT ResourceId, sum(usage) FROM %s WHERE ResourceId = '%s' \
+ AND log_time > %ld AND log_time < %ld", BATTERY_MONITOR_RESOURCE_ID_USAGE_TABLE, resource_id, s_t, e_t);
+
+ hstmt = bm_prepare_query(bm_db_handle, query);
+ if (bm_db_err_code(bm_db_handle) == SQLITE_PERM) {
+ _ERR("Access failed(%s)", bm_db_err_msg(bm_db_handle));
+ *error_code = BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
+ return NULL;
+ }
+ resourceid_usage_s *bm_resource_type = NULL;
+ rc = bm_query_step(hstmt);
+ BM_CATCH_ERROR_P(rc == SQLITE_ROW, {}, BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND, ("The record isn't found.(%s)\n", resource_id));
+
+ bm_resource_type = (resourceid_usage_s *)calloc(1, sizeof(resourceid_usage_s));
+ if (bm_resource_type == NULL) {
+ _ERR("memory allocation failed");
+ if (hstmt != NULL) {
+ rc = bm_query_finalize(hstmt);
+ BM_RETURN_VAL((rc == BATTERY_MONITOR_ERROR_NONE), { *error_code = rc; }, NULL, ("finalize error"));
+ hstmt = NULL;
+ }
+ *error_code = BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
+ return NULL;
+ }
+ bm_convert_column_to_resourceid_usage(hstmt, bm_resource_type);
+
+ rc = bm_query_finalize(hstmt);
+ BM_CATCH_ERROR_P((rc == BATTERY_MONITOR_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
+ *error_code = BATTERY_MONITOR_ERROR_NONE;
+
+CATCH:
+ if (hstmt != NULL) {
+ rc = bm_query_finalize(hstmt);
+ if (rc != BATTERY_MONITOR_ERROR_NONE) {
+ *error_code = rc;
+ _ERR("finalize error");
+ }
+ hstmt = NULL;
+ }
+ if ((*error_code != BATTERY_MONITOR_ERROR_NONE) && bm_resource_type) {
+ BM_FREE(bm_resource_type);
+ bm_resource_type = NULL;
+ }
+ if ((*error_code == BATTERY_MONITOR_ERROR_NONE) && bm_resource_type != NULL) {
+ _INFO("Returning appid usage");
+ return bm_resource_type;
+ }
+ EXIT;
+ return NULL;
+}
+
static int bm_delete_table(sqlite3 *bm_db_handle, bm_stmt *phstmt, int num_app_id, const char *app_id, const char* table)
{
ENTER;
return BATTERY_MONITOR_ERROR_NONE;
}
+/* For App usage related queries */
appid_usage_s *bm_server_query_app_usage_by_appid(const char *app_id, int period_type, int *error_code)
{
ENTER;
return bm_app_type;
}
+appid_usage_s *bm_server_query_app_usage_by_appid_ci(const char *app_id, long long s_time, long long e_time, int *error_code)
+{
+ ENTER;
+
+ appid_usage_s *bm_app_type = NULL;
+ *error_code = BATTERY_MONITOR_ERROR_NONE;
+
+ BM_RETURN_VAL((g_hBatteryMonitorDB != NULL), { *error_code = BATTERY_MONITOR_ERROR_DB_NOT_OPENED; }, NULL, ("The database isn't connected."));
+ BM_RETURN_VAL((app_id != NULL), { *error_code = BATTERY_MONITOR_ERROR_INVALID_PARAMETER; }, NULL, ("The Battery Monitor Handle is NULL"));
+
+ bm_app_type = bm_query_usage_by_appid_ci(g_hBatteryMonitorDB, app_id, s_time, e_time, error_code);
+
+ EXIT;
+ return bm_app_type;
+}
+
+/* For Resource usage related queries */
resourceid_usage_s *bm_server_query_resource_usage_resourceid(const char *resource_id, int period_type, int *error_code)
{
ENTER;
return bm_resource_type;
}
+resourceid_usage_s *bm_server_query_resource_usage_resourceid_ci(const char *resource_id, long long s_time, long long e_time, int *error_code)
+{
+ resourceid_usage_s *bm_resource_type = NULL;
+ *error_code = BATTERY_MONITOR_ERROR_NONE;
+
+ BM_RETURN_VAL((g_hBatteryMonitorDB != NULL), { *error_code = BATTERY_MONITOR_ERROR_DB_NOT_OPENED; }, NULL, ("The database isn't connected."));
+ BM_RETURN_VAL((resource_id != NULL), { *error_code = BATTERY_MONITOR_ERROR_INVALID_PARAMETER; }, NULL, ("The Battery Monitor Handle is NULL"));
+
+ bm_resource_type = bm_query_usage_by_resourceid_ci(g_hBatteryMonitorDB, resource_id, s_time, e_time, error_code);
+
+ EXIT;
+ return bm_resource_type;
+}
+
GSList* bm_server_query_appid_map(int *error_code)
{
ENTER;
return (((long)resource_val*100)/total_consumption);
}
+double bm_calc_individual_mah_consumption(int resource_val, double mah_c)
+{
+ if (resource_val == 0) {
+ _DBG("no consumption");
+ return 0;
+ }
+
+ _DBG("resource consumption - [%d]", resource_val);
+ return ((double)resource_val/mah_c);
+}
+
GVariant* bm_marshal_serialized_data(const bm_total_consumption_h data)
{
ENTER;