Add New Query Provisions in Test App 53/231153/1 submit/tizen/20200418.071655 submit/tizen/20200420.051632
authorDewal Agarwal <d1.agarwal@samsung.com>
Wed, 15 Apr 2020 06:18:26 +0000 (11:48 +0530)
committerDewal Agarwal <d1.agarwal@samsung.com>
Fri, 17 Apr 2020 13:10:24 +0000 (13:10 +0000)
Change-Id: Ia653be121e8d4b5778cde9f47abd6abd6a945763
Signed-off-by: Dewal Agarwal <d1.agarwal@samsung.com>
CMakeLists.txt
packaging/capi-system-battery-monitor.spec
test/test_cli_app/CMakeLists.txt
test/test_cli_app/include/bmt_utility.h
test/test_cli_app/src/bmt_usage.c
test/test_cli_app/src/bmt_utility.c

index 2c15b5bf9fe121d81f205a8a634c67abed5cef3c..eb620b4b0b1460783dc2a29ecd7192be179e5541 100644 (file)
@@ -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(
index cf4189b21c88cc6f43229364a3425808a8082d5c..e872e75c76cad147015fa3d495b8891a4e8c5681 100644 (file)
@@ -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)
 
index 0f893c8675d00bf9d020c29f8ea3bb6c893583e8..443d2f31d0d83147d6fb22c00dc3b1678e1ec7af 100644 (file)
@@ -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})
index 992f14901d6704ef3f2dc436936a879ff56f9a2a..3a64f8e844aa2a5e7876dc5a667e3d0f87085047 100644 (file)
 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);
index c3a31df82fc588455c5295d856977c3a3d47c4f2..ceb66d976962fe19101ed3c599ec324fe867400d 100644 (file)
@@ -30,7 +30,7 @@
 #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"
 
@@ -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;
index 94dfa9a815fd2e2ba5117950ac7ae9756ef483aa..91efd12cec55d63fd36f9b8dfc8292f582962c79 100644 (file)
@@ -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 App ID for CI\n");
+               testapp_print(" 2.  Get Total Usage By 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)