From c582453d1fdf531ac3315769dbc3cf15b63a75e3 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Wed, 10 Oct 2018 16:33:34 +0900 Subject: [PATCH 01/16] Add missing linker flag and option Change-Id: Ia03aaa308ac24ba6412589a849c5d5c0402bb08d Signed-off-by: Sangyoon Jang --- CMakeLists.txt | 1 + src/CMakeLists.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 69272ee..77e1752 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror -ffunction-sect ## Linker flags SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed,--gc-sections") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed,--gc-sections,--no-undefined") SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5187397..f4280e2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,6 +13,7 @@ APPLY_PKG_CONFIG(${TARGET_LIB_CAPMGR} PUBLIC DLOG_DEPS GIO_DEPS GLIB_DEPS + SQLITE_DEPS ) SET_TARGET_PROPERTIES(${TARGET_LIB_CAPMGR} PROPERTIES VERSION ${FULLVER}) -- 2.7.4 From 78aa5d403a5a9c9c3b659b2dc4f83976b82a5073 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Wed, 24 Oct 2018 14:45:39 +0900 Subject: [PATCH 02/16] Remove unnecessary excutable bit in file mode Change-Id: I77dee12b75975fd9097889d4e801738c5007a24d Signed-off-by: Sangyoon Jang --- include/capability-manager_internal.h | 0 src/client_internal.cc | 0 src/dbus.cc | 0 src/dbus.h | 0 src/dbus_signal.h | 0 tools/capmgr_test.cc | 0 6 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 include/capability-manager_internal.h mode change 100755 => 100644 src/client_internal.cc mode change 100755 => 100644 src/dbus.cc mode change 100755 => 100644 src/dbus.h mode change 100755 => 100644 src/dbus_signal.h mode change 100755 => 100644 tools/capmgr_test.cc diff --git a/include/capability-manager_internal.h b/include/capability-manager_internal.h old mode 100755 new mode 100644 diff --git a/src/client_internal.cc b/src/client_internal.cc old mode 100755 new mode 100644 diff --git a/src/dbus.cc b/src/dbus.cc old mode 100755 new mode 100644 diff --git a/src/dbus.h b/src/dbus.h old mode 100755 new mode 100644 diff --git a/src/dbus_signal.h b/src/dbus_signal.h old mode 100755 new mode 100644 diff --git a/tools/capmgr_test.cc b/tools/capmgr_test.cc old mode 100755 new mode 100644 -- 2.7.4 From a3da96bf5dcb4e1d685610f46b27823ca6f4c50e Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Wed, 24 Oct 2018 17:34:23 +0900 Subject: [PATCH 03/16] Rename header file as capability_manager.h Make it consistent as other native API headers. Change-Id: I6f346bd0ec9d6931817b114b3f10a5fd59f6b0c6 Signed-off-by: Sangyoon Jang --- include/{capability-manager.h => capability_manager.h} | 2 +- .../{capability-manager_internal.h => capability_manager_internal.h} | 2 +- packaging/capi-appfw-capmgr.spec | 4 ++-- src/client.cc | 2 +- src/client_internal.cc | 4 ++-- src/dbus.h | 2 +- tools/capmgr_test.cc | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) rename include/{capability-manager.h => capability_manager.h} (99%) rename include/{capability-manager_internal.h => capability_manager_internal.h} (97%) diff --git a/include/capability-manager.h b/include/capability_manager.h similarity index 99% rename from include/capability-manager.h rename to include/capability_manager.h index 41986c6..e7f1de5 100644 --- a/include/capability-manager.h +++ b/include/capability_manager.h @@ -12,7 +12,7 @@ extern "C" { #endif /** - * @file capability-manager.h + * @file capability_manager.h */ /** diff --git a/include/capability-manager_internal.h b/include/capability_manager_internal.h similarity index 97% rename from include/capability-manager_internal.h rename to include/capability_manager_internal.h index ff3afdc..e24a6ec 100644 --- a/include/capability-manager_internal.h +++ b/include/capability_manager_internal.h @@ -5,7 +5,7 @@ #ifndef INCLUDE_CAPABILITY_MANAGER_INTERNAL_H_ #define INCLUDE_CAPABILITY_MANAGER_INTERNAL_H_ -#include "include/capability-manager.h" +#include "include/capability_manager.h" #ifdef __cplusplus extern "C" { diff --git a/packaging/capi-appfw-capmgr.spec b/packaging/capi-appfw-capmgr.spec index 37a2323..ae05be9 100644 --- a/packaging/capi-appfw-capmgr.spec +++ b/packaging/capi-appfw-capmgr.spec @@ -53,7 +53,7 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` %{_bindir}/capmgr-test %files devel -%{_includedir}/capability-manager.h -%{_includedir}/capability-manager_internal.h +%{_includedir}/capability_manager.h +%{_includedir}/capability_manager_internal.h %{_libdir}/pkgconfig/%{name}.pc %{_libdir}/lib%{name}.so diff --git a/src/client.cc b/src/client.cc index 4d94287..5356173 100644 --- a/src/client.cc +++ b/src/client.cc @@ -13,7 +13,7 @@ #include #include -#include "include/capability-manager.h" +#include "include/capability_manager.h" #include "src/dbus.h" #include "src/sql_connection.h" #include "src/sql_statement.h" diff --git a/src/client_internal.cc b/src/client_internal.cc index c6ba05e..172d7fd 100644 --- a/src/client_internal.cc +++ b/src/client_internal.cc @@ -10,8 +10,8 @@ #include #include -#include "include/capability-manager.h" -#include "include/capability-manager_internal.h" +#include "include/capability_manager.h" +#include "include/capability_manager_internal.h" #include "src/dbus.h" #include "src/dbus_signal.h" #include "src/utils/logging.h" diff --git a/src/dbus.h b/src/dbus.h index 83336a3..5053cd6 100644 --- a/src/dbus.h +++ b/src/dbus.h @@ -10,7 +10,7 @@ #include -#include "include/capability-manager.h" +#include "include/capability_manager.h" namespace capmgr { diff --git a/tools/capmgr_test.cc b/tools/capmgr_test.cc index d57b732..8c79856 100644 --- a/tools/capmgr_test.cc +++ b/tools/capmgr_test.cc @@ -9,8 +9,8 @@ #include -#include "include/capability-manager.h" -#include "include/capability-manager_internal.h" +#include "include/capability_manager.h" +#include "include/capability_manager_internal.h" namespace bpo = boost::program_options; -- 2.7.4 From cc51a4f532e7a20d3ceaffeaf092b5895abf5f14 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 25 Oct 2018 10:16:09 +0900 Subject: [PATCH 04/16] Add a missing API Add capmgr_app_control_get_device(). Change-Id: Ie3a86199d2f61aa1027bdb9d10226e68b1f83495 Signed-off-by: Sangyoon Jang --- src/client.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/client.cc b/src/client.cc index 5356173..a2f05c3 100644 --- a/src/client.cc +++ b/src/client.cc @@ -252,6 +252,18 @@ API int capmgr_app_control_destroy(capmgr_app_control_h app_control) { return CAPMGR_ERROR_NONE; } +API int capmgr_app_control_get_device(capmgr_app_control_h app_control, + capmgr_device_h* device) { + if (!app_control || !device) + return CAPMGR_ERROR_INVALID_PARAMETER; + + int ret = capmgr_device_clone(app_control->device, device); + if (ret != CAPMGR_ERROR_NONE) + return ret; + + return CAPMGR_ERROR_NONE; +} + API int capmgr_app_control_get_operation(capmgr_app_control_h app_control, char** operation) { if (!app_control || !operation) -- 2.7.4 From 91d0f8d96118e277df59f431c08d30856c3927db Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 25 Oct 2018 13:38:05 +0900 Subject: [PATCH 05/16] Fix allocating structure object Use "new A()" style to zero initialize. Change-Id: I1baf86c4b8e8130ba81a7b7e10107eb5681f8faf Signed-off-by: Sangyoon Jang --- src/client.cc | 10 +++++----- src/dbus.cc | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/client.cc b/src/client.cc index a2f05c3..b01f4ee 100644 --- a/src/client.cc +++ b/src/client.cc @@ -88,7 +88,7 @@ API int capmgr_device_clone(const capmgr_device_h device, return CAPMGR_ERROR_INVALID_PARAMETER; try { - struct capmgr_device_s* clone = new struct capmgr_device_s; + struct capmgr_device_s* clone = new struct capmgr_device_s(); clone->device_id = device->device_id; clone->model_name = device->model_name; @@ -191,7 +191,7 @@ API int capmgr_app_control_create(capmgr_app_control_h* app_control) { return CAPMGR_ERROR_INVALID_PARAMETER; try { - struct capmgr_app_control_s* control = new struct capmgr_app_control_s; + struct capmgr_app_control_s* control = new struct capmgr_app_control_s(); control->b = bundle_create(); if (!control->b) { delete control; @@ -218,7 +218,7 @@ API int capmgr_app_control_clone(const capmgr_app_control_h app_control, return CAPMGR_ERROR_INVALID_PARAMETER; try { - struct capmgr_app_control_s* clone = new struct capmgr_app_control_s; + struct capmgr_app_control_s* clone = new struct capmgr_app_control_s(); int ret = capmgr_device_clone(app_control->device, &clone->device); if (ret != CAPMGR_ERROR_NONE) { @@ -468,7 +468,7 @@ void capmgr_dbus_callback(GVariant* result, void* user_data) { g_variant_iter_free(iter); struct cbdata* cbdata = reinterpret_cast(user_data); - struct capmgr_app_control_s* reply = new struct capmgr_app_control_s; + struct capmgr_app_control_s* reply = new struct capmgr_app_control_s(); reply->b = bundle_decode(data, len); if (!reply->b) { LOG(ERROR) << "Invalid bundle data!"; @@ -520,7 +520,7 @@ API int capmgr_app_control_send(capmgr_app_control_h app_control, return r; } - struct cbdata* cbdata = new struct cbdata; + struct cbdata* cbdata = new struct cbdata(); cbdata->request = clone; cbdata->cb = cb; cbdata->user_data = user_data; diff --git a/src/dbus.cc b/src/dbus.cc index 8b3c3f1..ec092d9 100644 --- a/src/dbus.cc +++ b/src/dbus.cc @@ -129,7 +129,7 @@ bool ProxyCallAsync(const char* method, GVariant* params, DBusCallback cb, } // will be freed at MethodCallback() - struct cbdata* cbdata = new struct cbdata; + struct cbdata* cbdata = new struct cbdata(); cbdata->cb = cb; cbdata->user_data = user_data; -- 2.7.4 From 3b6451caca10ce615beeaee8f795772968a0095a Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 25 Oct 2018 15:47:45 +0900 Subject: [PATCH 06/16] Fix capmgr_app_control_set_device() If device is already set, destroy the previous one. Change-Id: I40a305fbf7472645dc6cb994f34a49e3f6b33a76 Signed-off-by: Sangyoon Jang --- src/client.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/client.cc b/src/client.cc index b01f4ee..97a9d7e 100644 --- a/src/client.cc +++ b/src/client.cc @@ -353,6 +353,9 @@ API int capmgr_app_control_set_device(capmgr_app_control_h app_control, if (!app_control || !device) return CAPMGR_ERROR_INVALID_PARAMETER; + if (app_control->device) + capmgr_device_destroy(app_control->device); + int ret = capmgr_device_clone(device, &app_control->device); if (ret != CAPMGR_ERROR_NONE) return CAPMGR_ERROR_OUT_OF_MEMORY; -- 2.7.4 From 31f7aa294dc0dc72dffc1d4669ea7504428b0bf3 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Fri, 26 Oct 2018 11:01:14 +0900 Subject: [PATCH 07/16] Change API spec - Remove Apis about Package infomation - Add Apis about Application information Signed-off-by: Inkyun Kil --- include/capability_manager.h | 90 ++++++++++++++++++++------------------------ src/client.cc | 82 ++++++++++++++++------------------------ tools/capmgr_test.cc | 76 +++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+), 98 deletions(-) diff --git a/include/capability_manager.h b/include/capability_manager.h index e7f1de5..a8affce 100644 --- a/include/capability_manager.h +++ b/include/capability_manager.h @@ -25,10 +25,14 @@ extern "C" { * @since_tizen 5.0 */ typedef enum { - CAPMGR_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ - CAPMGR_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ - CAPMGR_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ - CAPMGR_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< Internal I/O error */ + /**< Successful */ + CAPMGR_ERROR_NONE = TIZEN_ERROR_NONE, + /**< Invalid parameter */ + CAPMGR_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, + /**< Out of memory */ + CAPMGR_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, + /**< Internal I/O error */ + CAPMGR_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, } capmgr_error_e; /** @@ -52,10 +56,10 @@ typedef struct capmgr_device_s* capmgr_device_h; typedef struct capmgr_app_control_s* capmgr_app_control_h; /** - * @brief Capability Manager package info handle. + * @brief Capability Manager application info handle. * @since_tizen 5.0 */ -typedef struct capmgr_package_info_s* capmgr_package_info_h; +typedef struct capmgr_application_info_s* capmgr_application_info_h; /** * @brief Called to retrieve information of devices currently discovered. @@ -86,28 +90,16 @@ typedef int (*capmgr_app_control_reply_cb)(const capmgr_app_control_h request, void* user_data); /** - * @brief Called for each remote package info. + * @brief Called for each remote application info. * @since_tizen 5.0 * - * @remarks The @a remote_package_info can be used only in the callback. To use outside, make a copy. - * @param[in] remote_package_info Capability Manager package info handle - * @param[in] user_data The user data to be passed to the callback function - * @see capmgr_package_info_foreach_packages() - */ -typedef int (*capmgr_package_info_foreach_package_cb)( - const capmgr_package_info_h remote_package_info, void* user_data); - -/** - * @brief Called for each application of remote package. - * @since_tizen 5.0 - * - * @remarks The @a appid can be used only in the callback. To use outside, make a copy. - * @param[in] appid Application ID of remote application + * @remarks The @a remote_app_info can be used only in the callback. To use outside, make a copy. + * @param[in] remote_app_info Capability Manager Application Info handle * @param[in] user_data The user data to be passed to the callback function - * @see capmgr_package_info_foreach_applications() + * @see capmgr_application_info_foreach_applications() */ -typedef int (*capmgr_package_info_foreach_app_cb)( - const char* appid, void* user_data); +typedef int (*capmgr_application_info_foreach_app_cb)( + const capmgr_application_info_h remote_app_info, void* user_data); /** * @brief Retrieves all remote device info stored on local device. @@ -505,10 +497,10 @@ int capmgr_app_control_send(capmgr_app_control_h app_control, capmgr_app_control_reply_cb cb, void* user_data); /** - * @brief Retrieves all packages installed at specified remote device and invoke callback each of it. + * @brief Retrieves all applications installed at specified remote device and invoke callback each of it. * @since_tizen 5.0 * @param[in] device The remote device handle - * @param[in] cb Callback to be invoked for each package + * @param[in] cb Callback to be invoked for each application * @param[in] user_data The user data to be passed to the callback function * @return @c 0 on success, * otherwise a negative error value @@ -517,70 +509,70 @@ int capmgr_app_control_send(capmgr_app_control_h app_control, * @retval #CAPMGR_ERROR_IO_ERROR I/O error * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory */ -int capmgr_package_info_foreach_packages(const capmgr_device_h device, - capmgr_package_info_foreach_package_cb cb, void* user_data); +int capmgr_application_info_foreach_applications( + const capmgr_device_h device, + capmgr_application_info_foreach_app_cb cb, + void* user_data); /** - * @brief Retrieves all applications belongs to given package and invoke callback each of it. + * @brief Gets the application ID from given remote application information. * @since_tizen 5.0 - * @param[in] remote_package_info The package information installed at specific remote device - * @param[in] cb Callback to be invoked for each application - * @param[in] user_data The user data to be passed to the callback function + * @remarks You must release @a appid using free(). + * @param[in] remote_app_info The application information installed at specific remote device + * @param[out] appid The application ID * @return @c 0 on success, * otherwise a negative error value * @retval #CAPMGR_ERROR_NONE Successful * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #CAPMGR_ERROR_IO_ERROR I/O error * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory */ -int capmgr_package_info_foreach_applications( - const capmgr_package_info_h remote_package_info, - capmgr_package_info_foreach_app_cb cb, void* user_data); +int capmgr_application_info_get_appid(capmgr_application_info_h remote_app_info, + char** appid); /** - * @brief Gets the package ID from given remote package information. + * @brief Gets the package ID from given remote application information. * @since_tizen 5.0 * @remarks You must release @a pkgid using free(). - * @param[in] remote_package_info The package information installed at specific remote device - * @param[in] pkgid The package ID + * @param[in] remote_app_info The application information installed at specific remote device + * @param[out] pkgid The package ID * @return @c 0 on success, * otherwise a negative error value * @retval #CAPMGR_ERROR_NONE Successful * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory */ -int capmgr_package_info_get_pkgid(capmgr_package_info_h remote_package_info, +int capmgr_application_info_get_pkgid(capmgr_application_info_h remote_app_info, char** pkgid); /** - * @brief Gets the label from given remote package information. + * @brief Gets the label from given remote application information. * @since_tizen 5.0 * @remarks You must release @a label using free(). - * @param[in] remote_package_info The package information installed at specific remote device - * @param[in] label The label of package + * @param[in] remote_app_info The application information installed at specific remote device + * @param[out] label The label of application * @return @c 0 on success, * otherwise a negative error value * @retval #CAPMGR_ERROR_NONE Successful * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory */ -int capmgr_package_info_get_label(capmgr_package_info_h remote_package_info, +int capmgr_application_info_get_label(capmgr_application_info_h remote_app_info, char** label); /** - * @brief Gets the version from given remote package information. + * @brief Gets the version from given remote application information. * @since_tizen 5.0 * @remarks You must release @a version using free(). - * @param[in] remote_package_info The package information installed at specific remote device - * @param[in] version The version of package + * @param[in] remote_app_info The application information installed at specific remote device + * @param[out] version The version of application * @return @c 0 on success, * otherwise a negative error value * @retval #CAPMGR_ERROR_NONE Successful * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory */ -int capmgr_package_info_get_version(capmgr_package_info_h remote_package_info, - char** version); +int capmgr_application_info_get_version( + capmgr_application_info_h remote_app_info, char** version); #ifdef __cplusplus } diff --git a/src/client.cc b/src/client.cc index 97a9d7e..de41c94 100644 --- a/src/client.cc +++ b/src/client.cc @@ -42,11 +42,11 @@ struct capmgr_app_control_s { bundle* b; }; -struct capmgr_package_info_s { +struct capmgr_application_info_s { + std::string appid; std::string pkgid; std::string label; std::string version; - std::vector appid_list; }; API int capmgr_device_foreach_devices(capmgr_device_foreach_cb cb, @@ -543,50 +543,58 @@ API int capmgr_app_control_send(capmgr_app_control_h app_control, return CAPMGR_ERROR_NONE; } -API int capmgr_package_info_get_pkgid(capmgr_package_info_h remote_package_info, - char** pkgid) { - if (!remote_package_info || !pkgid || - remote_package_info->pkgid.empty()) +API int capmgr_application_info_get_appid( + capmgr_application_info_h remote_app_info, char** appid) { + if (!remote_app_info || !appid || remote_app_info->appid.empty()) return CAPMGR_ERROR_INVALID_PARAMETER; - *pkgid = strdup(remote_package_info->pkgid.c_str()); + *appid = strdup(remote_app_info->appid.c_str()); + if (*appid == nullptr) + return CAPMGR_ERROR_OUT_OF_MEMORY; + + return CAPMGR_ERROR_NONE; +} + +API int capmgr_application_info_get_pkgid( + capmgr_application_info_h remote_app_info, char** pkgid) { + if (!remote_app_info || !pkgid || remote_app_info->pkgid.empty()) + return CAPMGR_ERROR_INVALID_PARAMETER; + + *pkgid = strdup(remote_app_info->pkgid.c_str()); if (*pkgid == nullptr) return CAPMGR_ERROR_OUT_OF_MEMORY; return CAPMGR_ERROR_NONE; } -API int capmgr_package_info_get_label(capmgr_package_info_h remote_package_info, - char** label) { - if (!remote_package_info || !label || - remote_package_info->label.empty()) +API int capmgr_application_info_get_label( + capmgr_application_info_h remote_app_info, char** label) { + if (!remote_app_info || !label || remote_app_info->label.empty()) return CAPMGR_ERROR_INVALID_PARAMETER; - *label = strdup(remote_package_info->label.c_str()); + *label = strdup(remote_app_info->label.c_str()); if (*label == nullptr) return CAPMGR_ERROR_OUT_OF_MEMORY; return CAPMGR_ERROR_NONE; } -API int capmgr_package_info_get_version( - capmgr_package_info_h remote_package_info, char** version) { - if (!remote_package_info || !version || - remote_package_info->version.empty()) +API int capmgr_application_info_get_version( + capmgr_application_info_h remote_app_info, char** version) { + if (!remote_app_info || !version || remote_app_info->version.empty()) return CAPMGR_ERROR_INVALID_PARAMETER; - *version = strdup(remote_package_info->version.c_str()); + *version = strdup(remote_app_info->version.c_str()); if (*version == nullptr) return CAPMGR_ERROR_OUT_OF_MEMORY; return CAPMGR_ERROR_NONE; } -API int capmgr_package_info_foreach_packages(const capmgr_device_h device, - capmgr_package_info_foreach_package_cb cb, +API int capmgr_application_info_foreach_applications( + const capmgr_device_h device, + capmgr_application_info_foreach_app_cb cb, void* user_data) { - std::map pkg_map; - if (!cb) return CAPMGR_ERROR_INVALID_PARAMETER; @@ -604,40 +612,16 @@ API int capmgr_package_info_foreach_packages(const capmgr_device_h device, if (stmt->BindString(1, device->device_id)) { while (stmt->Step() == capmgr::SQLStatement::StepResult::ROW) { - struct capmgr_package_info_s info; - std::string appid; + struct capmgr_application_info_s info; int idx = 0; - appid = stmt->GetColumnString(idx++); + info.appid = stmt->GetColumnString(idx++); info.pkgid = stmt->GetColumnString(idx++); info.label = stmt->GetColumnString(idx++); info.version = stmt->GetColumnString(idx++); - - auto search_info = pkg_map.find(appid); - if (search_info != pkg_map.end()) { - info.appid_list.emplace_back(appid); - pkg_map.emplace(appid, info); - } else { - struct capmgr_package_info_s found = search_info->second; - found.appid_list.emplace_back(appid); - } + if (cb(&info, user_data)) + break; } } - for (auto it = pkg_map.begin(); it != pkg_map.end(); it++) { - struct capmgr_package_info_s info = it->second; - if (cb(&info, user_data)) - break; - } - - return CAPMGR_ERROR_NONE; -} - -API int capmgr_package_info_foreach_applications( - const capmgr_package_info_h remote_pkg_info, - capmgr_package_info_foreach_app_cb cb, - void* user_data) { - if (!cb) - return CAPMGR_ERROR_INVALID_PARAMETER; - return CAPMGR_ERROR_NONE; } diff --git a/tools/capmgr_test.cc b/tools/capmgr_test.cc index 8c79856..6dad30b 100644 --- a/tools/capmgr_test.cc +++ b/tools/capmgr_test.cc @@ -34,6 +34,7 @@ class Client { void SendAppControl(const std::string& device_id, const std::string& appid); void SendFile(const std::string& device_id, const std::string& file_path); void ListDevices(); + void ListAppinfos(const std::string& device_id); private: GVariant* ProxyCallSync(const char* method, GVariant* params); @@ -112,6 +113,48 @@ int DeviceForeachCb(const capmgr_device_h device, void* user_data) { return 0; } +int AppForeachCb(const capmgr_application_info_h remote_app_info, + void* user_data) { + char* appid = nullptr; + char* pkgid = nullptr; + char* label = nullptr; + char* ver = nullptr; + + int ret = capmgr_application_info_get_appid(remote_app_info, &appid); + if (ret != CAPMGR_ERROR_NONE) + std::cout << "Failed to get appid" << std::endl; + + ret = capmgr_application_info_get_pkgid(remote_app_info, &pkgid); + if (ret != CAPMGR_ERROR_NONE) + std::cout << "Failed to get pkgid" << std::endl; + + ret = capmgr_application_info_get_label(remote_app_info, &label); + if (ret != CAPMGR_ERROR_NONE) + std::cout << "Failed to get label" << std::endl; + + ret = capmgr_application_info_get_version(remote_app_info, &ver); + if (ret != CAPMGR_ERROR_NONE) + std::cout << "Failed to get pkgid" << std::endl; + + std::cout << "==============================================" << std::endl; + try { + std::cout << "APPID: " << std::string(appid) << std::endl + << "PKGID: " << std::string(pkgid) << std::endl + << "Label: " << std::string(label) << std::endl + << "Version: " << std::string(ver) << std::endl; + } catch (...) { + std::cout << "Exception occured" << std::endl; + } + + free(appid); + free(pkgid); + free(label); + free(ver); + + return 0; +} + + Client::Client() { loop_ = g_main_loop_new(nullptr, FALSE); @@ -211,6 +254,36 @@ void Client::ListDevices() { << std::endl; } +void Client::ListAppinfos(const std::string& device_id) { + if (device_id.empty()) { + std::cout << "Target device is missing!" << std::endl; + return; + } + + capmgr_device_h device = nullptr; + struct cbdata cbdata = {&device, device_id}; + int ret = capmgr_device_foreach_devices(DeviceForeachCb, &cbdata); + if (ret != CAPMGR_ERROR_NONE) { + std::cout << "capmgr_device_foreach_devices() failed: " << ret + << std::endl; + return; + } + + if (*cbdata.device == nullptr) { + std::cout << "There is no such device!" << std::endl; + return; + } + + std::cout << "Target device is " <(), "send remote app-control") ("list-devices,l", "list remote devices") + ("list-appinfos,a", "list remote application infos") ("send-file,f", bpo::value(), "send file"); bpo::store(bpo::parse_command_line(argc, argv, options), opt_map); @@ -370,6 +444,8 @@ int main(int argc, char* argv[]) { opt_map["send-appcontrol"].as()); else if (opt_map.count("list-devices")) client.ListDevices(); + else if (opt_map.count("list-appinfos")) + client.ListAppinfos(opt_map["device"].as()); else if (opt_map.count("send-file")) client.SendFile(opt_map["device"].as(), opt_map["send-file"].as()); -- 2.7.4 From 2c44fa4f05f198984a256c348a520ee5cb058b07 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Mon, 29 Oct 2018 17:41:13 +0900 Subject: [PATCH 08/16] Add capmgr_application_info_clone() Change-Id: I84233af4d2aef6ef9587b00cfeb331a240aa9fbe Signed-off-by: Sangyoon Jang --- include/capability_manager.h | 15 +++++++++++++++ src/client.cc | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/capability_manager.h b/include/capability_manager.h index a8affce..4f7019b 100644 --- a/include/capability_manager.h +++ b/include/capability_manager.h @@ -515,6 +515,21 @@ int capmgr_application_info_foreach_applications( void* user_data); /** + * @brief Clones the remote application information handle. + * @since_tizen 5.0 + * @param[in] remote_app_info The remote application info handle + * @param[out] remote_app_info_clone A newly created remote application information handle, if successfully cloned + * @return @c 0 on success, + * otherwise a negative error value + * @retval #CAPMGR_ERROR_NONE Successful + * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory + */ +int capmgr_application_info_clone( + const capmgr_application_info_h remote_app_info, + capmgr_application_info_h* remote_app_info_clone); + +/** * @brief Gets the application ID from given remote application information. * @since_tizen 5.0 * @remarks You must release @a appid using free(). diff --git a/src/client.cc b/src/client.cc index de41c94..a6a08b7 100644 --- a/src/client.cc +++ b/src/client.cc @@ -543,6 +543,30 @@ API int capmgr_app_control_send(capmgr_app_control_h app_control, return CAPMGR_ERROR_NONE; } +API int capmgr_application_info_clone( + const capmgr_application_info_h remote_app_info, + capmgr_application_info_h* remote_app_info_clone) { + if (!remote_app_info || !remote_app_info_clone) + return CAPMGR_ERROR_INVALID_PARAMETER; + + struct capmgr_application_info_s* clone; + try { + clone = new struct capmgr_application_info_s(); + } catch (const std::bad_alloc& e) { + LOG(ERROR) << e.what(); + return CAPMGR_ERROR_OUT_OF_MEMORY; + } + + clone->appid = remote_app_info->appid; + clone->pkgid = remote_app_info->pkgid; + clone->label = remote_app_info->label; + clone->version = remote_app_info->version; + + *remote_app_info_clone = clone; + + return CAPMGR_ERROR_NONE; +} + API int capmgr_application_info_get_appid( capmgr_application_info_h remote_app_info, char** appid) { if (!remote_app_info || !appid || remote_app_info->appid.empty()) -- 2.7.4 From 239e5217ddff2e9c359e165db192c1256ce1ef49 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Wed, 7 Nov 2018 15:35:54 +0900 Subject: [PATCH 09/16] Add device handle to application information handle Signed-off-by: Inkyun Kil --- include/capability_manager.h | 29 +++++++++++++++++++++++++++++ src/client.cc | 33 +++++++++++++++++++++++++++++++++ tools/capmgr_test.cc | 15 ++++++++++++++- 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/include/capability_manager.h b/include/capability_manager.h index 4f7019b..e5b0a44 100644 --- a/include/capability_manager.h +++ b/include/capability_manager.h @@ -97,6 +97,7 @@ typedef int (*capmgr_app_control_reply_cb)(const capmgr_app_control_h request, * @param[in] remote_app_info Capability Manager Application Info handle * @param[in] user_data The user data to be passed to the callback function * @see capmgr_application_info_foreach_applications() + * @see capmgr_application_info_clone() */ typedef int (*capmgr_application_info_foreach_app_cb)( const capmgr_application_info_h remote_app_info, void* user_data); @@ -524,6 +525,7 @@ int capmgr_application_info_foreach_applications( * @retval #CAPMGR_ERROR_NONE Successful * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory + * @see capmgr_application_info_destroy() */ int capmgr_application_info_clone( const capmgr_application_info_h remote_app_info, @@ -589,6 +591,33 @@ int capmgr_application_info_get_label(capmgr_application_info_h remote_app_info, int capmgr_application_info_get_version( capmgr_application_info_h remote_app_info, char** version); +/** + * @brief Gets the remote device handle from the given remote application info context. + * @since_tizen 5.0 + * @remarks You must release @a device using capmgr_device_destroy(). + * @param[in] remote_app_info The application information installed at specific remote device + * @param[out] device The remote device handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #CAPMGR_ERROR_NONE Successful + * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory + */ +int capmgr_application_info_get_device( + capmgr_application_info_h remote_app_info, capmgr_device_h* device); + +/** + * @brief Destroys the remote application information handle and releases all its resources. + * @since_tizen 5.0 + * @param[in] remote_app_info The remote application information handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #CAPMGR_ERROR_NONE Successful + * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter + * @see capmgr_application_info_clone() + */ +int capmgr_application_info_destroy(capmgr_application_info_h remote_app_info); + #ifdef __cplusplus } #endif diff --git a/src/client.cc b/src/client.cc index a6a08b7..7e64cb1 100644 --- a/src/client.cc +++ b/src/client.cc @@ -47,6 +47,7 @@ struct capmgr_application_info_s { std::string pkgid; std::string label; std::string version; + capmgr_device_h device; }; API int capmgr_device_foreach_devices(capmgr_device_foreach_cb cb, @@ -562,11 +563,29 @@ API int capmgr_application_info_clone( clone->label = remote_app_info->label; clone->version = remote_app_info->version; + int ret = capmgr_device_clone(remote_app_info->device, &(clone->device)); + if (ret != CAPMGR_ERROR_NONE) { + LOG(ERROR) << "Failed to clone capmgr device"; + delete clone; + return ret; + } + *remote_app_info_clone = clone; return CAPMGR_ERROR_NONE; } +API int capmgr_application_info_destroy( + capmgr_application_info_h remote_app_info) { + if (!remote_app_info) + return CAPMGR_ERROR_INVALID_PARAMETER; + + capmgr_device_destroy(remote_app_info->device); + delete remote_app_info; + + return CAPMGR_ERROR_NONE; +} + API int capmgr_application_info_get_appid( capmgr_application_info_h remote_app_info, char** appid) { if (!remote_app_info || !appid || remote_app_info->appid.empty()) @@ -615,6 +634,19 @@ API int capmgr_application_info_get_version( return CAPMGR_ERROR_NONE; } +API int capmgr_application_info_get_device( + capmgr_application_info_h remote_app_info, + capmgr_device_h* device) { + if (!remote_app_info || !device) + return CAPMGR_ERROR_INVALID_PARAMETER; + + int ret = capmgr_device_clone(remote_app_info->device, device); + if (ret != CAPMGR_ERROR_NONE) + return ret; + + return CAPMGR_ERROR_NONE; +} + API int capmgr_application_info_foreach_applications( const capmgr_device_h device, capmgr_application_info_foreach_app_cb cb, @@ -642,6 +674,7 @@ API int capmgr_application_info_foreach_applications( info.pkgid = stmt->GetColumnString(idx++); info.label = stmt->GetColumnString(idx++); info.version = stmt->GetColumnString(idx++); + info.device = device; if (cb(&info, user_data)) break; } diff --git a/tools/capmgr_test.cc b/tools/capmgr_test.cc index 6dad30b..b2adec7 100644 --- a/tools/capmgr_test.cc +++ b/tools/capmgr_test.cc @@ -119,6 +119,8 @@ int AppForeachCb(const capmgr_application_info_h remote_app_info, char* pkgid = nullptr; char* label = nullptr; char* ver = nullptr; + capmgr_device_h device = nullptr; + char* device_id = nullptr; int ret = capmgr_application_info_get_appid(remote_app_info, &appid); if (ret != CAPMGR_ERROR_NONE) @@ -136,12 +138,22 @@ int AppForeachCb(const capmgr_application_info_h remote_app_info, if (ret != CAPMGR_ERROR_NONE) std::cout << "Failed to get pkgid" << std::endl; + ret = capmgr_application_info_get_device(remote_app_info, &device); + if (ret != CAPMGR_ERROR_NONE) + std::cout << "Failed to get device" << std::endl; + std::cout << "==============================================" << std::endl; + + ret = capmgr_device_get_device_id(device, &device_id); + if (ret != CAPMGR_ERROR_NONE) + std::cout << "Failed to get device id" << std::endl; + try { std::cout << "APPID: " << std::string(appid) << std::endl << "PKGID: " << std::string(pkgid) << std::endl << "Label: " << std::string(label) << std::endl - << "Version: " << std::string(ver) << std::endl; + << "Version: " << std::string(ver) << std::endl + << "Device ID: " << std::string(device_id) << std::endl; } catch (...) { std::cout << "Exception occured" << std::endl; } @@ -150,6 +162,7 @@ int AppForeachCb(const capmgr_application_info_h remote_app_info, free(pkgid); free(label); free(ver); + capmgr_device_destroy(device); return 0; } -- 2.7.4 From f629b4e9148709ae3dcaffc63024d7b9c4195d72 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Wed, 14 Nov 2018 19:13:11 +0900 Subject: [PATCH 10/16] Fix crash when invalid parameter given Change-Id: I958f11b27d06c2a9ba4f69a79398f02ded984cec Signed-off-by: Sangyoon Jang --- src/client.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client.cc b/src/client.cc index 7e64cb1..fa2030a 100644 --- a/src/client.cc +++ b/src/client.cc @@ -651,7 +651,7 @@ API int capmgr_application_info_foreach_applications( const capmgr_device_h device, capmgr_application_info_foreach_app_cb cb, void* user_data) { - if (!cb) + if (!device || !cb) return CAPMGR_ERROR_INVALID_PARAMETER; std::unique_ptr sql_conn( -- 2.7.4 From ba85b693deee438f0d1852e368cd2e0fe87805a5 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Wed, 24 Oct 2018 17:49:47 +0900 Subject: [PATCH 11/16] Add unit test Run /usr/bin/capi-appfw-capmgr-ut/unit-test after discovering at least one device. Change-Id: I261dc6b699e9b99f1b45940ae83e0b31a8cd75dc Signed-off-by: Sangyoon Jang --- CMakeLists.txt | 1 + packaging/capi-appfw-capmgr.spec | 11 ++ src/CMakeLists.txt | 2 + src/unit_tests/CMakeLists.txt | 16 ++ src/unit_tests/unit_test.cc | 401 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 431 insertions(+) create mode 100644 src/unit_tests/CMakeLists.txt create mode 100644 src/unit_tests/unit_test.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 77e1752..25bcfdc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ PKG_CHECK_MODULES(GLIB_DEPS REQUIRED glib-2.0) PKG_CHECK_MODULES(SQLITE_DEPS REQUIRED sqlite3) FIND_PACKAGE(Boost REQUIRED COMPONENTS filesystem program_options system) +FIND_PACKAGE(GTest REQUIRED) INSTALL(DIRECTORY include/ DESTINATION ${INCLUDEDIR} FILES_MATCHING PATTERN "*.h") ADD_SUBDIRECTORY(src) diff --git a/packaging/capi-appfw-capmgr.spec b/packaging/capi-appfw-capmgr.spec index ae05be9..5d90a34 100644 --- a/packaging/capi-appfw-capmgr.spec +++ b/packaging/capi-appfw-capmgr.spec @@ -8,6 +8,7 @@ Source0: %{name}-%{version}.tar.gz Source1001: %{name}.manifest BuildRequires: boost-devel BuildRequires: cmake +BuildRequires: gtest-devel BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(capi-base-common) @@ -27,6 +28,13 @@ Requires: %{name} = %{version} %description devel This package contains header files of capability manager native API +%package tests +Summary: Unit-tests for capmgr native API +Requires: %{name} = %{version} + +%description tests +Unit-tests for capmgr native API + %prep %setup -q cp %{SOURCE1001} . @@ -57,3 +65,6 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` %{_includedir}/capability_manager_internal.h %{_libdir}/pkgconfig/%{name}.pc %{_libdir}/lib%{name}.so + +%files tests +%{_bindir}/capi-appfw-capmgr-ut/* diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f4280e2..c5e8f33 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,3 +22,5 @@ SET_TARGET_PROPERTIES(${TARGET_LIB_CAPMGR} PROPERTIES SOVERSION ${MAJORVER}) INSTALL(TARGETS ${TARGET_LIB_CAPMGR} DESTINATION ${LIB_INSTALL_DIR}) CONFIGURE_FILE(capi-appfw-capmgr.pc.in capi-appfw-capmgr.pc @ONLY) INSTALL(FILES capi-appfw-capmgr.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) + +ADD_SUBDIRECTORY(unit_tests) diff --git a/src/unit_tests/CMakeLists.txt b/src/unit_tests/CMakeLists.txt new file mode 100644 index 0000000..bd06ad2 --- /dev/null +++ b/src/unit_tests/CMakeLists.txt @@ -0,0 +1,16 @@ +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ UNIT_TEST_SRCS) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../) + +SET(TARGET_UNIT_TEST "unit-test") + +ADD_EXECUTABLE(${TARGET_UNIT_TEST} ${UNIT_TEST_SRCS}) + +APPLY_PKG_CONFIG(${TARGET_UNIT_TEST} PUBLIC + DLOG_DEPS + GTEST +) + +TARGET_LINK_LIBRARIES(${TARGET_UNIT_TEST} PUBLIC ${TARGET_LIB_CAPMGR}) + +INSTALL(TARGETS ${TARGET_UNIT_TEST} DESTINATION bin/capi-appfw-capmgr-ut/) diff --git a/src/unit_tests/unit_test.cc b/src/unit_tests/unit_test.cc new file mode 100644 index 0000000..ae68e56 --- /dev/null +++ b/src/unit_tests/unit_test.cc @@ -0,0 +1,401 @@ +// Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#include + +#include + +#include "include/capability_manager.h" +#include "src/utils/logging.h" + +namespace { + +int DeviceForeachCbForSetup(const capmgr_device_h device, void* user_data) { + capmgr_device_h* clone = reinterpret_cast(user_data); + int ret = capmgr_device_clone(device, clone); + if (ret != CAPMGR_ERROR_NONE) + return 0; + // use the first device + else + return 1; +} + +int ApplicationForeachCbForSetup( + const capmgr_application_info_h remote_app_info, void* user_data) { + capmgr_application_info_h* clone = + reinterpret_cast(user_data); + int ret = capmgr_application_info_clone(remote_app_info, clone); + if (ret != CAPMGR_ERROR_NONE) + return 0; + // use the first app + else + return 1; +} + +int DeviceForeachCb(const capmgr_device_h device, void* user_data) { + bool* is_hit = reinterpret_cast(user_data); + *is_hit = true; + return 1; +} + +int ApplicationForeachCb(const capmgr_application_info_h remote_app_info, + void* user_data) { + bool* is_hit = reinterpret_cast(user_data); + *is_hit = true; + + char* appid; + capmgr_application_info_get_appid(remote_app_info, &appid); + free(appid); + LOG(INFO) << appid; + return 0; +} + +const char kExtraDataKeyStr[] = "extra_key"; +const char kExtraDataValueStr[] = "extra_value"; + +class TestEnvironment : public ::testing::Environment { + public: + TestEnvironment() : device_(nullptr), app_control_(nullptr), + app_(nullptr) {} + void SetUp() override { + ASSERT_EQ(capmgr_device_foreach_devices(DeviceForeachCbForSetup, &device_), + CAPMGR_ERROR_NONE) << "Failed to init test environment!"; + ASSERT_NE(device_, nullptr); + char* device_id; + capmgr_device_get_device_id(device_, &device_id); + LOG(INFO) << "Selected device id is: " << device_id; + free(device_id); + ASSERT_EQ(capmgr_app_control_create(&app_control_), CAPMGR_ERROR_NONE); + ASSERT_NE(app_control_, nullptr); + ASSERT_EQ(capmgr_app_control_set_device(app_control_, device_), + CAPMGR_ERROR_NONE); + ASSERT_EQ(capmgr_app_control_set_operation(app_control_, "operation"), + CAPMGR_ERROR_NONE); + ASSERT_EQ(capmgr_app_control_set_uri(app_control_, "uri"), + CAPMGR_ERROR_NONE); + ASSERT_EQ(capmgr_app_control_set_mime(app_control_, "mime"), + CAPMGR_ERROR_NONE); + ASSERT_EQ(capmgr_app_control_set_appid(app_control_, "appid"), + CAPMGR_ERROR_NONE); + ASSERT_EQ(capmgr_app_control_add_extra_data(app_control_, kExtraDataKeyStr, + kExtraDataValueStr), CAPMGR_ERROR_NONE); + ASSERT_EQ(capmgr_application_info_foreach_applications(device_, + ApplicationForeachCbForSetup, &app_), CAPMGR_ERROR_NONE); + } + void TearDown() override { + capmgr_application_info_destroy(app_); + capmgr_app_control_destroy(app_control_); + capmgr_device_destroy(device_); + } + + capmgr_device_h device_; + capmgr_app_control_h app_control_; + capmgr_application_info_h app_; +}; + +TestEnvironment* env = nullptr; + +} // namespace + +namespace capmgr { + +class UnitTest : public ::testing::Test { + protected: + virtual void SetUp() {} + virtual void TearDown() {} +}; + +TEST_F(UnitTest, DeviceForeachDevicesPositiveTest) { + bool is_hit = false; + ASSERT_EQ(capmgr_device_foreach_devices(DeviceForeachCb, &is_hit), + CAPMGR_ERROR_NONE); + ASSERT_TRUE(is_hit); +} + +TEST_F(UnitTest, DeviceForeachDevicesNegativeTest) { + ASSERT_EQ(capmgr_device_foreach_devices(nullptr, nullptr), + CAPMGR_ERROR_INVALID_PARAMETER); +} + +TEST_F(UnitTest, DeviceClonePositiveTest) { + // need to get device + capmgr_device_h clone; + ASSERT_EQ(capmgr_device_clone(env->device_, &clone), CAPMGR_ERROR_NONE); +} + +TEST_F(UnitTest, DeviceCloneNegativeTest) { + capmgr_device_h clone; + ASSERT_EQ(capmgr_device_clone(nullptr, &clone), + CAPMGR_ERROR_INVALID_PARAMETER); + ASSERT_EQ(capmgr_device_clone(env->device_, nullptr), + CAPMGR_ERROR_INVALID_PARAMETER); +} + +TEST_F(UnitTest, DeviceDestroyPositiveTest) { + capmgr_device_h clone; + ASSERT_EQ(capmgr_device_clone(env->device_, &clone), + CAPMGR_ERROR_NONE); + ASSERT_EQ(capmgr_device_destroy(clone), CAPMGR_ERROR_NONE); +} + +TEST_F(UnitTest, DeviceDestroyNegativeTest) { + ASSERT_EQ(capmgr_device_destroy(nullptr), CAPMGR_ERROR_INVALID_PARAMETER); +} + +#define DEVICE_GET_TEST_BLOCK(POSITIVE_TESTNAME, NEGATIVE_TESTNAME, ATTR) \ +TEST_F(UnitTest, POSITIVE_TESTNAME) { \ + char* ATTR = nullptr; \ + ASSERT_EQ(capmgr_device_get_##ATTR(env->device_, &ATTR), CAPMGR_ERROR_NONE); \ + ASSERT_NE(ATTR, nullptr); \ + free(ATTR); \ +} \ + \ +TEST_F(UnitTest, NEGATIVE_TESTNAME) { \ + char* ATTR; \ + ASSERT_EQ(capmgr_device_get_##ATTR(nullptr, &ATTR), \ + CAPMGR_ERROR_INVALID_PARAMETER); \ + ASSERT_EQ(capmgr_device_get_##ATTR(env->device_, nullptr), \ + CAPMGR_ERROR_INVALID_PARAMETER); \ +} \ + +DEVICE_GET_TEST_BLOCK(DeviceGetDeviceIdPositiveTest, + DeviceGetDeviceIdNegativeTest, device_id) + +DEVICE_GET_TEST_BLOCK(DeviceGetModelNamePositiveTest, + DeviceGetModelNameNegativeTest, model_name) + +DEVICE_GET_TEST_BLOCK(DeviceGetDeviceNamePositiveTest, + DeviceGetDeviceNameNegativeTest, device_name) + +DEVICE_GET_TEST_BLOCK(DeviceGetPlatformVerPositiveTest, + DeviceGetPlatformVerNegativeTest, platform_ver) + +DEVICE_GET_TEST_BLOCK(DeviceGetProfilePositiveTest, + DeviceGetProfileNegativeTest, profile) + +DEVICE_GET_TEST_BLOCK(DeviceGetSWVerPositiveTest, + DeviceGetSWVerNegativeTest, sw_ver) + +TEST_F(UnitTest, AppControlCreatePositiveTest) { + capmgr_app_control_h app_control; + ASSERT_EQ(capmgr_app_control_create(&app_control), CAPMGR_ERROR_NONE); + capmgr_app_control_destroy(app_control); +} + +TEST_F(UnitTest, AppControlCreateNegativeTest) { + ASSERT_EQ(capmgr_app_control_create(nullptr), CAPMGR_ERROR_INVALID_PARAMETER); +} + +TEST_F(UnitTest, AppControlDestroyPositiveTest) { + capmgr_app_control_h app_control; + ASSERT_EQ(capmgr_app_control_create(&app_control), CAPMGR_ERROR_NONE); + ASSERT_EQ(capmgr_app_control_destroy(app_control), CAPMGR_ERROR_NONE); +} + +TEST_F(UnitTest, AppControlDestroyNegativeTest) { + ASSERT_EQ(capmgr_app_control_destroy(nullptr), + CAPMGR_ERROR_INVALID_PARAMETER); +} + +TEST_F(UnitTest, AppControlGetDevicePositiveTest) { + capmgr_device_h device; + ASSERT_EQ(capmgr_app_control_get_device(env->app_control_, &device), + CAPMGR_ERROR_NONE); + capmgr_device_destroy(device); +} + +TEST_F(UnitTest, AppControlGetDeviceNegativeTest) { + capmgr_device_h device; + ASSERT_EQ(capmgr_app_control_get_device(nullptr, &device), + CAPMGR_ERROR_INVALID_PARAMETER); + ASSERT_EQ(capmgr_app_control_get_device(env->app_control_, nullptr), + CAPMGR_ERROR_INVALID_PARAMETER); +} + +#define APP_CONTROL_GET_TEST_BLOCK(POSITIVE_TESTNAME, NEGATIVE_TESTNAME, ATTR) \ +TEST_F(UnitTest, POSITIVE_TESTNAME) { \ + char* ATTR = nullptr; \ + ASSERT_EQ(capmgr_app_control_get_##ATTR(env->app_control_, &ATTR), \ + CAPMGR_ERROR_NONE); \ + ASSERT_NE(ATTR, nullptr); \ + free(ATTR); \ +} \ + \ +TEST_F(UnitTest, NEGATIVE_TESTNAME) { \ + char* ATTR; \ + ASSERT_EQ(capmgr_app_control_get_##ATTR(nullptr, &ATTR), \ + CAPMGR_ERROR_INVALID_PARAMETER); \ + ASSERT_EQ(capmgr_app_control_get_##ATTR(env->app_control_, nullptr), \ + CAPMGR_ERROR_INVALID_PARAMETER); \ +} \ + +APP_CONTROL_GET_TEST_BLOCK(AppControlGetOperationPositiveTest, + AppControlGetOperationNegativeTest, operation) + +APP_CONTROL_GET_TEST_BLOCK(AppControlGetUriPositiveTest, + AppControlGetUriNegativeTest, uri) + +APP_CONTROL_GET_TEST_BLOCK(AppControlGetMimePositiveTest, + AppControlGetMimeNegativeTest, mime) + +APP_CONTROL_GET_TEST_BLOCK(AppControlGetAppidPositiveTest, + AppControlGetAppidNegativeTest, appid) + +TEST_F(UnitTest, AppControlGetExtraDataPositiveTest) { + char* value = nullptr; + ASSERT_EQ(capmgr_app_control_get_extra_data(env->app_control_, + kExtraDataKeyStr, &value), CAPMGR_ERROR_NONE); + ASSERT_NE(value, nullptr); + free(value); +} + +TEST_F(UnitTest, AppControlGetExtraDataNegativeTest) { + char* value; + ASSERT_EQ(capmgr_app_control_get_extra_data(nullptr, + kExtraDataKeyStr, &value), CAPMGR_ERROR_INVALID_PARAMETER); + ASSERT_EQ(capmgr_app_control_get_extra_data(env->app_control_, + nullptr, &value), CAPMGR_ERROR_INVALID_PARAMETER); + ASSERT_EQ(capmgr_app_control_get_extra_data(env->app_control_, + kExtraDataKeyStr, nullptr), CAPMGR_ERROR_INVALID_PARAMETER); +} + +TEST_F(UnitTest, AppControlSetDevicePositiveTest) { + ASSERT_EQ(capmgr_app_control_set_device(env->app_control_, env->device_), + CAPMGR_ERROR_NONE); +} + +TEST_F(UnitTest, AppControlSetDeviceNegativeTest) { + ASSERT_EQ(capmgr_app_control_set_device(nullptr, env->device_), + CAPMGR_ERROR_INVALID_PARAMETER); + ASSERT_EQ(capmgr_app_control_set_device(env->app_control_, nullptr), + CAPMGR_ERROR_INVALID_PARAMETER); +} + +#define APP_CONTROL_SET_TEST_BLOCK(POSITIVE_TESTNAME, NEGATIVE_TESTNAME, ATTR) \ +TEST_F(UnitTest, POSITIVE_TESTNAME) { \ + ASSERT_EQ(capmgr_app_control_set_##ATTR(env->app_control_, "value"), \ + CAPMGR_ERROR_NONE); \ +} \ + \ +TEST_F(UnitTest, NEGATIVE_TESTNAME) { \ + ASSERT_EQ(capmgr_app_control_set_##ATTR(nullptr, "value"), \ + CAPMGR_ERROR_INVALID_PARAMETER); \ + ASSERT_EQ(capmgr_app_control_set_##ATTR(env->app_control_, nullptr), \ + CAPMGR_ERROR_INVALID_PARAMETER); \ +} \ + +APP_CONTROL_SET_TEST_BLOCK(AppControlSetOperationPositiveTest, + AppControlSetOperationNegativeTest, operation) + +APP_CONTROL_SET_TEST_BLOCK(AppControlSetUriPositiveTest, + AppControlSetUriNegativeTest, uri) + +APP_CONTROL_SET_TEST_BLOCK(AppControlSetMimePositiveTest, + AppControlSetMimeNegativeTest, mime) + +APP_CONTROL_SET_TEST_BLOCK(AppControlSetAppidPositiveTest, + AppControlSetAppidNegativeTest, appid) + +TEST_F(UnitTest, AppControlAddExtraDataPositiveTest) { + ASSERT_EQ( + capmgr_app_control_add_extra_data(env->app_control_, "key", "value"), + CAPMGR_ERROR_NONE); +} + +TEST_F(UnitTest, AppControlAddExtraDataNegativeTest) { + ASSERT_EQ( + capmgr_app_control_add_extra_data(nullptr, "key", "value"), + CAPMGR_ERROR_INVALID_PARAMETER); + ASSERT_EQ( + capmgr_app_control_add_extra_data(env->app_control_, nullptr, "value"), + CAPMGR_ERROR_INVALID_PARAMETER); + ASSERT_EQ( + capmgr_app_control_add_extra_data(env->app_control_, "key", nullptr), + CAPMGR_ERROR_INVALID_PARAMETER); +} + +TEST_F(UnitTest, AppControlRemoveExtraDataPositiveTest) { + ASSERT_EQ( + capmgr_app_control_add_extra_data(env->app_control_, "key2", "value2"), + CAPMGR_ERROR_NONE); + ASSERT_EQ( + capmgr_app_control_remove_extra_data(env->app_control_, "key2"), + CAPMGR_ERROR_NONE); + // should return such as CAPMGR_ERROR_NO_SUCH_KEY? + char* value; + ASSERT_EQ(capmgr_app_control_get_extra_data(env->app_control_, + "key2", &value), CAPMGR_ERROR_INVALID_PARAMETER); +} + +TEST_F(UnitTest, AppControlRemoveExtraDataNegativeTest) { + char* value; + ASSERT_EQ(capmgr_app_control_get_extra_data(nullptr, + kExtraDataKeyStr, &value), CAPMGR_ERROR_INVALID_PARAMETER); + ASSERT_EQ(capmgr_app_control_get_extra_data(env->app_control_, + nullptr, &value), CAPMGR_ERROR_INVALID_PARAMETER); + ASSERT_EQ(capmgr_app_control_get_extra_data(env->app_control_, + kExtraDataKeyStr, nullptr), CAPMGR_ERROR_INVALID_PARAMETER); +} + +// TODO(jeremy.jang) +/* +TEST_F(UnitTest, AppControlSendPositiveTest) { +} + +TEST_F(UnitTest, AppControlSendNegativeTest) { +} +*/ + +TEST_F(UnitTest, ApplicationInfoForeachPackagesPositiveTest) { + bool is_hit = false; + ASSERT_EQ(capmgr_application_info_foreach_applications(env->device_, + ApplicationForeachCb, &is_hit), CAPMGR_ERROR_NONE); + ASSERT_TRUE(is_hit); +} + +TEST_F(UnitTest, ApplicationInfoForeachPackagesNegativeTest) { + ASSERT_EQ(capmgr_application_info_foreach_applications(nullptr, + ApplicationForeachCb, nullptr), CAPMGR_ERROR_INVALID_PARAMETER); + ASSERT_EQ(capmgr_application_info_foreach_applications(env->device_, + nullptr, nullptr), CAPMGR_ERROR_INVALID_PARAMETER); +} + +#define APPLICATION_INFO_GET_TEST_BLOCK( \ + POSITIVE_TESTNAME, NEGATIVE_TESTNAME, ATTR) \ +TEST_F(UnitTest, POSITIVE_TESTNAME) { \ + char* ATTR = nullptr; \ + ASSERT_EQ(capmgr_application_info_get_##ATTR(env->app_, &ATTR), \ + CAPMGR_ERROR_NONE); \ + ASSERT_NE(ATTR, nullptr); \ + free(ATTR); \ +} \ + \ +TEST_F(UnitTest, NEGATIVE_TESTNAME) { \ + char* ATTR; \ + ASSERT_EQ(capmgr_application_info_get_##ATTR(nullptr, &ATTR), \ + CAPMGR_ERROR_INVALID_PARAMETER); \ + ASSERT_EQ(capmgr_application_info_get_##ATTR(env->app_, nullptr), \ + CAPMGR_ERROR_INVALID_PARAMETER); \ +} \ + +APPLICATION_INFO_GET_TEST_BLOCK(ApplicationInfoGetAppidPositiveTest, + ApplicationInfoGetAppidNegativeTest, appid) + +APPLICATION_INFO_GET_TEST_BLOCK(ApplicationInfoGetPkgidPositiveTest, + ApplicationInfoGetPkgidNegativeTest, pkgid) + +APPLICATION_INFO_GET_TEST_BLOCK(ApplicationInfoGetLabelPositiveTest, + ApplicationInfoGetLabelNegativeTest, label) + +APPLICATION_INFO_GET_TEST_BLOCK(ApplicationInfoGetVersionPositiveTest, + ApplicationInfoGetVersionNegativeTest, version) + +} // namespace capmgr + +int main(int argc, char* argv[]) { + ::testing::InitGoogleTest(&argc, argv); + ::env = static_cast( + ::testing::AddGlobalTestEnvironment(new TestEnvironment)); + return RUN_ALL_TESTS(); +} -- 2.7.4 From f25beaa71c7252caa73e7ccc28f8c847e176cec2 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Wed, 28 Nov 2018 20:13:19 +0900 Subject: [PATCH 12/16] Fix LogCatcher Fix format security error. Change-Id: Ia52ac22072436d27978bf4ed4b0cf4ed61f1e513 Signed-off-by: Sangyoon Jang --- src/utils/logging.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/logging.h b/src/utils/logging.h index 491521c..23683bc 100644 --- a/src/utils/logging.h +++ b/src/utils/logging.h @@ -70,7 +70,7 @@ class LogCatcher { : level_(level), tag_(tag) { } void operator&(const StringStream& str) const { - dlog_print(LogLevelToPriority(level_), tag_.c_str(), + dlog_print(LogLevelToPriority(level_), tag_.c_str(), "%s", Escape(str.str()).c_str()); } -- 2.7.4 From 4def41d2feed69bf32a8a2dcfe2fad7aaa54c154 Mon Sep 17 00:00:00 2001 From: Daehyeon Jung Date: Mon, 11 Mar 2019 14:54:03 +0900 Subject: [PATCH 13/16] Revise API header - Update since_tizen version. - Change application_info to app_info. - Add privilge for send app control. Change-Id: I855d4623c6f581a1856527a207d4a6e8242a2d12 Signed-off-by: Daehyeon Jung --- include/capability_manager.h | 223 +++++++++++++++++++++++-------------------- src/client.cc | 44 ++++----- src/unit_tests/unit_test.cc | 58 +++++------ tools/capmgr_test.cc | 32 +++---- 4 files changed, 187 insertions(+), 170 deletions(-) diff --git a/include/capability_manager.h b/include/capability_manager.h index e5b0a44..4aa9a1b 100644 --- a/include/capability_manager.h +++ b/include/capability_manager.h @@ -1,6 +1,18 @@ -// Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef __TIZEN_APPFW_CAPABILITY_MANAGER_H__ #define __TIZEN_APPFW_CAPABILITY_MANAGER_H__ @@ -21,66 +33,62 @@ extern "C" { */ /** - * @brief Enumerations for Capability Manager Errors. - * @since_tizen 5.0 + * @brief Enumeration for Capability Manager Errors. + * @since_tizen 5.5 */ typedef enum { - /**< Successful */ - CAPMGR_ERROR_NONE = TIZEN_ERROR_NONE, - /**< Invalid parameter */ - CAPMGR_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, - /**< Out of memory */ - CAPMGR_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, - /**< Internal I/O error */ - CAPMGR_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, + CAPMGR_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + CAPMGR_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + CAPMGR_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + CAPMGR_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< Internal I/O error */ + CAPMGR_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ } capmgr_error_e; /** - * @brief Enumerations for Capability Manager app control result type. - * @since_tizen 5.0 + * @brief Enumeration for Capability Manager app control result type. + * @since_tizen 5.5 */ typedef enum { - CAPMGR_APP_CONTROL_RESULT_OK, /**< Successful */ + CAPMGR_APP_CONTROL_RESULT_OK, /**< Successful */ } capmgr_app_control_result_e; /** * @brief Capability Manager device handle. - * @since_tizen 5.0 + * @since_tizen 5.5 */ typedef struct capmgr_device_s* capmgr_device_h; /** * @brief Capability Manager app control handle. - * @since_tizen 5.0 + * @since_tizen 5.5 */ typedef struct capmgr_app_control_s* capmgr_app_control_h; /** * @brief Capability Manager application info handle. - * @since_tizen 5.0 + * @since_tizen 5.5 */ -typedef struct capmgr_application_info_s* capmgr_application_info_h; +typedef struct capmgr_app_info_s* capmgr_app_info_h; /** * @brief Called to retrieve information of devices currently discovered. - * @since_tizen 5.0 + * @since_tizen 5.5 * * @remarks The @a device can be used only in the callback. To use outside, make a copy. * @param[in] device Device handle * @param[in] user_data The user data to be passed to the callback function - * @see capmgr_device_foreach_devices() + * @see capmgr_device_foreach_device() */ typedef int (*capmgr_device_foreach_cb)(const capmgr_device_h device, void* user_data); /** - * @brief Called when send app control request has finished. - * @since_tizen 5.0 + * @brief Called when a 'send app control' request has finished. + * @since_tizen 5.5 * * @remarks The @a request, @reply can be used only in the callback. To use outside, make a copy. - * @param[in] request Capability Manager app control handle contains data to be sent - * @param[in] reply Capability Manager app control handle which contains - * reply for request + * @param[in] request Capability Manager app control handle which contains data to be sent + * @param[in] reply Capability Manager app control handle which contains reply for request * @param[in] result App control send result * @param[in] user_data The user data to be passed to the callback function * @see capmgr_app_control_send() @@ -91,20 +99,21 @@ typedef int (*capmgr_app_control_reply_cb)(const capmgr_app_control_h request, /** * @brief Called for each remote application info. - * @since_tizen 5.0 + * @since_tizen 5.5 * * @remarks The @a remote_app_info can be used only in the callback. To use outside, make a copy. * @param[in] remote_app_info Capability Manager Application Info handle * @param[in] user_data The user data to be passed to the callback function - * @see capmgr_application_info_foreach_applications() - * @see capmgr_application_info_clone() + * @see capmgr_app_info_foreach_application() + * @see capmgr_app_info_clone() */ -typedef int (*capmgr_application_info_foreach_app_cb)( - const capmgr_application_info_h remote_app_info, void* user_data); +typedef int (*capmgr_app_info_foreach_app_cb)( + const capmgr_app_info_h remote_app_info, void* user_data); /** * @brief Retrieves all remote device info stored on local device. - * @since_tizen 5.0 + * @details This function iterates over the Capability Manager enabled devices in the local network. + * @since_tizen 5.5 * * @param[in] cb The callback function to invoke * @param[in] user_data The user data to be passed to the callback function @@ -117,12 +126,13 @@ typedef int (*capmgr_application_info_foreach_app_cb)( * @see capmgr_device_foreach_cb() * */ -int capmgr_device_foreach_devices(capmgr_device_foreach_cb cb, - void* user_data); +int capmgr_device_foreach_device(capmgr_device_foreach_cb cb, void* user_data); /** - * @brief Clones the remote device information handle. - * @since_tizen 5.0 + * @brief Clones the remote device information handle received from capmgr_device_foreach_device(). + * @since_tizen 5.5 + * + * @remarks You must release @a device_clone using capmgr_device_destroy(). * @param[in] device The remote device handle * @param[out] device_clone A newly created remote device information handle, if successfully cloned * @return @c 0 on success, @@ -136,20 +146,20 @@ int capmgr_device_clone(const capmgr_device_h device, /** * @brief Destroys the remote device information handle and releases all its resources. - * @since_tizen 5.0 + * @since_tizen 5.5 * @param[in] device The remote device information handle * @return @c 0 on success, * otherwise a negative error value * @retval #CAPMGR_ERROR_NONE Successful * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter * @see capmgr_device_clone() - * @see capmgr_device_foreach_devices() + * @see capmgr_device_foreach_device() */ int capmgr_device_destroy(capmgr_device_h device); /** - * @brief Gets the device ID with the given remote device context. - * @since_tizen 5.0 + * @brief Gets the device ID of the given remote device context. + * @since_tizen 5.5 * @remarks You must release @a device_id using free(). * @param[in] device The remote device information handle * @param[out] device_id The remote device ID of the given remote device context @@ -159,13 +169,13 @@ int capmgr_device_destroy(capmgr_device_h device); * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory * @see capmgr_device_clone() - * @see capmgr_device_foreach_devices() + * @see capmgr_device_foreach_device() */ int capmgr_device_get_device_id(capmgr_device_h device, char** device_id); /** - * @brief Gets the model name with the given remote device context. - * @since_tizen 5.0 + * @brief Gets the model name of the given remote device context. + * @since_tizen 5.5 * @remarks You must release @a model_name using free(). * @param[in] device The remote device information handle * @param[out] model_name The model name of the given remote device context @@ -175,13 +185,13 @@ int capmgr_device_get_device_id(capmgr_device_h device, char** device_id); * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory * @see capmgr_device_clone() - * @see capmgr_device_foreach_devices() + * @see capmgr_device_foreach_device() */ int capmgr_device_get_model_name(capmgr_device_h device, char** model_name); /** - * @brief Gets the device name with the given remote device context. - * @since_tizen 5.0 + * @brief Gets the device name of the given remote device context. + * @since_tizen 5.5 * @remarks You must release @a device_name using free(). * @param[in] device The remote device information handle * @param[out] device_name The device name of the given remote device context @@ -191,13 +201,13 @@ int capmgr_device_get_model_name(capmgr_device_h device, char** model_name); * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory * @see capmgr_device_clone() - * @see capmgr_device_foreach_devices() + * @see capmgr_device_foreach_device() */ int capmgr_device_get_device_name(capmgr_device_h device, char** device_name); /** - * @brief Gets the platform verion with the given remote device context. - * @since_tizen 5.0 + * @brief Gets the platform verion of the given remote device context. + * @since_tizen 5.5 * @remarks You must release @a platform_ver using free(). * @param[in] device The remote device information handle * @param[out] platform_ver The platform version of the given remote device context @@ -207,13 +217,13 @@ int capmgr_device_get_device_name(capmgr_device_h device, char** device_name); * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory * @see capmgr_device_clone() - * @see capmgr_device_foreach_devices() + * @see capmgr_device_foreach_device() */ int capmgr_device_get_platform_ver(capmgr_device_h device, char** platform_ver); /** - * @brief Gets the profile with the given remote device context. - * @since_tizen 5.0 + * @brief Gets the profile of the given remote device context. + * @since_tizen 5.5 * @remarks You must release @a profile using free(). * @param[in] device The remote device information handle * @param[out] profile The profile value of the given remote device context @@ -223,13 +233,13 @@ int capmgr_device_get_platform_ver(capmgr_device_h device, char** platform_ver); * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory * @see capmgr_device_clone() - * @see capmgr_device_foreach_devices() + * @see capmgr_device_foreach_device() */ int capmgr_device_get_profile(capmgr_device_h device, char** profile); /** - * @brief Gets the software verion with the given remote device context. - * @since_tizen 5.0 + * @brief Gets the software verion of the given remote device context. + * @since_tizen 5.5 * @remarks You must release @a sw_ver using free(). * @param[in] device The remote device information handle * @param[out] sw_ver The software version of the given remote device context @@ -239,13 +249,13 @@ int capmgr_device_get_profile(capmgr_device_h device, char** profile); * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory * @see capmgr_device_clone() - * @see capmgr_device_foreach_devices() + * @see capmgr_device_foreach_device() */ int capmgr_device_get_sw_ver(capmgr_device_h device, char** sw_ver); /** * @brief Creates a remote app control handle. - * @since_tizen 5.0 + * @since_tizen 5.5 * @remarks You must release @a app_control using capmgr_app_control_destroy(). * * @param[out] app_control The remote app control handle that is newly created on success @@ -262,7 +272,8 @@ int capmgr_app_control_create(capmgr_app_control_h* app_control); /** * @brief Clones the remote app control handle. - * @since_tizen 5.0 + * @since_tizen 5.5 + * @remarks The newly created app_control should be destroyed by calling the capmgr_app_control_destroy() if it is no longer needed. * @param[in] app_control The remote app control handle * @param[out] app_control_clone A newly created remote app control handle, if successfully cloned * @return @c 0 on success, @@ -276,7 +287,7 @@ int capmgr_app_control_clone(const capmgr_app_control_h app_control, /** * @brief Destroys the remote app control handle and releases all its resources. - * @since_tizen 5.0 + * @since_tizen 5.5 * @param[in] app_control The remote app control handle * @return @c 0 on success, * otherwise a negative error value @@ -288,7 +299,7 @@ int capmgr_app_control_destroy(capmgr_app_control_h app_control); /** * @brief Gets the remote device handle from the given app control context. - * @since_tizen 5.0 + * @since_tizen 5.5 * @remarks You must release @a device using capmgr_device_destroy(). * @param[in] app_control The remote app control handle * @param[out] device The remote device handle @@ -304,7 +315,7 @@ int capmgr_app_control_get_device(capmgr_app_control_h app_control, /** * @brief Gets the operation value from the given remote app control context. - * @since_tizen 5.0 + * @since_tizen 5.5 * @remarks You must release @a operation using free(). * @param[in] app_control The remote app control handle * @param[out] operation The operation value @@ -320,7 +331,7 @@ int capmgr_app_control_get_operation(capmgr_app_control_h app_control, /** * @brief Gets the URI value from the given remote app control context. - * @since_tizen 5.0 + * @since_tizen 5.5 * @remarks You must release @a uri using free(). * @param[in] app_control The remote app control handle * @param[out] uri The URI value @@ -336,7 +347,7 @@ int capmgr_app_control_get_uri(capmgr_app_control_h app_control, /** * @brief Gets the MIME value from the given remote app control context. - * @since_tizen 5.0 + * @since_tizen 5.5 * @remarks You must release @a mime using free(). * @param[in] app_control The remote app control handle * @param[out] mime The MIME value @@ -352,7 +363,7 @@ int capmgr_app_control_get_mime(capmgr_app_control_h app_control, /** * @brief Gets the application ID from the given remote app control context. - * @since_tizen 5.0 + * @since_tizen 5.5 * @remarks You must release @a appid using free(). * @param[in] app_control The remote app control handle * @param[out] appid The application ID @@ -368,7 +379,7 @@ int capmgr_app_control_get_appid(capmgr_app_control_h app_control, /** * @brief Gets the extra data corresponding to given key from remote app control context. - * @since_tizen 5.0 + * @since_tizen 5.5 * @remarks You must release @a value using free(). * @param[in] app_control The remote app control handle * @param[in] key The key value @@ -385,7 +396,7 @@ int capmgr_app_control_get_extra_data(capmgr_app_control_h app_control, /** * @brief Sets the target remote device to given remote app control context. - * @since_tizen 5.0 + * @since_tizen 5.5 * @param[in] app_control The remote app control handle * @param[in] device The remote device handle to set * @return @c 0 on success, @@ -399,7 +410,7 @@ int capmgr_app_control_set_device(capmgr_app_control_h app_control, /** * @brief Sets the operation value to given remote app control context. - * @since_tizen 5.0 + * @since_tizen 5.5 * @param[in] app_control The remote app control handle * @param[in] operation The operation value to set * @return @c 0 on success, @@ -413,7 +424,7 @@ int capmgr_app_control_set_operation(capmgr_app_control_h app_control, /** * @brief Sets the URI value to given remote app control context. - * @since_tizen 5.0 + * @since_tizen 5.5 * @param[in] app_control The remote app control handle * @param[in] uri The URI value to set * @return @c 0 on success, @@ -427,7 +438,7 @@ int capmgr_app_control_set_uri(capmgr_app_control_h app_control, /** * @brief Sets the MIME value to given remote app control context. - * @since_tizen 5.0 + * @since_tizen 5.5 * @param[in] app_control The remote app control handle * @param[in] mime The MIME value to set * @return @c 0 on success, @@ -441,7 +452,7 @@ int capmgr_app_control_set_mime(capmgr_app_control_h app_control, /** * @brief Sets the application ID to given remote app control context. - * @since_tizen 5.0 + * @since_tizen 5.5 * @param[in] app_control The remote app control handle * @param[in] appid The application ID to set * @return @c 0 on success, @@ -455,7 +466,7 @@ int capmgr_app_control_set_appid(capmgr_app_control_h app_control, /** * @brief Sets the extra data to given remote app control context. - * @since_tizen 5.0 + * @since_tizen 5.5 * @param[in] app_control The remote app control handle * @param[in] key The key of extra data to set * @param[in] value The value corresponding to key. @@ -470,7 +481,7 @@ int capmgr_app_control_add_extra_data(capmgr_app_control_h app_control, /** * @brief Removes the extra data corresponding to given key at remote app control context. - * @since_tizen 5.0 + * @since_tizen 5.5 * @param[in] app_control The remote app control handle * @param[in] key The key of extra data to remove * @return @c 0 on success, @@ -484,7 +495,11 @@ int capmgr_app_control_remove_extra_data(capmgr_app_control_h app_control, /** * @brief Sends the app control to remote device specified at handle. - * @since_tizen 5.0 + * @remark The remote app should declare %http://tizen.org/privilege/d2d.remotelaunch privilege for receive. + * @since_tizen 5.5 + * @privlevel public + * @privilege %http://tizen.org/privilege/d2d.datasharing + * @privilege %http://tizen.org/privilege/appmanager.launch * @param[in] app_control The remote app control handle * @param[in] cb Callback to be invoked when send has done * @param[in] user_data The user data to be passed to the callback function @@ -493,13 +508,14 @@ int capmgr_app_control_remove_extra_data(capmgr_app_control_h app_control, * @retval #CAPMGR_ERROR_NONE Successful * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CAPMGR_ERROR_PERMISSION_DENIED Permission denied */ int capmgr_app_control_send(capmgr_app_control_h app_control, capmgr_app_control_reply_cb cb, void* user_data); /** - * @brief Retrieves all applications installed at specified remote device and invoke callback each of it. - * @since_tizen 5.0 + * @brief Retrieves all applications installed on the specified remote device and invokes the callback each of them. + * @since_tizen 5.5 * @param[in] device The remote device handle * @param[in] cb Callback to be invoked for each application * @param[in] user_data The user data to be passed to the callback function @@ -510,14 +526,15 @@ int capmgr_app_control_send(capmgr_app_control_h app_control, * @retval #CAPMGR_ERROR_IO_ERROR I/O error * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory */ -int capmgr_application_info_foreach_applications( +int capmgr_app_info_foreach_application( const capmgr_device_h device, - capmgr_application_info_foreach_app_cb cb, + capmgr_app_info_foreach_app_cb cb, void* user_data); /** * @brief Clones the remote application information handle. - * @since_tizen 5.0 + * @since_tizen 5.5 + * @remarks The newly created app_info should be destroyed by calling the capmgr_app_info_destroy() if it is no longer needed. * @param[in] remote_app_info The remote application info handle * @param[out] remote_app_info_clone A newly created remote application information handle, if successfully cloned * @return @c 0 on success, @@ -525,17 +542,17 @@ int capmgr_application_info_foreach_applications( * @retval #CAPMGR_ERROR_NONE Successful * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory - * @see capmgr_application_info_destroy() + * @see capmgr_app_info_destroy() */ -int capmgr_application_info_clone( - const capmgr_application_info_h remote_app_info, - capmgr_application_info_h* remote_app_info_clone); +int capmgr_app_info_clone( + const capmgr_app_info_h remote_app_info, + capmgr_app_info_h* remote_app_info_clone); /** * @brief Gets the application ID from given remote application information. - * @since_tizen 5.0 + * @since_tizen 5.5 * @remarks You must release @a appid using free(). - * @param[in] remote_app_info The application information installed at specific remote device + * @param[in] remote_app_info The application information installed on the specific remote device * @param[out] appid The application ID * @return @c 0 on success, * otherwise a negative error value @@ -543,14 +560,14 @@ int capmgr_application_info_clone( * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory */ -int capmgr_application_info_get_appid(capmgr_application_info_h remote_app_info, +int capmgr_app_info_get_appid(capmgr_app_info_h remote_app_info, char** appid); /** * @brief Gets the package ID from given remote application information. - * @since_tizen 5.0 + * @since_tizen 5.5 * @remarks You must release @a pkgid using free(). - * @param[in] remote_app_info The application information installed at specific remote device + * @param[in] remote_app_info The application information installed on the specific remote device * @param[out] pkgid The package ID * @return @c 0 on success, * otherwise a negative error value @@ -558,14 +575,14 @@ int capmgr_application_info_get_appid(capmgr_application_info_h remote_app_info, * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory */ -int capmgr_application_info_get_pkgid(capmgr_application_info_h remote_app_info, +int capmgr_app_info_get_pkgid(capmgr_app_info_h remote_app_info, char** pkgid); /** * @brief Gets the label from given remote application information. - * @since_tizen 5.0 + * @since_tizen 5.5 * @remarks You must release @a label using free(). - * @param[in] remote_app_info The application information installed at specific remote device + * @param[in] remote_app_info The application information installed on the specific remote device * @param[out] label The label of application * @return @c 0 on success, * otherwise a negative error value @@ -573,14 +590,14 @@ int capmgr_application_info_get_pkgid(capmgr_application_info_h remote_app_info, * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory */ -int capmgr_application_info_get_label(capmgr_application_info_h remote_app_info, +int capmgr_app_info_get_label(capmgr_app_info_h remote_app_info, char** label); /** * @brief Gets the version from given remote application information. - * @since_tizen 5.0 + * @since_tizen 5.5 * @remarks You must release @a version using free(). - * @param[in] remote_app_info The application information installed at specific remote device + * @param[in] remote_app_info The application information installed on the specific remote device * @param[out] version The version of application * @return @c 0 on success, * otherwise a negative error value @@ -588,14 +605,14 @@ int capmgr_application_info_get_label(capmgr_application_info_h remote_app_info, * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory */ -int capmgr_application_info_get_version( - capmgr_application_info_h remote_app_info, char** version); +int capmgr_app_info_get_version( + capmgr_app_info_h remote_app_info, char** version); /** * @brief Gets the remote device handle from the given remote application info context. - * @since_tizen 5.0 + * @since_tizen 5.5 * @remarks You must release @a device using capmgr_device_destroy(). - * @param[in] remote_app_info The application information installed at specific remote device + * @param[in] remote_app_info The application information installed on the specific remote device * @param[out] device The remote device handle * @return @c 0 on success, * otherwise a negative error value @@ -603,20 +620,20 @@ int capmgr_application_info_get_version( * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CAPMGR_ERROR_OUT_OF_MEMORY Out of memory */ -int capmgr_application_info_get_device( - capmgr_application_info_h remote_app_info, capmgr_device_h* device); +int capmgr_app_info_get_device( + capmgr_app_info_h remote_app_info, capmgr_device_h* device); /** * @brief Destroys the remote application information handle and releases all its resources. - * @since_tizen 5.0 + * @since_tizen 5.5 * @param[in] remote_app_info The remote application information handle * @return @c 0 on success, * otherwise a negative error value * @retval #CAPMGR_ERROR_NONE Successful * @retval #CAPMGR_ERROR_INVALID_PARAMETER Invalid parameter - * @see capmgr_application_info_clone() + * @see capmgr_app_info_clone() */ -int capmgr_application_info_destroy(capmgr_application_info_h remote_app_info); +int capmgr_app_info_destroy(capmgr_app_info_h remote_app_info); #ifdef __cplusplus } diff --git a/src/client.cc b/src/client.cc index fa2030a..6a6ffcb 100644 --- a/src/client.cc +++ b/src/client.cc @@ -42,7 +42,7 @@ struct capmgr_app_control_s { bundle* b; }; -struct capmgr_application_info_s { +struct capmgr_app_info_s { std::string appid; std::string pkgid; std::string label; @@ -50,7 +50,7 @@ struct capmgr_application_info_s { capmgr_device_h device; }; -API int capmgr_device_foreach_devices(capmgr_device_foreach_cb cb, +API int capmgr_device_foreach_device(capmgr_device_foreach_cb cb, void* user_data) { if (!cb) return CAPMGR_ERROR_INVALID_PARAMETER; @@ -544,15 +544,15 @@ API int capmgr_app_control_send(capmgr_app_control_h app_control, return CAPMGR_ERROR_NONE; } -API int capmgr_application_info_clone( - const capmgr_application_info_h remote_app_info, - capmgr_application_info_h* remote_app_info_clone) { +API int capmgr_app_info_clone( + const capmgr_app_info_h remote_app_info, + capmgr_app_info_h* remote_app_info_clone) { if (!remote_app_info || !remote_app_info_clone) return CAPMGR_ERROR_INVALID_PARAMETER; - struct capmgr_application_info_s* clone; + struct capmgr_app_info_s* clone; try { - clone = new struct capmgr_application_info_s(); + clone = new struct capmgr_app_info_s(); } catch (const std::bad_alloc& e) { LOG(ERROR) << e.what(); return CAPMGR_ERROR_OUT_OF_MEMORY; @@ -575,8 +575,8 @@ API int capmgr_application_info_clone( return CAPMGR_ERROR_NONE; } -API int capmgr_application_info_destroy( - capmgr_application_info_h remote_app_info) { +API int capmgr_app_info_destroy( + capmgr_app_info_h remote_app_info) { if (!remote_app_info) return CAPMGR_ERROR_INVALID_PARAMETER; @@ -586,8 +586,8 @@ API int capmgr_application_info_destroy( return CAPMGR_ERROR_NONE; } -API int capmgr_application_info_get_appid( - capmgr_application_info_h remote_app_info, char** appid) { +API int capmgr_app_info_get_appid( + capmgr_app_info_h remote_app_info, char** appid) { if (!remote_app_info || !appid || remote_app_info->appid.empty()) return CAPMGR_ERROR_INVALID_PARAMETER; @@ -598,8 +598,8 @@ API int capmgr_application_info_get_appid( return CAPMGR_ERROR_NONE; } -API int capmgr_application_info_get_pkgid( - capmgr_application_info_h remote_app_info, char** pkgid) { +API int capmgr_app_info_get_pkgid( + capmgr_app_info_h remote_app_info, char** pkgid) { if (!remote_app_info || !pkgid || remote_app_info->pkgid.empty()) return CAPMGR_ERROR_INVALID_PARAMETER; @@ -610,8 +610,8 @@ API int capmgr_application_info_get_pkgid( return CAPMGR_ERROR_NONE; } -API int capmgr_application_info_get_label( - capmgr_application_info_h remote_app_info, char** label) { +API int capmgr_app_info_get_label( + capmgr_app_info_h remote_app_info, char** label) { if (!remote_app_info || !label || remote_app_info->label.empty()) return CAPMGR_ERROR_INVALID_PARAMETER; @@ -622,8 +622,8 @@ API int capmgr_application_info_get_label( return CAPMGR_ERROR_NONE; } -API int capmgr_application_info_get_version( - capmgr_application_info_h remote_app_info, char** version) { +API int capmgr_app_info_get_version( + capmgr_app_info_h remote_app_info, char** version) { if (!remote_app_info || !version || remote_app_info->version.empty()) return CAPMGR_ERROR_INVALID_PARAMETER; @@ -634,8 +634,8 @@ API int capmgr_application_info_get_version( return CAPMGR_ERROR_NONE; } -API int capmgr_application_info_get_device( - capmgr_application_info_h remote_app_info, +API int capmgr_app_info_get_device( + capmgr_app_info_h remote_app_info, capmgr_device_h* device) { if (!remote_app_info || !device) return CAPMGR_ERROR_INVALID_PARAMETER; @@ -647,9 +647,9 @@ API int capmgr_application_info_get_device( return CAPMGR_ERROR_NONE; } -API int capmgr_application_info_foreach_applications( +API int capmgr_app_info_foreach_application( const capmgr_device_h device, - capmgr_application_info_foreach_app_cb cb, + capmgr_app_info_foreach_app_cb cb, void* user_data) { if (!device || !cb) return CAPMGR_ERROR_INVALID_PARAMETER; @@ -668,7 +668,7 @@ API int capmgr_application_info_foreach_applications( if (stmt->BindString(1, device->device_id)) { while (stmt->Step() == capmgr::SQLStatement::StepResult::ROW) { - struct capmgr_application_info_s info; + struct capmgr_app_info_s info; int idx = 0; info.appid = stmt->GetColumnString(idx++); info.pkgid = stmt->GetColumnString(idx++); diff --git a/src/unit_tests/unit_test.cc b/src/unit_tests/unit_test.cc index ae68e56..3d19410 100644 --- a/src/unit_tests/unit_test.cc +++ b/src/unit_tests/unit_test.cc @@ -22,10 +22,10 @@ int DeviceForeachCbForSetup(const capmgr_device_h device, void* user_data) { } int ApplicationForeachCbForSetup( - const capmgr_application_info_h remote_app_info, void* user_data) { - capmgr_application_info_h* clone = - reinterpret_cast(user_data); - int ret = capmgr_application_info_clone(remote_app_info, clone); + const capmgr_app_info_h remote_app_info, void* user_data) { + capmgr_app_info_h* clone = + reinterpret_cast(user_data); + int ret = capmgr_app_info_clone(remote_app_info, clone); if (ret != CAPMGR_ERROR_NONE) return 0; // use the first app @@ -39,13 +39,13 @@ int DeviceForeachCb(const capmgr_device_h device, void* user_data) { return 1; } -int ApplicationForeachCb(const capmgr_application_info_h remote_app_info, +int ApplicationForeachCb(const capmgr_app_info_h remote_app_info, void* user_data) { bool* is_hit = reinterpret_cast(user_data); *is_hit = true; char* appid; - capmgr_application_info_get_appid(remote_app_info, &appid); + capmgr_app_info_get_appid(remote_app_info, &appid); free(appid); LOG(INFO) << appid; return 0; @@ -59,7 +59,7 @@ class TestEnvironment : public ::testing::Environment { TestEnvironment() : device_(nullptr), app_control_(nullptr), app_(nullptr) {} void SetUp() override { - ASSERT_EQ(capmgr_device_foreach_devices(DeviceForeachCbForSetup, &device_), + ASSERT_EQ(capmgr_device_foreach_device(DeviceForeachCbForSetup, &device_), CAPMGR_ERROR_NONE) << "Failed to init test environment!"; ASSERT_NE(device_, nullptr); char* device_id; @@ -80,18 +80,18 @@ class TestEnvironment : public ::testing::Environment { CAPMGR_ERROR_NONE); ASSERT_EQ(capmgr_app_control_add_extra_data(app_control_, kExtraDataKeyStr, kExtraDataValueStr), CAPMGR_ERROR_NONE); - ASSERT_EQ(capmgr_application_info_foreach_applications(device_, + ASSERT_EQ(capmgr_app_info_foreach_application(device_, ApplicationForeachCbForSetup, &app_), CAPMGR_ERROR_NONE); } void TearDown() override { - capmgr_application_info_destroy(app_); + capmgr_app_info_destroy(app_); capmgr_app_control_destroy(app_control_); capmgr_device_destroy(device_); } capmgr_device_h device_; capmgr_app_control_h app_control_; - capmgr_application_info_h app_; + capmgr_app_info_h app_; }; TestEnvironment* env = nullptr; @@ -108,13 +108,13 @@ class UnitTest : public ::testing::Test { TEST_F(UnitTest, DeviceForeachDevicesPositiveTest) { bool is_hit = false; - ASSERT_EQ(capmgr_device_foreach_devices(DeviceForeachCb, &is_hit), + ASSERT_EQ(capmgr_device_foreach_device(DeviceForeachCb, &is_hit), CAPMGR_ERROR_NONE); ASSERT_TRUE(is_hit); } TEST_F(UnitTest, DeviceForeachDevicesNegativeTest) { - ASSERT_EQ(capmgr_device_foreach_devices(nullptr, nullptr), + ASSERT_EQ(capmgr_device_foreach_device(nullptr, nullptr), CAPMGR_ERROR_INVALID_PARAMETER); } @@ -347,25 +347,25 @@ TEST_F(UnitTest, AppControlSendNegativeTest) { } */ -TEST_F(UnitTest, ApplicationInfoForeachPackagesPositiveTest) { +TEST_F(UnitTest, AppInfoForeachPackagesPositiveTest) { bool is_hit = false; - ASSERT_EQ(capmgr_application_info_foreach_applications(env->device_, + ASSERT_EQ(capmgr_app_info_foreach_application(env->device_, ApplicationForeachCb, &is_hit), CAPMGR_ERROR_NONE); ASSERT_TRUE(is_hit); } -TEST_F(UnitTest, ApplicationInfoForeachPackagesNegativeTest) { - ASSERT_EQ(capmgr_application_info_foreach_applications(nullptr, +TEST_F(UnitTest, AppInfoForeachPackagesNegativeTest) { + ASSERT_EQ(capmgr_app_info_foreach_application(nullptr, ApplicationForeachCb, nullptr), CAPMGR_ERROR_INVALID_PARAMETER); - ASSERT_EQ(capmgr_application_info_foreach_applications(env->device_, + ASSERT_EQ(capmgr_app_info_foreach_application(env->device_, nullptr, nullptr), CAPMGR_ERROR_INVALID_PARAMETER); } -#define APPLICATION_INFO_GET_TEST_BLOCK( \ +#define APP_INFO_GET_TEST_BLOCK( \ POSITIVE_TESTNAME, NEGATIVE_TESTNAME, ATTR) \ TEST_F(UnitTest, POSITIVE_TESTNAME) { \ char* ATTR = nullptr; \ - ASSERT_EQ(capmgr_application_info_get_##ATTR(env->app_, &ATTR), \ + ASSERT_EQ(capmgr_app_info_get_##ATTR(env->app_, &ATTR), \ CAPMGR_ERROR_NONE); \ ASSERT_NE(ATTR, nullptr); \ free(ATTR); \ @@ -373,23 +373,23 @@ TEST_F(UnitTest, POSITIVE_TESTNAME) { \ \ TEST_F(UnitTest, NEGATIVE_TESTNAME) { \ char* ATTR; \ - ASSERT_EQ(capmgr_application_info_get_##ATTR(nullptr, &ATTR), \ + ASSERT_EQ(capmgr_app_info_get_##ATTR(nullptr, &ATTR), \ CAPMGR_ERROR_INVALID_PARAMETER); \ - ASSERT_EQ(capmgr_application_info_get_##ATTR(env->app_, nullptr), \ + ASSERT_EQ(capmgr_app_info_get_##ATTR(env->app_, nullptr), \ CAPMGR_ERROR_INVALID_PARAMETER); \ } \ -APPLICATION_INFO_GET_TEST_BLOCK(ApplicationInfoGetAppidPositiveTest, - ApplicationInfoGetAppidNegativeTest, appid) +APP_INFO_GET_TEST_BLOCK(AppInfoGetAppidPositiveTest, + AppInfoGetAppidNegativeTest, appid) -APPLICATION_INFO_GET_TEST_BLOCK(ApplicationInfoGetPkgidPositiveTest, - ApplicationInfoGetPkgidNegativeTest, pkgid) +APP_INFO_GET_TEST_BLOCK(AppInfoGetPkgidPositiveTest, + AppInfoGetPkgidNegativeTest, pkgid) -APPLICATION_INFO_GET_TEST_BLOCK(ApplicationInfoGetLabelPositiveTest, - ApplicationInfoGetLabelNegativeTest, label) +APP_INFO_GET_TEST_BLOCK(AppInfoGetLabelPositiveTest, + AppInfoGetLabelNegativeTest, label) -APPLICATION_INFO_GET_TEST_BLOCK(ApplicationInfoGetVersionPositiveTest, - ApplicationInfoGetVersionNegativeTest, version) +APP_INFO_GET_TEST_BLOCK(AppInfoGetVersionPositiveTest, + AppInfoGetVersionNegativeTest, version) } // namespace capmgr diff --git a/tools/capmgr_test.cc b/tools/capmgr_test.cc index b2adec7..789bf9c 100644 --- a/tools/capmgr_test.cc +++ b/tools/capmgr_test.cc @@ -113,7 +113,7 @@ int DeviceForeachCb(const capmgr_device_h device, void* user_data) { return 0; } -int AppForeachCb(const capmgr_application_info_h remote_app_info, +int AppForeachCb(const capmgr_app_info_h remote_app_info, void* user_data) { char* appid = nullptr; char* pkgid = nullptr; @@ -122,23 +122,23 @@ int AppForeachCb(const capmgr_application_info_h remote_app_info, capmgr_device_h device = nullptr; char* device_id = nullptr; - int ret = capmgr_application_info_get_appid(remote_app_info, &appid); + int ret = capmgr_app_info_get_appid(remote_app_info, &appid); if (ret != CAPMGR_ERROR_NONE) std::cout << "Failed to get appid" << std::endl; - ret = capmgr_application_info_get_pkgid(remote_app_info, &pkgid); + ret = capmgr_app_info_get_pkgid(remote_app_info, &pkgid); if (ret != CAPMGR_ERROR_NONE) std::cout << "Failed to get pkgid" << std::endl; - ret = capmgr_application_info_get_label(remote_app_info, &label); + ret = capmgr_app_info_get_label(remote_app_info, &label); if (ret != CAPMGR_ERROR_NONE) std::cout << "Failed to get label" << std::endl; - ret = capmgr_application_info_get_version(remote_app_info, &ver); + ret = capmgr_app_info_get_version(remote_app_info, &ver); if (ret != CAPMGR_ERROR_NONE) std::cout << "Failed to get pkgid" << std::endl; - ret = capmgr_application_info_get_device(remote_app_info, &device); + ret = capmgr_app_info_get_device(remote_app_info, &device); if (ret != CAPMGR_ERROR_NONE) std::cout << "Failed to get device" << std::endl; @@ -211,9 +211,9 @@ void Client::SendAppControl(const std::string& device_id, capmgr_device_h device = nullptr; struct cbdata cbdata = {&device, device_id}; - int ret = capmgr_device_foreach_devices(DeviceForeachCb, &cbdata); + int ret = capmgr_device_foreach_device(DeviceForeachCb, &cbdata); if (ret != CAPMGR_ERROR_NONE) { - std::cout << "capmgr_device_foreach_devices() failed: " << ret + std::cout << "capmgr_device_foreach_device() failed: " << ret << std::endl; return; } @@ -261,9 +261,9 @@ void Client::SendAppControl(const std::string& device_id, } void Client::ListDevices() { - int ret = capmgr_device_foreach_devices(DeviceForeachCb, nullptr); + int ret = capmgr_device_foreach_device(DeviceForeachCb, nullptr); if (ret != CAPMGR_ERROR_NONE) - std::cout << "capmgr_device_foreach_devices() failed: " << ret + std::cout << "capmgr_device_foreach_device() failed: " << ret << std::endl; } @@ -275,9 +275,9 @@ void Client::ListAppinfos(const std::string& device_id) { capmgr_device_h device = nullptr; struct cbdata cbdata = {&device, device_id}; - int ret = capmgr_device_foreach_devices(DeviceForeachCb, &cbdata); + int ret = capmgr_device_foreach_device(DeviceForeachCb, &cbdata); if (ret != CAPMGR_ERROR_NONE) { - std::cout << "capmgr_device_foreach_devices() failed: " << ret + std::cout << "capmgr_device_foreach_device() failed: " << ret << std::endl; return; } @@ -288,10 +288,10 @@ void Client::ListAppinfos(const std::string& device_id) { } std::cout << "Target device is " < Date: Thu, 18 Apr 2019 11:06:34 +0900 Subject: [PATCH 14/16] Fix static analysis issues Change-Id: If18854531d0555fcec4e1f65994b600f50334b69 --- src/client.cc | 6 ++--- src/dbus.cc | 3 ++- src/unit_tests/unit_test.cc | 59 +++++++++++++++++++++++++++++---------------- tools/capmgr_test.cc | 1 + 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/client.cc b/src/client.cc index 6a6ffcb..4c95d1c 100644 --- a/src/client.cc +++ b/src/client.cc @@ -192,19 +192,17 @@ API int capmgr_app_control_create(capmgr_app_control_h* app_control) { return CAPMGR_ERROR_INVALID_PARAMETER; try { - struct capmgr_app_control_s* control = new struct capmgr_app_control_s(); + std::unique_ptr control(new capmgr_app_control_s()); control->b = bundle_create(); if (!control->b) { - delete control; return CAPMGR_ERROR_OUT_OF_MEMORY; } int r = aul_svc_set_operation(control->b, AUL_SVC_OPERATION_DEFAULT); if (r != AUL_SVC_RET_OK) { bundle_free(control->b); - delete control; return CAPMGR_ERROR_OUT_OF_MEMORY; } - *app_control = control; + *app_control = control.release(); } catch (const std::bad_alloc& e) { LOG(ERROR) << e.what(); return CAPMGR_ERROR_OUT_OF_MEMORY; diff --git a/src/dbus.cc b/src/dbus.cc index ec092d9..93627c3 100644 --- a/src/dbus.cc +++ b/src/dbus.cc @@ -88,7 +88,8 @@ void DisposeDBusProxy(GDBusConnection* conn, GDBusProxy* proxy) { namespace capmgr { DBusSignal::DBusSignal(const std::string& signal_name) - : signal_name_ { signal_name } {} + : signal_name_{ signal_name }, cb_ { nullptr }, user_data_ { nullptr }, + proxy_ { nullptr }, conn_ { nullptr } {} DBusSignal::~DBusSignal() { DisposeDBusProxy(this->conn_, this->proxy_); diff --git a/src/unit_tests/unit_test.cc b/src/unit_tests/unit_test.cc index 3d19410..e9f439f 100644 --- a/src/unit_tests/unit_test.cc +++ b/src/unit_tests/unit_test.cc @@ -120,8 +120,13 @@ TEST_F(UnitTest, DeviceForeachDevicesNegativeTest) { TEST_F(UnitTest, DeviceClonePositiveTest) { // need to get device - capmgr_device_h clone; - ASSERT_EQ(capmgr_device_clone(env->device_, &clone), CAPMGR_ERROR_NONE); + capmgr_device_h clone = nullptr; + int ret; + ret = capmgr_device_clone(env->device_, &clone); + if (clone && ret == CAPMGR_ERROR_NONE) + capmgr_device_destroy(clone); + + ASSERT_EQ(ret, CAPMGR_ERROR_NONE); } TEST_F(UnitTest, DeviceCloneNegativeTest) { @@ -133,10 +138,15 @@ TEST_F(UnitTest, DeviceCloneNegativeTest) { } TEST_F(UnitTest, DeviceDestroyPositiveTest) { - capmgr_device_h clone; - ASSERT_EQ(capmgr_device_clone(env->device_, &clone), - CAPMGR_ERROR_NONE); - ASSERT_EQ(capmgr_device_destroy(clone), CAPMGR_ERROR_NONE); + capmgr_device_h clone = nullptr; + int ret1 = CAPMGR_ERROR_INVALID_PARAMETER; + int ret2 = CAPMGR_ERROR_INVALID_PARAMETER; + ret1 = capmgr_device_clone(env->device_, &clone); + if (clone && ret1 == CAPMGR_ERROR_NONE) + ret2 = capmgr_device_destroy(clone); + + ASSERT_EQ(ret1, CAPMGR_ERROR_NONE); + ASSERT_EQ(ret2, CAPMGR_ERROR_NONE); } TEST_F(UnitTest, DeviceDestroyNegativeTest) { @@ -146,9 +156,10 @@ TEST_F(UnitTest, DeviceDestroyNegativeTest) { #define DEVICE_GET_TEST_BLOCK(POSITIVE_TESTNAME, NEGATIVE_TESTNAME, ATTR) \ TEST_F(UnitTest, POSITIVE_TESTNAME) { \ char* ATTR = nullptr; \ - ASSERT_EQ(capmgr_device_get_##ATTR(env->device_, &ATTR), CAPMGR_ERROR_NONE); \ + int ret = capmgr_device_get_##ATTR(env->device_, &ATTR); \ ASSERT_NE(ATTR, nullptr); \ free(ATTR); \ + ASSERT_EQ(ret, CAPMGR_ERROR_NONE); \ } \ \ TEST_F(UnitTest, NEGATIVE_TESTNAME) { \ @@ -178,9 +189,11 @@ DEVICE_GET_TEST_BLOCK(DeviceGetSWVerPositiveTest, DeviceGetSWVerNegativeTest, sw_ver) TEST_F(UnitTest, AppControlCreatePositiveTest) { - capmgr_app_control_h app_control; - ASSERT_EQ(capmgr_app_control_create(&app_control), CAPMGR_ERROR_NONE); - capmgr_app_control_destroy(app_control); + capmgr_app_control_h app_control = nullptr; + int ret = capmgr_app_control_create(&app_control); + if (app_control && ret == CAPMGR_ERROR_NONE) + capmgr_app_control_destroy(app_control); + ASSERT_EQ(ret, CAPMGR_ERROR_NONE); } TEST_F(UnitTest, AppControlCreateNegativeTest) { @@ -188,9 +201,10 @@ TEST_F(UnitTest, AppControlCreateNegativeTest) { } TEST_F(UnitTest, AppControlDestroyPositiveTest) { - capmgr_app_control_h app_control; - ASSERT_EQ(capmgr_app_control_create(&app_control), CAPMGR_ERROR_NONE); + capmgr_app_control_h app_control = nullptr; + int ret = capmgr_app_control_create(&app_control); ASSERT_EQ(capmgr_app_control_destroy(app_control), CAPMGR_ERROR_NONE); + ASSERT_EQ(ret, CAPMGR_ERROR_NONE); } TEST_F(UnitTest, AppControlDestroyNegativeTest) { @@ -216,10 +230,10 @@ TEST_F(UnitTest, AppControlGetDeviceNegativeTest) { #define APP_CONTROL_GET_TEST_BLOCK(POSITIVE_TESTNAME, NEGATIVE_TESTNAME, ATTR) \ TEST_F(UnitTest, POSITIVE_TESTNAME) { \ char* ATTR = nullptr; \ - ASSERT_EQ(capmgr_app_control_get_##ATTR(env->app_control_, &ATTR), \ - CAPMGR_ERROR_NONE); \ + int ret = capmgr_app_control_get_##ATTR(env->app_control_, &ATTR); \ ASSERT_NE(ATTR, nullptr); \ free(ATTR); \ + ASSERT_EQ(ret, CAPMGR_ERROR_NONE); \ } \ \ TEST_F(UnitTest, NEGATIVE_TESTNAME) { \ @@ -244,10 +258,11 @@ APP_CONTROL_GET_TEST_BLOCK(AppControlGetAppidPositiveTest, TEST_F(UnitTest, AppControlGetExtraDataPositiveTest) { char* value = nullptr; - ASSERT_EQ(capmgr_app_control_get_extra_data(env->app_control_, - kExtraDataKeyStr, &value), CAPMGR_ERROR_NONE); + int ret = capmgr_app_control_get_extra_data(env->app_control_, + kExtraDataKeyStr, &value); ASSERT_NE(value, nullptr); free(value); + ASSERT_EQ(ret, CAPMGR_ERROR_NONE); } TEST_F(UnitTest, AppControlGetExtraDataNegativeTest) { @@ -323,9 +338,11 @@ TEST_F(UnitTest, AppControlRemoveExtraDataPositiveTest) { capmgr_app_control_remove_extra_data(env->app_control_, "key2"), CAPMGR_ERROR_NONE); // should return such as CAPMGR_ERROR_NO_SUCH_KEY? - char* value; - ASSERT_EQ(capmgr_app_control_get_extra_data(env->app_control_, - "key2", &value), CAPMGR_ERROR_INVALID_PARAMETER); + char* value = nullptr; + int ret = capmgr_app_control_get_extra_data(env->app_control_, "key2", + &value); + free(value); + ASSERT_EQ(ret, CAPMGR_ERROR_INVALID_PARAMETER); } TEST_F(UnitTest, AppControlRemoveExtraDataNegativeTest) { @@ -365,10 +382,10 @@ TEST_F(UnitTest, AppInfoForeachPackagesNegativeTest) { POSITIVE_TESTNAME, NEGATIVE_TESTNAME, ATTR) \ TEST_F(UnitTest, POSITIVE_TESTNAME) { \ char* ATTR = nullptr; \ - ASSERT_EQ(capmgr_app_info_get_##ATTR(env->app_, &ATTR), \ - CAPMGR_ERROR_NONE); \ + int ret = capmgr_app_info_get_##ATTR(env->app_, &ATTR); \ ASSERT_NE(ATTR, nullptr); \ free(ATTR); \ + ASSERT_EQ(ret, CAPMGR_ERROR_NONE); \ } \ \ TEST_F(UnitTest, NEGATIVE_TESTNAME) { \ diff --git a/tools/capmgr_test.cc b/tools/capmgr_test.cc index 789bf9c..f1779fc 100644 --- a/tools/capmgr_test.cc +++ b/tools/capmgr_test.cc @@ -161,6 +161,7 @@ int AppForeachCb(const capmgr_app_info_h remote_app_info, free(appid); free(pkgid); free(label); + free(device_id); free(ver); capmgr_device_destroy(device); -- 2.7.4 From a01775ccd4a48788cd8b314e51f7623ff8d13e5d Mon Sep 17 00:00:00 2001 From: Daehyeon Jung Date: Tue, 23 Apr 2019 11:25:56 +0900 Subject: [PATCH 15/16] Add doxygen header Change-Id: Id588d6e40e2303377ab5cbd318555a347ee0f7d9 Signed-off-by: Daehyeon Jung --- doc/capability_manager_doc.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 doc/capability_manager_doc.h diff --git a/doc/capability_manager_doc.h b/doc/capability_manager_doc.h new file mode 100644 index 0000000..dd1b0f0 --- /dev/null +++ b/doc/capability_manager_doc.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __TIZEN_APPFW_CAPABILITY_MANAGER_DOC_H__ +#define __TIZEN_APPFW_CAPABILITY_MANAGER_DOC_H__ + +/** + * @ingroup CAPI_APPLICATION_FRAMEWORK_MODULE + * @defgroup CAPI_CAPABILITY_MANAGER_MODULE Capability Manager + * @brief The @ref CAPI_CAPABILITY_MANAGER_MODULE API provides functions to launch and query applications in other devices in the local network. + * @section CAPI_CAPABILITY_MANAGER_MODULE_HEADER Required Header + * \#include + * + */ + +#endif /* __TIZEN_APPFW_CAPABILITY_MANAGER_DOC_H__ */ -- 2.7.4 From 626bf247642db7e908a09a353f0867db461b2a9e Mon Sep 17 00:00:00 2001 From: Daehyeon Jung Date: Tue, 23 Apr 2019 14:02:16 +0900 Subject: [PATCH 16/16] Fix typo Change-Id: I31253a965612bf4a6988ee88d0dee335ae1c6e18 --- doc/capability_manager_doc.h | 2 +- include/capability_manager.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/capability_manager_doc.h b/doc/capability_manager_doc.h index dd1b0f0..474d145 100644 --- a/doc/capability_manager_doc.h +++ b/doc/capability_manager_doc.h @@ -19,7 +19,7 @@ #define __TIZEN_APPFW_CAPABILITY_MANAGER_DOC_H__ /** - * @ingroup CAPI_APPLICATION_FRAMEWORK_MODULE + * @ingroup CAPI_APPLICATION_FRAMEWORK * @defgroup CAPI_CAPABILITY_MANAGER_MODULE Capability Manager * @brief The @ref CAPI_CAPABILITY_MANAGER_MODULE API provides functions to launch and query applications in other devices in the local network. * @section CAPI_CAPABILITY_MANAGER_MODULE_HEADER Required Header diff --git a/include/capability_manager.h b/include/capability_manager.h index 4aa9a1b..17da395 100644 --- a/include/capability_manager.h +++ b/include/capability_manager.h @@ -206,7 +206,7 @@ int capmgr_device_get_model_name(capmgr_device_h device, char** model_name); int capmgr_device_get_device_name(capmgr_device_h device, char** device_name); /** - * @brief Gets the platform verion of the given remote device context. + * @brief Gets the platform version of the given remote device context. * @since_tizen 5.5 * @remarks You must release @a platform_ver using free(). * @param[in] device The remote device information handle @@ -238,7 +238,7 @@ int capmgr_device_get_platform_ver(capmgr_device_h device, char** platform_ver); int capmgr_device_get_profile(capmgr_device_h device, char** profile); /** - * @brief Gets the software verion of the given remote device context. + * @brief Gets the software version of the given remote device context. * @since_tizen 5.5 * @remarks You must release @a sw_ver using free(). * @param[in] device The remote device information handle @@ -495,7 +495,7 @@ int capmgr_app_control_remove_extra_data(capmgr_app_control_h app_control, /** * @brief Sends the app control to remote device specified at handle. - * @remark The remote app should declare %http://tizen.org/privilege/d2d.remotelaunch privilege for receive. + * @remarks The remote app should declare %http://tizen.org/privilege/d2d.remotelaunch privilege for receive. * @since_tizen 5.5 * @privlevel public * @privilege %http://tizen.org/privilege/d2d.datasharing -- 2.7.4