From: Dewal Agarwal Date: Wed, 15 Apr 2020 06:18:26 +0000 (+0530) Subject: Add New Query Provisions in Test App X-Git-Tag: submit/tizen/20200418.071655^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d22e87cadf4070be0fb2468b5a56525f37c0151a;p=platform%2Fcore%2Fapi%2Fbatterymonitor.git Add New Query Provisions in Test App Change-Id: Ia653be121e8d4b5778cde9f47abd6abd6a945763 Signed-off-by: Dewal Agarwal --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c15b5b..eb620b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ pkg_check_modules(PKGS REQUIRED gio-unix-2.0 libtzplatform-config capi-system-info + capi-appfw-app-manager ) ADD_CUSTOM_COMMAND( diff --git a/packaging/capi-system-battery-monitor.spec b/packaging/capi-system-battery-monitor.spec index cf4189b..e872e75 100644 --- a/packaging/capi-system-battery-monitor.spec +++ b/packaging/capi-system-battery-monitor.spec @@ -13,6 +13,7 @@ BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(gio-unix-2.0) BuildRequires: pkgconfig(pkgmgr-info) +BuildRequires: pkgconfig(capi-appfw-app-manager) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(aul) diff --git a/test/test_cli_app/CMakeLists.txt b/test/test_cli_app/CMakeLists.txt index 0f893c8..443d2f3 100644 --- a/test/test_cli_app/CMakeLists.txt +++ b/test/test_cli_app/CMakeLists.txt @@ -3,6 +3,7 @@ SET(test "bm-test") INCLUDE(FindPkgConfig) pkg_check_modules(${test} REQUIRED glib-2.0 + capi-appfw-app-manager ) FOREACH(flag ${${test}_CFLAGS}) diff --git a/test/test_cli_app/include/bmt_utility.h b/test/test_cli_app/include/bmt_utility.h index 992f149..3a64f8e 100644 --- a/test/test_cli_app/include/bmt_utility.h +++ b/test/test_cli_app/include/bmt_utility.h @@ -27,11 +27,13 @@ typedef enum { BM_MAIN_MENU = 0x0, BM_USAGE_MENU, -/* -BM_DUMMY_MENU -*/ } battery_monitor_menu_e; +typedef struct testapp_time_s { + long long int from; + long long int to; +} testapp_time_s; + void testapp_print(char *fmt, ...); void testapp_show_menu(battery_monitor_menu_e menu); void testapp_show_prompt(battery_monitor_menu_e menu); diff --git a/test/test_cli_app/src/bmt_usage.c b/test/test_cli_app/src/bmt_usage.c index c3a31df..ceb66d9 100644 --- a/test/test_cli_app/src/bmt_usage.c +++ b/test/test_cli_app/src/bmt_usage.c @@ -30,7 +30,7 @@ #include #include #include - +#include #include "battery_monitor.h" #include "battery_monitor_util.h" @@ -51,7 +51,7 @@ static gboolean bmt_testapp_get_total_power_usage_by_app_id_for_ci() 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; @@ -74,7 +74,7 @@ static gboolean bmt_testapp_get_total_power_usage_by_app_id_for_ci() 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; } @@ -118,7 +118,7 @@ static gboolean bmt_testapp_get_total_power_usage_by_resource_id_ci() 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; } @@ -138,7 +138,7 @@ static gboolean bmt_testapp_get_total_power_usage_by_app_id_for_all_resource_id_ 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; @@ -160,11 +160,9 @@ static gboolean bmt_testapp_get_total_power_usage_by_app_id_for_all_resource_id_ 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 @@ -172,15 +170,11 @@ static gboolean bmt_testapp_get_total_power_usage_by_app_id_for_all_resource_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); @@ -209,7 +203,7 @@ static gboolean bmt_testapp_get_total_power_usage_by_app_id_for_all_resource_id_ 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; } @@ -231,7 +225,7 @@ static gboolean bmt_testapp_get_power_usage_by_app_id_for_resource_id_ci() 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; @@ -260,10 +254,230 @@ static gboolean bmt_testapp_get_power_usage_by_app_id_for_resource_id_ci() 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; } @@ -283,7 +497,16 @@ static gboolean testapp_test_interpret_command(int selected_number) 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; diff --git a/test/test_cli_app/src/bmt_utility.c b/test/test_cli_app/src/bmt_utility.c index 94dfa9a..91efd12 100644 --- a/test/test_cli_app/src/bmt_utility.c +++ b/test/test_cli_app/src/bmt_utility.c @@ -55,13 +55,15 @@ void testapp_show_menu(battery_monitor_menu_e menu) testapp_print("==========================================\n"); testapp_print(" USAGE MENU \n"); testapp_print("==========================================\n"); - testapp_print(" ===== FOR CUSTOM INTERVALS ===== \n"); - testapp_print(" 1. Get Total Usage By App ID for CI\n"); - testapp_print(" 2. Get Total Usage By Resource ID for CI\n"); - testapp_print(" 3. Get App Usage for All Resource IDs for CI\n"); + testapp_print(" ========= FOR CUSTOM INTERVALS ========= \n"); + testapp_print(" 1. Get Total Usage By a App ID for CI\n"); + testapp_print(" 2. Get Total Usage By a Resource ID for CI\n"); + testapp_print(" 3. Get Each Resource Usage for a App ID for CI\n"); testapp_print(" 4. Get App Usage for a Resource ID for CI\n"); - - testapp_print(" 5. Dummy menu entry (Don't Use)\n"); + testapp_print(" 5. Get Total Usage for each App ID for CI\n"); + testapp_print(" 6. Get Total Usage for each Resource ID for CI\n"); + testapp_print(" 7. Get Each Resource Usage for each App ID for CI\n"); + testapp_print(" 8. Dummy menu entry (Don't Use)\n"); testapp_print(" 0. Go to Main Menu\n"); testapp_print("------------------------------------------\n\n"); @@ -93,7 +95,6 @@ void testapp_show_menu(battery_monitor_menu_e menu) default: break; } - } void testapp_show_prompt(battery_monitor_menu_e menu)