#include <sys/time.h>
#include <sys/times.h>
#include <tzplatform_config.h>
-
+#include <app_manager.h>
#include "battery_monitor.h"
#include "battery_monitor_util.h"
int error_code = BATTERY_MONITOR_ERROR_NONE;
double battery_usage = -1;
- testapp_print("\n Input AppID using Look Up table:\n");
+ testapp_print("\n Input AppID:\n");
if (0 >= scanf("%55s", app_name)) {
testapp_print("Invalid input ");
return FALSE;
error_code = battery_monitor_get_power_usage_by_app(app_name, (time_t)start_time, (time_t)end_time, &battery_usage);
if (error_code == BATTERY_MONITOR_ERROR_NONE)
- testapp_print(" battery_monitor_get_total_usage_by_app_id for APPID [%s] returned Usage of [%lf] & Error Code [%d] \n", app_name, battery_usage, error_code);
+ testapp_print("Battery Usage for APPID [%s] =========== [%lf] mAh\n", app_name, battery_usage);
return FALSE;
}
error_code = battery_monitor_get_power_usage_by_resource(resource_id, (time_t)start_time, (time_t)end_time, &battery_usage);
if (error_code == BATTERY_MONITOR_ERROR_NONE)
- testapp_print(" battery_monitor_get_total_usage_by_resource_id for RID [%d], returned Usage of [%lf] & Error Code [%d] \n", resource_id, battery_usage, error_code);
+ testapp_print(" Battery Usage for RID [%d] ============= [%lf] \n", resource_id, battery_usage);
return FALSE;
}
int error_code = BATTERY_MONITOR_ERROR_NONE;
battery_usage_data_h data_handle = NULL;
- testapp_print("\n Input AppID using Look Up table:\n");
+ testapp_print("\n Input AppID:\n");
if (0 >= scanf("%55s", app_name)) {
testapp_print("Invalid input ");
return FALSE;
testapp_print("\n End Time: %lld \n", end_time);
error_code = battery_monitor_get_power_usage_by_app_for_all_resources(app_name, (time_t)start_time, (time_t)end_time, &data_handle);
-
if (error_code == BATTERY_MONITOR_ERROR_NONE) {
- testapp_print ("Valid Handle Received, Value of error_code is [%d] \n", error_code);
-
- double battery_usage = -1;
+ testapp_print ("Valid Handle Received\n");
+ double battery_usage = -1;
#ifdef DISABLE_FEATURE_DATA_FROM_GPS_HRM_PLUGIN
for (int id = BATTERY_MONITOR_RESOURCE_ID_BLE; id < BATTERY_MONITOR_RESOURCE_ID_MAX; id++) {
#else
#endif
battery_usage = -1;
error_code = battery_monitor_usage_data_get_power_usage_per_resource(data_handle, id, &battery_usage);
-
if (error_code != BATTERY_MONITOR_ERROR_NONE) {
if (error_code == BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND)
testapp_print ("This resource is not available \n");
- else
- testapp_print ("Error Received, Value of error_code is [%d] \n", error_code);
continue;
}
-
switch (id) {
case BATTERY_MONITOR_RESOURCE_ID_BLE:
testapp_print ("Resource ID : BT App Usage Value = [%lf] \n", battery_usage);
error_code = battery_monitor_battery_usage_data_destroy(data_handle);
if (error_code != BATTERY_MONITOR_ERROR_NONE)
- testapp_print ("Handle Destroy Failed");
+ testapp_print ("Handle Destroy Failed \n");
return FALSE;
}
double battery_usage = -1;
int error_code = BATTERY_MONITOR_ERROR_NONE;
- testapp_print("\n Input AppID using Look Up table:\n");
+ testapp_print("\n Input AppID:\n");
if (0 >= scanf("%55s", app_name)) {
testapp_print("Invalid input");
return FALSE;
testapp_print("\n End Time: %lld \n", end_time);
error_code = battery_monitor_get_power_usage_by_app_per_resource(app_name, resource_id, (time_t)start_time, (time_t)end_time, &battery_usage);
+ if (error_code == BATTERY_MONITOR_ERROR_NONE)
+ testapp_print (" Battery Usage for APPID [%s], of RID [%d] is [%lf] \n", app_name, resource_id, battery_usage);
+
+ return FALSE;
+}
+
+bool get_app_id_cb(app_info_h app_info, void *user_data)
+{
+ char* app_id = NULL;
+ double battery_usage = -1;
+ int error_code = BATTERY_MONITOR_ERROR_NONE;
+
+ if (app_info_get_app_id(app_info, &app_id)) {
+ testapp_print("app_info_get_app_id failed \n");
+ return false;
+ }
+ //Call your Battery Monitor API
+ testapp_time_s *tv = (testapp_time_s *)user_data;
+ error_code = battery_monitor_get_power_usage_by_app(app_id, (time_t)(tv->from), (time_t)(tv->to), &battery_usage);
if (error_code == BATTERY_MONITOR_ERROR_NONE)
- testapp_print (" Battery Usage for APPID [%s], of RID [%d] is [%lf]", app_name, resource_id, battery_usage);
+ testapp_print("APPID [%s] ====== Usage of [%lf]\n", app_id, battery_usage);
+ else if (error_code == BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND)
+ testapp_print("APPID [%s] ====== Usage Not Available\n", app_id);
+
+ free(app_id);
+
+ return true;
+}
+
+static gboolean bmt_testapp_get_power_usage_for_all_app_id()
+{
+ long long int start_time = -1;
+ long long int end_time = -1;
+
+ testapp_print("\n Input Start Time:\n");
+ if (0 >= scanf("%lld", &start_time)) {
+ testapp_print("Invalid input ");
+ return FALSE;
+ }
+ testapp_print("\n Start Time: %lld \n", start_time);
+
+ testapp_print("\n Input End Time:\n");
+ if (0 >= scanf("%lld", &end_time)) {
+ testapp_print("Invalid input ");
+ return FALSE;
+ }
+ testapp_print("\n End Time: %lld \n", end_time);
+
+ testapp_time_s *user_data = (testapp_time_s *)calloc(1, sizeof(testapp_time_s));
+ if (user_data == NULL) {
+ testapp_print("time_s memory allocation failed \n");
+ return FALSE;
+ }
+
+ user_data->from = start_time; user_data->to = end_time;
+ int error_code = APP_MANAGER_ERROR_NONE;
+ error_code = app_manager_foreach_app_info(get_app_id_cb, (void *)user_data);
+ if (error_code != APP_MANAGER_ERROR_NONE)
+ testapp_print("app manager fails \n");
+
+ free(user_data);
+ return FALSE;
+}
+
+static gboolean bmt_testapp_get_power_usage_for_all_resource_id()
+{
+ long long int start_time = -1;
+ long long int end_time = -1;
+ double battery_usage = -1;
+ int error_code = BATTERY_MONITOR_ERROR_NONE;
+
+ testapp_print("\n Input Start Time:\n");
+ if (0 >= scanf("%lld", &start_time)) {
+ testapp_print("Invalid input ");
+ return FALSE;
+ }
+ testapp_print("\n Start Time: %lld \n", start_time);
+
+ testapp_print("\n Input End Time:\n");
+ if (0 >= scanf("%lld", &end_time)) {
+ testapp_print("Invalid input ");
+ return FALSE;
+ }
+ testapp_print("\n End Time: %lld \n", end_time);
+
+#ifdef DISABLE_FEATURE_DATA_FROM_GPS_HRM_PLUGIN
+ for (int id = BATTERY_MONITOR_RESOURCE_ID_BLE; id < BATTERY_MONITOR_RESOURCE_ID_MAX; id++) {
+#else
+ for (int id = BATTERY_MONITOR_RESOURCE_ID_BLE; id <= BATTERY_MONITOR_RESOURCE_ID_GPS_SENSOR; id++) {
+#endif
+ battery_usage = -1;
+ error_code = battery_monitor_get_power_usage_by_resource(id, (time_t)start_time, (time_t)end_time, &battery_usage);
+ if (error_code != BATTERY_MONITOR_ERROR_NONE) {
+ if (error_code == BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND)
+ testapp_print ("This resource is not available \n");
+ continue;
+ }
+
+ switch (id) {
+ case BATTERY_MONITOR_RESOURCE_ID_BLE:
+ testapp_print ("Resource ID : BT Usage Value = [%lf] \n", battery_usage);
+ break;
+ case BATTERY_MONITOR_RESOURCE_ID_WIFI:
+ testapp_print ("Resource ID : WIFI Usage Value = [%lf] \n", battery_usage);
+ break;
+ case BATTERY_MONITOR_RESOURCE_ID_CPU:
+ testapp_print ("Resource ID : CPU Usage Value = [%lf] \n", battery_usage);
+ break;
+ case BATTERY_MONITOR_RESOURCE_ID_DISPLAY:
+ testapp_print ("Resource ID : DISPLAY Usage Value = [%lf] \n", battery_usage);
+ break;
+ case BATTERY_MONITOR_RESOURCE_ID_DEVICE_NETWORK:
+ testapp_print ("Resource ID : DEVICE NETWORK Usage Value = [%lf] \n", battery_usage);
+ break;
+ case BATTERY_MONITOR_RESOURCE_ID_GPS_SENSOR:
+ testapp_print ("Resource ID : GPS Usage Value = [%lf] \n", battery_usage);
+ break;
+ default:
+ testapp_print ("Default Case \n");
+ break;
+ }
+
+ }
+ return FALSE;
+}
+bool get_app_id_all_resource_cb(app_info_h app_info, void *user_data)
+{
+ char* app_id = NULL;
+ double battery_usage = -1;
+ int error_code = BATTERY_MONITOR_ERROR_NONE;
+
+ if (app_info_get_app_id(app_info, &app_id)) {
+ testapp_print("app_info_get_app_id failed \n");
+ return false;
+ }
+
+ //Call your Battery Monitor API
+ testapp_time_s *tv = (testapp_time_s *)user_data;
+ battery_usage_data_h data_handle = NULL;
+ error_code = battery_monitor_get_power_usage_by_app_for_all_resources(app_id, (time_t)(tv->from), (time_t)(tv->to), &data_handle);
+ if (error_code == BATTERY_MONITOR_ERROR_NONE) {
+ testapp_print ("Valid Handle Received for APPID [%s] \n", app_id);
+#ifdef DISABLE_FEATURE_DATA_FROM_GPS_HRM_PLUGIN
+ for (int id = BATTERY_MONITOR_RESOURCE_ID_BLE; id < BATTERY_MONITOR_RESOURCE_ID_MAX; id++) {
+#else
+ for (int id = BATTERY_MONITOR_RESOURCE_ID_BLE; id <= BATTERY_MONITOR_RESOURCE_ID_GPS_SENSOR; ++id) {
+#endif
+ battery_usage = -1;
+ error_code = battery_monitor_usage_data_get_power_usage_per_resource(data_handle, id, &battery_usage);
+ if (error_code != BATTERY_MONITOR_ERROR_NONE) {
+ if (error_code == BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND)
+ testapp_print ("This resource is not available \n");
+ else
+ testapp_print ("Error Received, Value of error_code is [%d] \n", error_code);
+ continue;
+ }
+
+ switch (id) {
+ case BATTERY_MONITOR_RESOURCE_ID_BLE:
+ testapp_print ("Resource ID : BT App Usage Value = [%lf] \n", battery_usage);
+ break;
+ case BATTERY_MONITOR_RESOURCE_ID_WIFI:
+ testapp_print ("Resource ID : WIFI App Usage Value = [%lf] \n", battery_usage);
+ break;
+ case BATTERY_MONITOR_RESOURCE_ID_CPU:
+ testapp_print ("Resource ID : CPU App Usage Value = [%lf] \n", battery_usage);
+ break;
+ case BATTERY_MONITOR_RESOURCE_ID_DISPLAY:
+ testapp_print ("Resource ID : DISPLAY App Usage Value = [%lf] \n", battery_usage);
+ break;
+ case BATTERY_MONITOR_RESOURCE_ID_DEVICE_NETWORK:
+ testapp_print ("Resource ID : DEVICE NETWORK App Usage Value = [%lf] \n", battery_usage);
+ break;
+ case BATTERY_MONITOR_RESOURCE_ID_GPS_SENSOR:
+ testapp_print ("Resource ID : GPS App Usage Value = [%lf] \n", battery_usage);
+ break;
+ default:
+ testapp_print ("Default Case");
+ break;
+ }
+ }
+ battery_monitor_battery_usage_data_destroy(data_handle);
+ testapp_print ("App Usage Printed \n");
+ } else if (error_code == BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND)
+ testapp_print("APPID [%s] ====== Usage Not Available\n", app_id);
+
+ free(app_id);
+ return true;
+}
+
+static gboolean bmt_testapp_get_power_usage_for_all_app_id_per_resource()
+{
+ long long int start_time = -1;
+ long long int end_time = -1;
+
+ testapp_print("\n Input Start Time:\n");
+ if (0 >= scanf("%lld", &start_time)) {
+ testapp_print("Invalid input ");
+ return FALSE;
+ }
+ testapp_print("\n Start Time: %lld \n", start_time);
+
+ testapp_print("\n Input End Time:\n");
+ if (0 >= scanf("%lld", &end_time)) {
+ testapp_print("Invalid input ");
+ return FALSE;
+ }
+ testapp_print("\n End Time: %lld \n", end_time);
+
+ testapp_time_s *user_data = (testapp_time_s *)calloc(1, sizeof(testapp_time_s));
+ if (user_data == NULL) {
+ testapp_print("time_s memory allocation failed");
+ return FALSE;
+ }
+
+ user_data->from = start_time; user_data->to = end_time;
+ int error_code = APP_MANAGER_ERROR_NONE;
+ error_code = app_manager_foreach_app_info(get_app_id_all_resource_cb, (void *)user_data);
+ if (error_code != APP_MANAGER_ERROR_NONE)
+ testapp_print("app manager fails");
+
+ free(user_data);
return FALSE;
}
break;
case 4:
bmt_testapp_get_power_usage_by_app_id_for_resource_id_ci();
-
+ break;
+ case 5:
+ bmt_testapp_get_power_usage_for_all_app_id();
+ break;
+ case 6:
+ bmt_testapp_get_power_usage_for_all_resource_id();
+ break;
+ case 7:
+ bmt_testapp_get_power_usage_for_all_app_id_per_resource();
+ break;
case 0:
go_to_loop = FALSE;
break;