From 439452ff5e88014255b816fe7338c8faffd5dc93 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 20 Feb 2020 14:07:51 +0900 Subject: [PATCH 01/16] Add org.tizen.sticker-receiver as dependency Change-Id: I1e6f86460f9f26b2e275a03fe2819fff7abf81ac Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index ed33df1..2e744c0 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -31,6 +31,7 @@ BuildRequires: pkgconfig(sap-client-stub-api) BuildRequires: hash-signer Requires(post): signing-client +Requires: org.tizen.sticker-receiver %endif Requires: security-config -- 2.7.4 From 7901b7e447bf2f404750ed731dbf9053d2e45748 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Thu, 20 Feb 2020 14:01:39 +0900 Subject: [PATCH 02/16] Update package version to 0.1.12 Change-Id: I1c3894a7952856a8f09e5a33a9804b1795ae6778 --- packaging/capi-ui-sticker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 2e744c0..b14c2c2 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -1,6 +1,6 @@ Name: capi-ui-sticker Summary: Sticker client library and daemon -Version: 0.1.11 +Version: 0.1.12 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 -- 2.7.4 From 1882bd6caaadf9728f81b9e03d2cc603cfe938df Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 20 Feb 2020 15:54:11 +0900 Subject: [PATCH 03/16] Fix issue failed to install due to no base directory Change-Id: I73177635916e4f980f357d8b33cfccf65119006c Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index b14c2c2..5cae043 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -167,8 +167,12 @@ chsmack -a "System::Shared" %{TZ_SYS_SHARE}/sticker-data %{_includedir}/sticker_provider.h %if 0%{?sec_product_feature_profile_wearable} +%post -n %{_companion_app_name} +mkdir -p %{TZ_SYS_RO_APP}/%{_companion_app_name} + %files -n %{_companion_app_name} %manifest receiver/%{_companion_app_name}.manifest +%license LICENSE %{TZ_SYS_RO_PACKAGES}/%{_companion_app_name}.xml %{TZ_SYS_RO_APP}/%{_companion_app_name}/* %endif -- 2.7.4 From 23422a723afe9fb8df3c92b88428351cd6aaa3e4 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 20 Feb 2020 15:59:38 +0900 Subject: [PATCH 04/16] Update package version to 0.1.13 Change-Id: I1c3c03ef79ad85459d970fd17a58114799c45db1 Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 5cae043..75149e5 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -1,6 +1,6 @@ Name: capi-ui-sticker Summary: Sticker client library and daemon -Version: 0.1.12 +Version: 0.1.13 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 -- 2.7.4 From 532005322b3bfd3ed780b97e39f2605a9cc42b5b Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 20 Feb 2020 19:47:57 +0900 Subject: [PATCH 05/16] Fix signing issue on wearable device Change-Id: If67e682df5da525ed44a883855706829c72f283d Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 75149e5..87df788 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -137,10 +137,6 @@ chown -R ui_fw:ui_fw %{TZ_SYS_SHARE}/sticker-data chsmack -t %{TZ_SYS_SHARE}/sticker-data chsmack -a "System::Shared" %{TZ_SYS_SHARE}/sticker-data -%if 0%{?sec_product_feature_profile_wearable} -/usr/bin/signing-client/hash-signer-client.sh -a -d -p platform %{TZ_SYS_RO_APP}/%{_companion_app_name} -%endif - %postun -p /sbin/ldconfig %files @@ -168,7 +164,7 @@ chsmack -a "System::Shared" %{TZ_SYS_SHARE}/sticker-data %if 0%{?sec_product_feature_profile_wearable} %post -n %{_companion_app_name} -mkdir -p %{TZ_SYS_RO_APP}/%{_companion_app_name} +/usr/bin/signing-client/hash-signer-client.sh -a -d -p platform %{TZ_SYS_RO_APP}/%{_companion_app_name} %files -n %{_companion_app_name} %manifest receiver/%{_companion_app_name}.manifest -- 2.7.4 From b45853c2b013cfc651a9b024a325b01423edde4d Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 20 Feb 2020 19:48:20 +0900 Subject: [PATCH 06/16] Update package version to 0.1.14 Change-Id: I0189865c1d58bcb461a0db2101b3cc96c2308db6 Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 87df788..7e4cb25 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -1,6 +1,6 @@ Name: capi-ui-sticker Summary: Sticker client library and daemon -Version: 0.1.13 +Version: 0.1.14 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 -- 2.7.4 From 119054284ae25a733a8d54fcac54800a146767ff Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 21 Feb 2020 20:04:14 +0900 Subject: [PATCH 07/16] Remove unused function Change-Id: I288a400ea7ef143a3337b12ee9596f7065682b2b Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index c5ccfbf..133f673 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -215,16 +215,6 @@ void conn_terminated(sap_peer_agent_h peer_agent, } void -on_message_received(sap_peer_agent_h peer_agent, unsigned int payload_length, void *buffer, - void *user_data) /* message exchange on_receive callback (sap_agent_data_received_cb) */ -{ - char *peer_app; - sap_peer_agent_get_app_name(peer_agent, &peer_app); - dlog_print(DLOG_INFO, TAG, "received data: %s, len:%d from %s", (char *)buffer, payload_length, peer_app); - g_free(peer_app); -} - -void on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned int payload_length, void *buffer, void *user_data) /* message exchange on_receive callback (sap_agent_data_received_cb) */ { -- 2.7.4 From 29f80e1fc8fd0b8d58645047709a5a488e7c7995 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Mon, 24 Feb 2020 17:12:56 +0900 Subject: [PATCH 08/16] Change log format in sticker-receiver Change-Id: Id5730c2353be61cfc35804e6e519269224e594b2 Signed-off-by: Jihoon Kim --- receiver/inc/log.h | 6 ++- receiver/inc/main.h | 2 - receiver/inc/sticker_info.h | 2 - receiver/src/ft.cpp | 87 ++++++++++++++++++++++--------------------- receiver/src/main.cpp | 3 +- receiver/src/sticker_info.cpp | 23 ++++++------ 6 files changed, 62 insertions(+), 61 deletions(-) diff --git a/receiver/inc/log.h b/receiver/inc/log.h index df3f0b2..3749cad 100644 --- a/receiver/inc/log.h +++ b/receiver/inc/log.h @@ -3,6 +3,9 @@ #include +#undef LOG_TAG +#define LOG_TAG "STICKER_RECEIVER" + #ifndef _LOG #define _LOG(logLevel, fmt, ...) do { \ dlog_print(logLevel, LOG_TAG, "%s : %s(%d) > " fmt, rindex(__FILE__, '/')+1, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ @@ -29,5 +32,4 @@ #define LOGF(format, arg...) _LOG(DLOG_FATAL, format, ##arg) #endif -#endif /* __debug_H__ */ - +#endif /* __debug_H__ */ \ No newline at end of file diff --git a/receiver/inc/main.h b/receiver/inc/main.h index 473ac68..b6fac02 100644 --- a/receiver/inc/main.h +++ b/receiver/inc/main.h @@ -5,8 +5,6 @@ #ifndef __MAIN_H__ #define __MAIN_H__ -#define TAG "STICKER_RECEIVER" - #if !defined(PACKAGE) #define PACKAGE "org.tizen.sticker-receiver" #endif diff --git a/receiver/inc/sticker_info.h b/receiver/inc/sticker_info.h index 27f2206..7cf88fe 100644 --- a/receiver/inc/sticker_info.h +++ b/receiver/inc/sticker_info.h @@ -1,8 +1,6 @@ #ifndef __STICKER_INFO_H__ #define __STICKER_INFO_H__ -#define TAG "STICKER_RECEIVER" - void insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc); int create_sticker_provider_handle(void); void destroy_sticker_provider_handle(void); diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 133f673..a67c6d6 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -29,10 +29,11 @@ #include #include -#define ACCESSORY_SERVICE_PROFILE_ID "/sample/filetransfersender" - +#include "log.h" #include "sticker_info.h" +#define ACCESSORY_SERVICE_PROFILE_ID "/sample/filetransfersender" + using namespace std; struct priv { @@ -53,7 +54,7 @@ static void _on_send_completed(sap_file_transaction_h file_transaction, { char error_message[100]; - dlog_print(DLOG_INFO, TAG, "# transfer completed"); + LOGI("# transfer completed"); if (priv_data.socket) { sap_file_transfer_destroy(file_transaction); @@ -62,68 +63,68 @@ static void _on_send_completed(sap_file_transaction_h file_transaction, if (result == SAP_FT_TRANSFER_SUCCESS) { sprintf(error_message, "Transfer Completed"); - dlog_print(DLOG_INFO, TAG, "Transfer Completed"); + LOGI("Transfer Completed"); if (chmod(recv_filepath.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == -1) { - dlog_print(DLOG_ERROR, TAG, "Failed to change permission : %s. error : %s", recv_filepath.c_str(), strerror(errno)); + LOGE("Failed to change permission : %s. error : %s", recv_filepath.c_str(), strerror(errno)); } else { - dlog_print(DLOG_INFO, TAG, "Succeed to change permission : %s", recv_filepath.c_str()); + LOGI("Succeed to change permission : %s", recv_filepath.c_str()); if (create_sticker_provider_handle() == STICKER_ERROR_NONE) { insert_sticker_data(recv_filepath.c_str(), "keyword", "group", "test icon"); destroy_sticker_provider_handle(); if (unlink(recv_filepath.c_str()) == -1) - dlog_print(DLOG_ERROR, TAG, "Failed to remove sticker file"); + LOGE("Failed to remove sticker file"); } } } else { switch (result) { case (SAP_FT_TRANSFER_FAIL_CHANNEL_IO): { sprintf(error_message, "Channel IO Error."); - dlog_print(DLOG_WARN, TAG, "Channel IO Error."); + LOGW("Channel IO Error."); break; } case (SAP_FT_TRANSFER_FAIL_FILE_IO): { sprintf(error_message, "File IO Error."); - dlog_print(DLOG_WARN, TAG, "File IO Error."); + LOGW("File IO Error."); break; } case (SAP_FT_TRANSFER_FAIL_CMD_DROPPED): { sprintf(error_message, "Transfer dropped."); - dlog_print(DLOG_WARN, TAG, "Transfer dropped."); + LOGW("Transfer dropped."); break; } case (SAP_FT_TRANSFER_FAIL_PEER_UNRESPONSIVE): { sprintf(error_message, "Peer Un Responsive."); - dlog_print(DLOG_WARN, TAG, "Peer Un Responsive."); + LOGW("Peer Un Responsive."); break; } case (SAP_FT_TRANSFER_FAIL_PEER_CONN_LOST): { sprintf(error_message, "Connection Lost."); - dlog_print(DLOG_WARN, TAG, "Connection Lost."); + LOGW("Connection Lost."); break; } case (SAP_FT_TRANSFER_FAIL_PEER_CANCELLED): { sprintf(error_message, "Peer Cancelled."); - dlog_print(DLOG_WARN, TAG, "Peer Cancelled."); + LOGW("Peer Cancelled."); break; } case (SAP_FT_TRANSFER_FAIL_SPACE_NOT_AVAILABLE): { sprintf(error_message, "No Space."); - dlog_print(DLOG_WARN, TAG, "No Space."); + LOGW("No Space."); break; } default: sprintf(error_message, "Unknown Error"); - dlog_print(DLOG_WARN, TAG, "Unknown Error"); + LOGW("Unknown Error"); } } @@ -134,12 +135,12 @@ static void _on_sending_file_in_progress(sap_file_transaction_h file_transaction unsigned short int percentage_progress, void *user_data) { - dlog_print(DLOG_INFO, TAG, "# progress %d", percentage_progress); + LOGI("# progress %d", percentage_progress); } static void __set_file_transfer_cb(sap_file_transaction_h file_socket) { - dlog_print(DLOG_INFO, TAG, "# set callbacks"); + LOGI("# set callbacks"); sap_file_transfer_set_progress_cb(file_socket, _on_sending_file_in_progress, NULL); sap_file_transfer_set_done_cb(file_socket, _on_send_completed, NULL); @@ -152,22 +153,22 @@ void accept_file() char *data_path = NULL; data_path = app_get_shared_data_path(); - dlog_print(DLOG_INFO, TAG, "Path : %s", data_path); + LOGI("Path : %s", data_path); sprintf(file_path, "%s/%s", data_path, incoming_file_name.c_str()); - dlog_print(DLOG_INFO, TAG, "Receive filepath : %s", file_path); + LOGI("Receive filepath : %s", file_path); recv_filepath = string(file_path); free(data_path); ret = sap_file_transfer_receive(priv_data.socket, file_path); switch(ret) { case SAP_RESULT_PERMISSION_DENIED: - dlog_print(DLOG_WARN, TAG, "permission denied"); + LOGW("permission denied"); break; case SAP_RESULT_FAILURE: - dlog_print(DLOG_WARN, TAG, "Fail"); + LOGW("Fail"); break; case SAP_RESULT_SUCCESS: - dlog_print(DLOG_INFO, TAG, "Success"); + LOGI("Success"); break; } @@ -182,7 +183,7 @@ void sap_file_transfer_get_receive_filepath(char **filepath) void reject_file() { int ret = sap_file_transfer_reject(priv_data.socket); - dlog_print(DLOG_INFO, TAG, "ret : %d", ret); + LOGI("ret : %d", ret); file_on_progress = 0; } @@ -194,14 +195,14 @@ static void _on_receive_file_cb(sap_peer_agent_h peer_agent_h, { file_on_progress = 1; priv_data.socket = socket; - dlog_print(DLOG_INFO, TAG, "# incoming file request."); + LOGI("# incoming file request."); __set_file_transfer_cb(priv_data.socket); incoming_file_name = file_path; std::size_t found = incoming_file_name.find_last_of("/"); incoming_file_name = incoming_file_name.substr(found+1); - dlog_print(DLOG_INFO, TAG, "# file path : %s, incoming file name : %s", file_path, incoming_file_name.c_str()); + LOGI("# file path : %s, incoming file name : %s", file_path, incoming_file_name.c_str()); accept_file(); } @@ -211,14 +212,14 @@ void conn_terminated(sap_peer_agent_h peer_agent, sap_service_connection_terminated_reason_e result, void *user_data) { - dlog_print(DLOG_INFO, TAG, "connection terminated"); + LOGI("connection terminated"); } void on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned int payload_length, void *buffer, void *user_data) /* message exchange on_receive callback (sap_agent_data_received_cb) */ { - dlog_print(DLOG_INFO, TAG, "received data: %s, len:%d", (char *)buffer, payload_length); + LOGI("received data: %s, len:%d", (char *)buffer, payload_length); } static void on_conn_req(sap_peer_agent_h peer_agent, @@ -239,7 +240,7 @@ static void on_agent_initialized(sap_agent_h agent, switch (result) { case SAP_AGENT_INITIALIZED_RESULT_SUCCESS: - dlog_print(DLOG_DEBUG, TAG, "agent is initialized"); + LOGD("agent is initialized"); priv_data.agent = agent; @@ -249,22 +250,22 @@ static void on_agent_initialized(sap_agent_h agent, break; case SAP_AGENT_INITIALIZED_RESULT_DUPLICATED: - dlog_print(DLOG_ERROR, TAG, "duplicate registration"); + LOGE("duplicate registration"); break; case SAP_AGENT_INITIALIZED_RESULT_INVALID_ARGUMENTS: - dlog_print(DLOG_ERROR, TAG, "invalid arguments"); + LOGE("invalid arguments"); break; case SAP_AGENT_INITIALIZED_RESULT_INTERNAL_ERROR: - dlog_print(DLOG_ERROR, TAG, "internal sap error"); + LOGE("internal sap error"); break; default: - dlog_print(DLOG_ERROR, TAG, "unknown status (%d)", result); + LOGE("unknown status (%d)", result); break; } @@ -274,45 +275,45 @@ static void _on_device_status_changed(sap_device_status_e status, sap_transport_type_e transport_type, void *user_data) { - dlog_print(DLOG_DEBUG, TAG, "%s, status :%d", __func__, status); + LOGD("%s, status :%d", __func__, status); switch (transport_type) { case SAP_TRANSPORT_TYPE_BT: - dlog_print(DLOG_DEBUG, TAG, "transport_type (%d): bt", transport_type); + LOGD("transport_type (%d): bt", transport_type); break; case SAP_TRANSPORT_TYPE_BLE: - dlog_print(DLOG_DEBUG, TAG, "transport_type (%d): ble", transport_type); + LOGD("transport_type (%d): ble", transport_type); break; case SAP_TRANSPORT_TYPE_TCP: - dlog_print(DLOG_DEBUG, TAG, "transport_type (%d): tcp/ip", transport_type); + LOGD("transport_type (%d): tcp/ip", transport_type); break; case SAP_TRANSPORT_TYPE_USB: - dlog_print(DLOG_DEBUG, TAG, "transport_type (%d): usb", transport_type); + LOGD("transport_type (%d): usb", transport_type); break; case SAP_TRANSPORT_TYPE_MOBILE: - dlog_print(DLOG_DEBUG, TAG, "transport_type (%d): mobile", transport_type); + LOGD("transport_type (%d): mobile", transport_type); break; default: - dlog_print(DLOG_ERROR, TAG, "unknown transport_type (%d)", transport_type); + LOGE("unknown transport_type (%d)", transport_type); break; } switch (status) { case SAP_DEVICE_STATUS_DETACHED: - dlog_print(DLOG_DEBUG, TAG, "device is not connected."); + LOGD("device is not connected."); break; case SAP_DEVICE_STATUS_ATTACHED: - dlog_print(DLOG_DEBUG, TAG, "Attached calling find peer now"); + LOGD("Attached calling find peer now"); break; default: - dlog_print(DLOG_ERROR, TAG, "unknown status (%d)", status); + LOGE("unknown status (%d)", status); break; } } @@ -325,7 +326,7 @@ gboolean agent_initialize() result = sap_agent_initialize(priv_data.agent, ACCESSORY_SERVICE_PROFILE_ID, SAP_AGENT_ROLE_CONSUMER, on_agent_initialized, NULL); - dlog_print(DLOG_DEBUG, TAG, "SAP >>> getRegisteredServiceAgent() >>> %d", result); + LOGD("SAP >>> getRegisteredServiceAgent() >>> %d", result); } while (result != SAP_RESULT_SUCCESS); return TRUE; diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index 3192e42..d99158b 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -1,5 +1,6 @@ #include "main.h" #include "ft.h" +#include "log.h" #include #include @@ -38,7 +39,7 @@ int main(int argc, char *argv[]) ret = service_app_main(argc, argv, &event_callback, NULL); if (ret != APP_ERROR_NONE) { - dlog_print(DLOG_ERROR, TAG, "app_main() is failed. err = %d", ret); + LOGE("app_main() is failed. err = %d", ret); } return ret; } diff --git a/receiver/src/sticker_info.cpp b/receiver/src/sticker_info.cpp index 0282163..37f11e8 100644 --- a/receiver/src/sticker_info.cpp +++ b/receiver/src/sticker_info.cpp @@ -1,10 +1,11 @@ #include "sticker_info.h" #include -#include #include #include #include +#include "log.h" + static sticker_provider_h sticker_provider = NULL; sticker_data_h @@ -19,14 +20,14 @@ int len, const char* group, const char* thumbnail, const char* description) ret = sticker_data_create(&sticker_data); if (ret != STICKER_ERROR_NONE) { /* Error handling */ - dlog_print(DLOG_ERROR, TAG, "Failed to create sticker data"); + LOGE("Failed to create sticker data"); } /* Sets the URI and URI type of the sticker */ ret = sticker_data_set_uri(sticker_data, type, uri); if (ret != STICKER_ERROR_NONE) { /* Error handling */ - dlog_print(DLOG_ERROR, TAG, "Failed to set uri"); + LOGE("Failed to set uri"); } //for (int i = 0; i < len; i++) @@ -35,7 +36,7 @@ int len, const char* group, const char* thumbnail, const char* description) ret = sticker_data_add_keyword(sticker_data, keyword); if (ret != STICKER_ERROR_NONE) { /* Error handling */ - dlog_print(DLOG_ERROR, TAG, "Failed to add keyword"); + LOGE("Failed to add keyword"); } } @@ -43,7 +44,7 @@ int len, const char* group, const char* thumbnail, const char* description) ret = sticker_data_set_group_name(sticker_data, group); if (ret != STICKER_ERROR_NONE) { /* Error handling */ - dlog_print(DLOG_ERROR, TAG, "Failed to set group name"); + LOGE("Failed to set group name"); } /* Sets the thumbnail local path of the sticker */ @@ -51,7 +52,7 @@ int len, const char* group, const char* thumbnail, const char* description) ret = sticker_data_set_thumbnail(sticker_data, thumbnail); if (ret != STICKER_ERROR_NONE) { /* Error handling */ - dlog_print(DLOG_ERROR, TAG, "Failed to set thumbnail"); + LOGE("Failed to set thumbnail"); } } @@ -59,7 +60,7 @@ int len, const char* group, const char* thumbnail, const char* description) ret = sticker_data_set_description(sticker_data, description); if (ret != STICKER_ERROR_NONE) { /* Error handling */ - dlog_print(DLOG_ERROR, TAG, "Failed to set description"); + LOGE("Failed to set description"); } return sticker_data; @@ -75,17 +76,17 @@ insert_sticker_data(const char *filepath, const char *keyword, const char *group ret = sticker_provider_insert_data(sticker_provider, data_handle); if (ret != STICKER_ERROR_NONE) { - dlog_print(DLOG_ERROR, TAG, "Failed to insert data. error code : %x. message : %s", ret, get_error_message(ret)); + LOGE("Failed to insert data. error code : %x. message : %s", ret, get_error_message(ret)); } else { - dlog_print(DLOG_INFO, TAG, "Succeeded to insert data"); + LOGI("Succeeded to insert data"); } /* Destroys a sticker data handle */ ret = sticker_data_destroy(data_handle); if (ret != STICKER_ERROR_NONE) { /* Error handling */ - dlog_print(DLOG_ERROR, TAG, "Failed to destroy sticker data"); + LOGE("Failed to destroy sticker data"); } } @@ -95,7 +96,7 @@ int create_sticker_provider_handle(void) ret = sticker_provider_create(&sticker_provider); if (ret != STICKER_ERROR_NONE) { /* Error handling */ - dlog_print(DLOG_ERROR, TAG, "Failed to create sticker provider"); + LOGE("Failed to create sticker provider"); } return ret; -- 2.7.4 From 7c50b342d94f258c7c2331df7b9b7ff81c1d6e52 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 21 Feb 2020 20:49:19 +0900 Subject: [PATCH 09/16] Terminate sticker-receiver when disconnected from mobile device Change-Id: I463ed46ba612b7a2521e26a242386bb283e946d3 Signed-off-by: Jihoon Kim --- receiver/inc/ft.h | 1 + receiver/src/ft.cpp | 33 +++++++++++++++++++++++++++++++++ receiver/src/main.cpp | 1 + 3 files changed, 35 insertions(+) diff --git a/receiver/inc/ft.h b/receiver/inc/ft.h index b64fa8d..bf25d8e 100644 --- a/receiver/inc/ft.h +++ b/receiver/inc/ft.h @@ -27,6 +27,7 @@ void reject_file(void); void accept_file(void); gboolean initialize_sap(void); +void deinitialize_sap(void); void sap_file_transfer_get_receive_filepath(char **filepath); diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index a67c6d6..ac09cf5 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -213,6 +214,7 @@ void conn_terminated(sap_peer_agent_h peer_agent, void *user_data) { LOGI("connection terminated"); + service_app_exit(); } void @@ -271,6 +273,13 @@ static void on_agent_initialized(sap_agent_h agent, } } +static void on_agent_deinitialized(sap_agent_h agent, + sap_agent_deinitialized_result_e result, + void *user_data) +{ + LOGD("result of deinitialize : %d", result); +} + static void _on_device_status_changed(sap_device_status_e status, sap_transport_type_e transport_type, void *user_data) @@ -346,3 +355,27 @@ gboolean initialize_sap(void) return TRUE; } + +void deinitialize_sap(void) +{ + if (priv_data.agent) { + int ret = sap_agent_deinitialize(priv_data.agent, on_agent_deinitialized, NULL); + switch (ret) { + case SAP_RESULT_FAILURE: + LOGW("Failed to deinitialize"); + break; + case SAP_RESULT_SUCCESS: + LOGD("Succeed to deinitialize"); + break; + case SAP_RESULT_PERMISSION_DENIED: + LOGW("permission denied: deinitialize "); + break; + default: + LOGD("deinitialize : %d", ret); + break; + } + + sap_agent_destroy(priv_data.agent); + priv_data.agent = NULL; + } +} diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index d99158b..6151d90 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -24,6 +24,7 @@ static void app_control(app_control_h app_control, void *data) static void app_terminate(void *data) { /* Release all resources. */ + deinitialize_sap(); } int main(int argc, char *argv[]) -- 2.7.4 From 57d90c68c33b22271da476dbb90a4943d246aedf Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Mon, 24 Feb 2020 18:57:29 +0900 Subject: [PATCH 10/16] Change indentation from tab to spaces Change-Id: I4f79da47ef7b6b05d096596230683a5582005cb5 Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 500 +++++++++++++++++++++--------------------- receiver/src/main.cpp | 40 ++-- receiver/src/sticker_info.cpp | 3 +- 3 files changed, 266 insertions(+), 277 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index ac09cf5..d03495d 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -38,8 +38,8 @@ using namespace std; struct priv { - sap_agent_h agent; - sap_file_transaction_h socket; + sap_agent_h agent; + sap_file_transaction_h socket; }; static struct priv priv_data = { 0 }; @@ -49,333 +49,323 @@ static string incoming_file_name; static string recv_filepath; static void _on_send_completed(sap_file_transaction_h file_transaction, - sap_ft_transfer_e result, - const char *file_path, - void *user_data) + sap_ft_transfer_e result, + const char *file_path, + void *user_data) { - char error_message[100]; - - LOGI("# transfer completed"); - - if (priv_data.socket) { - sap_file_transfer_destroy(file_transaction); - priv_data.socket = NULL; - } - - if (result == SAP_FT_TRANSFER_SUCCESS) { - sprintf(error_message, "Transfer Completed"); - LOGI("Transfer Completed"); - - if (chmod(recv_filepath.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == -1) { - LOGE("Failed to change permission : %s. error : %s", recv_filepath.c_str(), strerror(errno)); - } - else { - LOGI("Succeed to change permission : %s", recv_filepath.c_str()); - if (create_sticker_provider_handle() == STICKER_ERROR_NONE) { - insert_sticker_data(recv_filepath.c_str(), "keyword", "group", "test icon"); - destroy_sticker_provider_handle(); - - if (unlink(recv_filepath.c_str()) == -1) - LOGE("Failed to remove sticker file"); - } - } - } else { - switch (result) { - case (SAP_FT_TRANSFER_FAIL_CHANNEL_IO): { - sprintf(error_message, "Channel IO Error."); - LOGW("Channel IO Error."); - break; - } - - case (SAP_FT_TRANSFER_FAIL_FILE_IO): { - sprintf(error_message, "File IO Error."); - LOGW("File IO Error."); - break; - } - - case (SAP_FT_TRANSFER_FAIL_CMD_DROPPED): { - sprintf(error_message, "Transfer dropped."); - LOGW("Transfer dropped."); - break; - } - - case (SAP_FT_TRANSFER_FAIL_PEER_UNRESPONSIVE): { - sprintf(error_message, "Peer Un Responsive."); - LOGW("Peer Un Responsive."); - break; - } - - case (SAP_FT_TRANSFER_FAIL_PEER_CONN_LOST): { - sprintf(error_message, "Connection Lost."); - LOGW("Connection Lost."); - break; - } - - case (SAP_FT_TRANSFER_FAIL_PEER_CANCELLED): { - sprintf(error_message, "Peer Cancelled."); - LOGW("Peer Cancelled."); - break; - } - - case (SAP_FT_TRANSFER_FAIL_SPACE_NOT_AVAILABLE): { - sprintf(error_message, "No Space."); - LOGW("No Space."); - break; - } - - default: - sprintf(error_message, "Unknown Error"); - LOGW("Unknown Error"); - } - } - - file_on_progress = 0; + char error_message[100]; + + LOGI("# transfer completed"); + + if (priv_data.socket) { + sap_file_transfer_destroy(file_transaction); + priv_data.socket = NULL; + } + + if (result == SAP_FT_TRANSFER_SUCCESS) { + sprintf(error_message, "Transfer Completed"); + LOGI("Transfer Completed"); + + if (chmod(recv_filepath.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == -1) { + LOGE("Failed to change permission : %s. error : %s", recv_filepath.c_str(), strerror(errno)); + } + else { + LOGI("Succeed to change permission : %s", recv_filepath.c_str()); + if (create_sticker_provider_handle() == STICKER_ERROR_NONE) { + insert_sticker_data(recv_filepath.c_str(), "keyword", "group", "test icon"); + destroy_sticker_provider_handle(); + + if (unlink(recv_filepath.c_str()) == -1) + LOGE("Failed to remove sticker file"); + } + } + } else { + switch (result) { + case (SAP_FT_TRANSFER_FAIL_CHANNEL_IO): { + sprintf(error_message, "Channel IO Error."); + LOGW("Channel IO Error."); + break; + } + + case (SAP_FT_TRANSFER_FAIL_FILE_IO): { + sprintf(error_message, "File IO Error."); + LOGW("File IO Error."); + break; + } + + case (SAP_FT_TRANSFER_FAIL_CMD_DROPPED): + { + sprintf(error_message, "Transfer dropped."); + LOGW("Transfer dropped."); + break; + } + + case (SAP_FT_TRANSFER_FAIL_PEER_UNRESPONSIVE): + { + sprintf(error_message, "Peer Un Responsive."); + LOGW("Peer Un Responsive."); + break; + } + + case (SAP_FT_TRANSFER_FAIL_PEER_CONN_LOST): + { + sprintf(error_message, "Connection Lost."); + LOGW("Connection Lost."); + break; + } + + case (SAP_FT_TRANSFER_FAIL_PEER_CANCELLED): + { + sprintf(error_message, "Peer Cancelled."); + LOGW("Peer Cancelled."); + break; + } + + case (SAP_FT_TRANSFER_FAIL_SPACE_NOT_AVAILABLE): + { + sprintf(error_message, "No Space."); + LOGW("No Space."); + break; + } + + default: + sprintf(error_message, "Unknown Error"); + LOGW("Unknown Error"); + break; + } + } + + file_on_progress = 0; } static void _on_sending_file_in_progress(sap_file_transaction_h file_transaction, - unsigned short int percentage_progress, - void *user_data) + unsigned short int percentage_progress, + void *user_data) { - LOGI("# progress %d", percentage_progress); + LOGI("# progress %d", percentage_progress); } static void __set_file_transfer_cb(sap_file_transaction_h file_socket) { - LOGI("# set callbacks"); - sap_file_transfer_set_progress_cb(file_socket, _on_sending_file_in_progress, NULL); + LOGI("# set callbacks"); + sap_file_transfer_set_progress_cb(file_socket, _on_sending_file_in_progress, NULL); - sap_file_transfer_set_done_cb(file_socket, _on_send_completed, NULL); + sap_file_transfer_set_done_cb(file_socket, _on_send_completed, NULL); } void accept_file() { - int ret; - char file_path[PATH_MAX]; - char *data_path = NULL; - - data_path = app_get_shared_data_path(); - LOGI("Path : %s", data_path); - sprintf(file_path, "%s/%s", data_path, incoming_file_name.c_str()); - LOGI("Receive filepath : %s", file_path); - recv_filepath = string(file_path); - free(data_path); - - ret = sap_file_transfer_receive(priv_data.socket, file_path); - switch(ret) { - case SAP_RESULT_PERMISSION_DENIED: - LOGW("permission denied"); - break; - case SAP_RESULT_FAILURE: - LOGW("Fail"); - break; - case SAP_RESULT_SUCCESS: - LOGI("Success"); - break; - } - - file_on_progress = 1; + int ret; + char file_path[PATH_MAX]; + char *data_path = NULL; + + data_path = app_get_shared_data_path(); + LOGI("Path : %s", data_path); + sprintf(file_path, "%s/%s", data_path, incoming_file_name.c_str()); + LOGI("Receive filepath : %s", file_path); + recv_filepath = string(file_path); + free(data_path); + + ret = sap_file_transfer_receive(priv_data.socket, file_path); + switch(ret) { + case SAP_RESULT_PERMISSION_DENIED: + LOGW("permission denied"); + break; + case SAP_RESULT_FAILURE: + LOGW("Fail"); + break; + case SAP_RESULT_SUCCESS: + LOGI("Success"); + break; + } + + file_on_progress = 1; } void sap_file_transfer_get_receive_filepath(char **filepath) { - *filepath = strdup(recv_filepath.c_str()); + *filepath = strdup(recv_filepath.c_str()); } void reject_file() { - int ret = sap_file_transfer_reject(priv_data.socket); - LOGI("ret : %d", ret); + int ret = sap_file_transfer_reject(priv_data.socket); + LOGI("ret : %d", ret); - file_on_progress = 0; + file_on_progress = 0; } static void _on_receive_file_cb(sap_peer_agent_h peer_agent_h, - sap_file_transaction_h socket, - const char *file_path, - void *user_data) + sap_file_transaction_h socket, + const char *file_path, + void *user_data) { - file_on_progress = 1; - priv_data.socket = socket; - LOGI("# incoming file request."); - __set_file_transfer_cb(priv_data.socket); + file_on_progress = 1; + priv_data.socket = socket; + LOGI("# incoming file request."); + __set_file_transfer_cb(priv_data.socket); - incoming_file_name = file_path; - std::size_t found = incoming_file_name.find_last_of("/"); - incoming_file_name = incoming_file_name.substr(found+1); + incoming_file_name = file_path; + std::size_t found = incoming_file_name.find_last_of("/"); + incoming_file_name = incoming_file_name.substr(found+1); - LOGI("# file path : %s, incoming file name : %s", file_path, incoming_file_name.c_str()); + LOGI("# file path : %s, incoming file name : %s", file_path, incoming_file_name.c_str()); - accept_file(); + accept_file(); } void conn_terminated(sap_peer_agent_h peer_agent, - sap_socket_h socket, - sap_service_connection_terminated_reason_e result, - void *user_data) + sap_socket_h socket, + sap_service_connection_terminated_reason_e result, + void *user_data) { - LOGI("connection terminated"); - service_app_exit(); + LOGI("connection terminated"); + service_app_exit(); } void on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned int payload_length, void *buffer, - void *user_data) /* message exchange on_receive callback (sap_agent_data_received_cb) */ + void *user_data) /* message exchange on_receive callback (sap_agent_data_received_cb) */ { - LOGI("received data: %s, len:%d", (char *)buffer, payload_length); + LOGI("received data: %s, len:%d", (char *)buffer, payload_length); } static void on_conn_req(sap_peer_agent_h peer_agent, - sap_socket_h socket, - sap_service_connection_result_e result, - void *user_data) + sap_socket_h socket, + sap_service_connection_result_e result, + void *user_data) { - sap_peer_agent_accept_service_connection(peer_agent); - sap_peer_agent_set_service_connection_terminated_cb(peer_agent, conn_terminated, NULL); + sap_peer_agent_accept_service_connection(peer_agent); + sap_peer_agent_set_service_connection_terminated_cb(peer_agent, conn_terminated, NULL); - sap_socket_set_data_received_cb(socket, on_data_received, peer_agent); + sap_socket_set_data_received_cb(socket, on_data_received, peer_agent); } static void on_agent_initialized(sap_agent_h agent, - sap_agent_initialized_result_e result, - void *user_data) + sap_agent_initialized_result_e result, + void *user_data) { - switch (result) { - case SAP_AGENT_INITIALIZED_RESULT_SUCCESS: - - LOGD("agent is initialized"); - - priv_data.agent = agent; - - sap_file_transfer_set_incoming_file_cb(agent, _on_receive_file_cb, NULL); - sap_agent_set_service_connection_requested_cb(agent, on_conn_req, NULL); - - break; - - case SAP_AGENT_INITIALIZED_RESULT_DUPLICATED: - LOGE("duplicate registration"); - - break; - - case SAP_AGENT_INITIALIZED_RESULT_INVALID_ARGUMENTS: - LOGE("invalid arguments"); - - break; - - case SAP_AGENT_INITIALIZED_RESULT_INTERNAL_ERROR: - LOGE("internal sap error"); - - break; - - default: - LOGE("unknown status (%d)", result); - - break; - } + switch (result) { + case SAP_AGENT_INITIALIZED_RESULT_SUCCESS: + LOGD("agent is initialized"); + + priv_data.agent = agent; + + sap_file_transfer_set_incoming_file_cb(agent, _on_receive_file_cb, NULL); + sap_agent_set_service_connection_requested_cb(agent, on_conn_req, NULL); + + break; + case SAP_AGENT_INITIALIZED_RESULT_DUPLICATED: + LOGE("duplicate registration"); + break; + case SAP_AGENT_INITIALIZED_RESULT_INVALID_ARGUMENTS: + LOGE("invalid arguments"); + break; + case SAP_AGENT_INITIALIZED_RESULT_INTERNAL_ERROR: + LOGE("internal sap error"); + break; + default: + LOGE("unknown status (%d)", result); + break; + } } static void on_agent_deinitialized(sap_agent_h agent, - sap_agent_deinitialized_result_e result, - void *user_data) + sap_agent_deinitialized_result_e result, + void *user_data) { - LOGD("result of deinitialize : %d", result); + LOGD("result of deinitialize : %d", result); } static void _on_device_status_changed(sap_device_status_e status, - sap_transport_type_e transport_type, - void *user_data) + sap_transport_type_e transport_type, + void *user_data) { - LOGD("%s, status :%d", __func__, status); - - switch (transport_type) { - case SAP_TRANSPORT_TYPE_BT: - LOGD("transport_type (%d): bt", transport_type); - break; - - case SAP_TRANSPORT_TYPE_BLE: - LOGD("transport_type (%d): ble", transport_type); - break; - - case SAP_TRANSPORT_TYPE_TCP: - LOGD("transport_type (%d): tcp/ip", transport_type); - break; - - case SAP_TRANSPORT_TYPE_USB: - LOGD("transport_type (%d): usb", transport_type); - break; - - case SAP_TRANSPORT_TYPE_MOBILE: - LOGD("transport_type (%d): mobile", transport_type); - break; - - default: - LOGE("unknown transport_type (%d)", transport_type); - break; - } - - switch (status) { - case SAP_DEVICE_STATUS_DETACHED: - LOGD("device is not connected."); - break; - - case SAP_DEVICE_STATUS_ATTACHED: - LOGD("Attached calling find peer now"); - break; - - default: - LOGE("unknown status (%d)", status); - break; - } + LOGD("%s, status :%d", __func__, status); + + switch (transport_type) { + case SAP_TRANSPORT_TYPE_BT: + LOGD("transport_type (%d): bt", transport_type); + break; + case SAP_TRANSPORT_TYPE_BLE: + LOGD("transport_type (%d): ble", transport_type); + break; + case SAP_TRANSPORT_TYPE_TCP: + LOGD("transport_type (%d): tcp/ip", transport_type); + break; + case SAP_TRANSPORT_TYPE_USB: + LOGD("transport_type (%d): usb", transport_type); + break; + case SAP_TRANSPORT_TYPE_MOBILE: + LOGD("transport_type (%d): mobile", transport_type); + break; + default: + LOGE("unknown transport_type (%d)", transport_type); + break; + } + + switch (status) { + case SAP_DEVICE_STATUS_DETACHED: + LOGD("device is not connected."); + break; + case SAP_DEVICE_STATUS_ATTACHED: + LOGD("Attached calling find peer now"); + break; + default: + LOGE("unknown status (%d)", status); + break; + } } gboolean agent_initialize() { - int result = 0; + int result = 0; - do { - result = sap_agent_initialize(priv_data.agent, ACCESSORY_SERVICE_PROFILE_ID, SAP_AGENT_ROLE_CONSUMER, - on_agent_initialized, NULL); + do { + result = sap_agent_initialize(priv_data.agent, ACCESSORY_SERVICE_PROFILE_ID, SAP_AGENT_ROLE_CONSUMER, + on_agent_initialized, NULL); - LOGD("SAP >>> getRegisteredServiceAgent() >>> %d", result); - } while (result != SAP_RESULT_SUCCESS); + LOGD("SAP >>> getRegisteredServiceAgent() >>> %d", result); + } while (result != SAP_RESULT_SUCCESS); - return TRUE; + return TRUE; } gboolean initialize_sap(void) { - sap_agent_h agent = NULL; + sap_agent_h agent = NULL; - sap_agent_create(&agent); + sap_agent_create(&agent); - priv_data.agent = agent; + priv_data.agent = agent; - agent_initialize(); + agent_initialize(); - sap_set_device_status_changed_cb(_on_device_status_changed, NULL); + sap_set_device_status_changed_cb(_on_device_status_changed, NULL); - return TRUE; + return TRUE; } void deinitialize_sap(void) { - if (priv_data.agent) { - int ret = sap_agent_deinitialize(priv_data.agent, on_agent_deinitialized, NULL); - switch (ret) { - case SAP_RESULT_FAILURE: - LOGW("Failed to deinitialize"); - break; - case SAP_RESULT_SUCCESS: - LOGD("Succeed to deinitialize"); - break; - case SAP_RESULT_PERMISSION_DENIED: - LOGW("permission denied: deinitialize "); - break; - default: - LOGD("deinitialize : %d", ret); - break; - } - - sap_agent_destroy(priv_data.agent); - priv_data.agent = NULL; - } + if (priv_data.agent) { + int ret = sap_agent_deinitialize(priv_data.agent, on_agent_deinitialized, NULL); + switch (ret) { + case SAP_RESULT_FAILURE: + LOGW("Failed to deinitialize"); + break; + case SAP_RESULT_SUCCESS: + LOGD("Succeed to deinitialize"); + break; + case SAP_RESULT_PERMISSION_DENIED: + LOGW("permission denied: deinitialize "); + break; + default: + LOGD("deinitialize : %d", ret); + break; + } + + sap_agent_destroy(priv_data.agent); + priv_data.agent = NULL; + } } diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index 6151d90..3bf6300 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -6,41 +6,41 @@ static bool app_create(void *data) { - /* Hook to take necessary actions before main event loop starts - Initialize UI resources and application's data - If this function returns true, the main loop of application starts - If this function returns false, the application is terminated */ + /* Hook to take necessary actions before main event loop starts + Initialize UI resources and application's data + If this function returns true, the main loop of application starts + If this function returns false, the application is terminated */ - initialize_sap(); + initialize_sap(); - return true; + return true; } static void app_control(app_control_h app_control, void *data) { - /* Handle the launch request. */ + /* Handle the launch request. */ } static void app_terminate(void *data) { - /* Release all resources. */ - deinitialize_sap(); + /* Release all resources. */ + deinitialize_sap(); } int main(int argc, char *argv[]) { - int ret = 0; + int ret = 0; - service_app_lifecycle_callback_s event_callback; - memset(&event_callback, 0x0, sizeof(service_app_lifecycle_callback_s)); + service_app_lifecycle_callback_s event_callback; + memset(&event_callback, 0x0, sizeof(service_app_lifecycle_callback_s)); - event_callback.create = (service_app_create_cb)app_create; - event_callback.terminate = (service_app_terminate_cb)app_terminate; - event_callback.app_control = (service_app_control_cb)app_control; + event_callback.create = (service_app_create_cb)app_create; + event_callback.terminate = (service_app_terminate_cb)app_terminate; + event_callback.app_control = (service_app_control_cb)app_control; - ret = service_app_main(argc, argv, &event_callback, NULL); - if (ret != APP_ERROR_NONE) { - LOGE("app_main() is failed. err = %d", ret); - } - return ret; + ret = service_app_main(argc, argv, &event_callback, NULL); + if (ret != APP_ERROR_NONE) { + LOGE("app_main() is failed. err = %d", ret); + } + return ret; } diff --git a/receiver/src/sticker_info.cpp b/receiver/src/sticker_info.cpp index 37f11e8..a391fc2 100644 --- a/receiver/src/sticker_info.cpp +++ b/receiver/src/sticker_info.cpp @@ -12,7 +12,6 @@ sticker_data_h set_sticker_data(sticker_data_uri_type_e type, const char* uri, const char* keyword, int len, const char* group, const char* thumbnail, const char* description) { - sticker_data_h sticker_data; int ret; @@ -106,4 +105,4 @@ void destroy_sticker_provider_handle(void) { sticker_provider_destroy(sticker_provider); sticker_provider = NULL; -} \ No newline at end of file +} -- 2.7.4 From 1f7fe8f256483a4afd7875e22aba692f317498c1 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 2 Mar 2020 10:39:22 +0900 Subject: [PATCH 11/16] Fix issues detected by static analysis tool Change-Id: Ifc206b696c03bff49baac3e048febca3348f212b --- server/stickerd_db_manager.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/stickerd_db_manager.c b/server/stickerd_db_manager.c index 02c4691..ab68092 100644 --- a/server/stickerd_db_manager.c +++ b/server/stickerd_db_manager.c @@ -616,14 +616,14 @@ int stickerd_db_get_keyword_list(GVariantBuilder *builder, char *app_id) if (!db) return STICKERD_SERVER_ERROR_DB_FAILED; - sqlite3_bind_text(stmt, 1, app_id, -1, SQLITE_TRANSIENT); - ret = sqlite3_prepare_v2(db, STICKER_DB_GET_ALL_KEYWORD_LIST, -1, &stmt, NULL); if (ret != SQLITE_OK) { LOGE("fail to get keyword list : %s", sqlite3_errmsg(db)); goto cleanup; } + sqlite3_bind_text(stmt, 1, app_id, -1, SQLITE_TRANSIENT); + while (sqlite3_step(stmt) == SQLITE_ROW) { const unsigned char *keyword = sqlite3_column_text(stmt, 0); if (keyword) -- 2.7.4 From 090894c826d52ba453de7ee43b9610eeedf5418f Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 2 Mar 2020 10:40:38 +0900 Subject: [PATCH 12/16] Update package version to 0.1.15 Change-Id: I1026c72fdeae6e3bccae1e4e7fbcb8fe582b68b8 (cherry picked from commit b14f2f3415ef1b176f1522efc0fc3e566a5b5e4c) --- packaging/capi-ui-sticker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 7e4cb25..269d1fb 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -1,6 +1,6 @@ Name: capi-ui-sticker Summary: Sticker client library and daemon -Version: 0.1.14 +Version: 0.1.15 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 -- 2.7.4 From edf8f3f882043e853799dd8356a4b34f283edff2 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Tue, 3 Mar 2020 14:26:02 +0900 Subject: [PATCH 13/16] Remove unused code Change-Id: I4b89eaca5ca208eca0edd2e3e54e0e93a599da6c Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index d03495d..8cca375 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -53,17 +53,12 @@ static void _on_send_completed(sap_file_transaction_h file_transaction, const char *file_path, void *user_data) { - char error_message[100]; - - LOGI("# transfer completed"); - if (priv_data.socket) { sap_file_transfer_destroy(file_transaction); priv_data.socket = NULL; } if (result == SAP_FT_TRANSFER_SUCCESS) { - sprintf(error_message, "Transfer Completed"); LOGI("Transfer Completed"); if (chmod(recv_filepath.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == -1) { @@ -82,54 +77,46 @@ static void _on_send_completed(sap_file_transaction_h file_transaction, } else { switch (result) { case (SAP_FT_TRANSFER_FAIL_CHANNEL_IO): { - sprintf(error_message, "Channel IO Error."); LOGW("Channel IO Error."); break; } case (SAP_FT_TRANSFER_FAIL_FILE_IO): { - sprintf(error_message, "File IO Error."); LOGW("File IO Error."); break; } case (SAP_FT_TRANSFER_FAIL_CMD_DROPPED): { - sprintf(error_message, "Transfer dropped."); LOGW("Transfer dropped."); break; } case (SAP_FT_TRANSFER_FAIL_PEER_UNRESPONSIVE): { - sprintf(error_message, "Peer Un Responsive."); LOGW("Peer Un Responsive."); break; } case (SAP_FT_TRANSFER_FAIL_PEER_CONN_LOST): { - sprintf(error_message, "Connection Lost."); LOGW("Connection Lost."); break; } case (SAP_FT_TRANSFER_FAIL_PEER_CANCELLED): { - sprintf(error_message, "Peer Cancelled."); LOGW("Peer Cancelled."); break; } case (SAP_FT_TRANSFER_FAIL_SPACE_NOT_AVAILABLE): { - sprintf(error_message, "No Space."); LOGW("No Space."); break; } default: - sprintf(error_message, "Unknown Error"); LOGW("Unknown Error"); break; } -- 2.7.4 From b6f06009395439e25ca84de93ee1b48138e0f0b6 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Tue, 3 Mar 2020 15:16:57 +0900 Subject: [PATCH 14/16] Show connection termination reason Change-Id: I7a115a0dd0b13862fd3fada2df1f324c04685be7 Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 8cca375..7676b2e 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -206,7 +206,22 @@ void conn_terminated(sap_peer_agent_h peer_agent, sap_service_connection_terminated_reason_e result, void *user_data) { - LOGI("connection terminated"); + switch (result) + { + case SAP_CONNECTION_TERMINATED_REASON_PEER_DISCONNECTED: + LOGW("Peer Disconnected"); + break; + case SAP_CONNECTION_TERMINATED_REASON_DEVICE_DETACHED: + LOGW("Disconnected Device Detached"); + break; + case SAP_CONNECTION_TERMINATED_REASON_UNKNOWN: + LOGW("Disconnected Unknown Reason"); + break; + default: + LOGW("connection terminated. reason : %d", result); + break; + } + service_app_exit(); } -- 2.7.4 From 012fb63dc2a1de79be7196b796f34d0c687d7f8c Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 2 Mar 2020 15:26:33 +0900 Subject: [PATCH 15/16] Add a logic for sending and receiving JSON data Change-Id: I35a22242645906d0cb4f7c4ac18df852d6f6266e --- receiver/CMakeLists.txt | 1 + receiver/inc/ft.h | 1 + receiver/src/ft.cpp | 263 ++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 246 insertions(+), 19 deletions(-) diff --git a/receiver/CMakeLists.txt b/receiver/CMakeLists.txt index 3d1e6a9..247230a 100644 --- a/receiver/CMakeLists.txt +++ b/receiver/CMakeLists.txt @@ -13,6 +13,7 @@ pkg_check_modules(pkgs_test REQUIRED dlog capi-appfw-service-application sap-client-stub-api + json-glib-1.0 ) INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/receiver/inc) diff --git a/receiver/inc/ft.h b/receiver/inc/ft.h index bf25d8e..271a98f 100644 --- a/receiver/inc/ft.h +++ b/receiver/inc/ft.h @@ -30,5 +30,6 @@ gboolean initialize_sap(void); void deinitialize_sap(void); void sap_file_transfer_get_receive_filepath(char **filepath); +void request_sticker_data(const char *mode, const char *category, const char *type); #endif /* __FT_H__ */ diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 7676b2e..49734f1 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -29,51 +29,129 @@ #include #include #include +#include +#include "ft.h" #include "log.h" #include "sticker_info.h" #define ACCESSORY_SERVICE_PROFILE_ID "/sample/filetransfersender" +#define ACCESSORY_SERVICE_CHANNEL_ID 107 + +#define STICKER_SYNC_START_REQ "sticker-sync-start-req" +#define STICKER_SYNC_START_RSP "sticker-sync-start-rsp" +#define STICKER_SEND_START_REQ "sticker-send-start-req" +#define STICKER_SEND_START_RSP "sticker-send-start-rsp" +#define STICKER_SEND_FACE_DATA "sticker-send-face-data" +#define STICKER_SEND_STOP_REQ "sticker-send-stop-req" +#define STICKER_SEND_STOP_RSP "sticker-send-stop-rsp" using namespace std; struct priv { sap_agent_h agent; - sap_file_transaction_h socket; + sap_socket_h socket; + sap_file_transaction_h file_socket; +}; + +static void _reset_sticker_data(); + +struct sticker_info { + string file_path; + string group; + string keyword; + string disp_type; + string description; + + sticker_info() + { + _reset_sticker_data(); + } }; static struct priv priv_data = { 0 }; +static struct sticker_info sticker_data; gboolean file_on_progress = 0; static string incoming_file_name; -static string recv_filepath; +static int t_id = 0; +static int rec_file_cnt = 0; + +static gboolean _send_json_data(JsonObject *obj) +{ + JsonGenerator *j_generator = NULL; + JsonNode *j_node = NULL; + gsize size = 0; + gchar *data = NULL; + int result = 1; + + j_generator = json_generator_new(); + if (j_generator == NULL) { + LOGE("Unable to json_generator_new"); + goto cleanup; + } + + j_node = json_node_new(JSON_NODE_OBJECT); + if (j_node == NULL) { + LOGE("Unable to json_node_new"); + goto cleanup; + } + + json_node_set_object(j_node, obj); + json_generator_set_root(j_generator, j_node); + + data = json_generator_to_data(j_generator, &size); + if (data == NULL) { + LOGE("Unable to json_generator_to_data"); + goto cleanup; + } + + if (priv_data.socket) { + LOGD("Send JSON data : %s", data); + result = sap_socket_send_data(priv_data.socket, ACCESSORY_SERVICE_CHANNEL_ID, strlen(data), (void *)data); + } + +cleanup: + if (data) + g_free(data); + + if (j_node) + json_node_free(j_node); + + if (j_generator) + g_object_unref(j_generator); + + return result ? FALSE : TRUE; +} static void _on_send_completed(sap_file_transaction_h file_transaction, sap_ft_transfer_e result, const char *file_path, void *user_data) { - if (priv_data.socket) { + if (priv_data.file_socket) { sap_file_transfer_destroy(file_transaction); - priv_data.socket = NULL; + priv_data.file_socket = NULL; } if (result == SAP_FT_TRANSFER_SUCCESS) { LOGI("Transfer Completed"); - if (chmod(recv_filepath.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == -1) { - LOGE("Failed to change permission : %s. error : %s", recv_filepath.c_str(), strerror(errno)); + if (chmod(sticker_data.file_path.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == -1) { + LOGE("Failed to change permission : %s. error : %s", sticker_data.file_path.c_str(), strerror(errno)); } else { - LOGI("Succeed to change permission : %s", recv_filepath.c_str()); + LOGI("Succeed to change permission : %s", sticker_data.file_path.c_str()); if (create_sticker_provider_handle() == STICKER_ERROR_NONE) { - insert_sticker_data(recv_filepath.c_str(), "keyword", "group", "test icon"); + insert_sticker_data(sticker_data.file_path.c_str(), sticker_data.keyword.c_str(), sticker_data.group.c_str(), sticker_data.description.c_str()); destroy_sticker_provider_handle(); - if (unlink(recv_filepath.c_str()) == -1) + if (unlink(sticker_data.file_path.c_str()) == -1) LOGE("Failed to remove sticker file"); } } + + rec_file_cnt++; } else { switch (result) { case (SAP_FT_TRANSFER_FAIL_CHANNEL_IO): { @@ -150,10 +228,10 @@ void accept_file() LOGI("Path : %s", data_path); sprintf(file_path, "%s/%s", data_path, incoming_file_name.c_str()); LOGI("Receive filepath : %s", file_path); - recv_filepath = string(file_path); + sticker_data.file_path = string(file_path); free(data_path); - ret = sap_file_transfer_receive(priv_data.socket, file_path); + ret = sap_file_transfer_receive(priv_data.file_socket, file_path); switch(ret) { case SAP_RESULT_PERMISSION_DENIED: LOGW("permission denied"); @@ -171,12 +249,32 @@ void accept_file() void sap_file_transfer_get_receive_filepath(char **filepath) { - *filepath = strdup(recv_filepath.c_str()); + *filepath = strdup(sticker_data.file_path.c_str()); +} + +void request_sticker_data(const char *mode, const char *category, const char *type) +{ + JsonObject *j_object = json_object_new(); + if (j_object == NULL) { + LOGE("json object create error"); + return; + } + + json_object_set_string_member(j_object, "msgId", STICKER_SYNC_START_REQ); + json_object_set_int_member(j_object, "tID", ++t_id); + json_object_set_string_member(j_object, "mode", mode); + json_object_set_string_member(j_object, "category", category); + json_object_set_string_member(j_object, "type", type); + + if (_send_json_data(j_object) == FALSE) + LOGE("Failed to request sticker data"); + + json_object_unref(j_object); } void reject_file() { - int ret = sap_file_transfer_reject(priv_data.socket); + int ret = sap_file_transfer_reject(priv_data.file_socket); LOGI("ret : %d", ret); file_on_progress = 0; @@ -188,9 +286,9 @@ static void _on_receive_file_cb(sap_peer_agent_h peer_agent_h, void *user_data) { file_on_progress = 1; - priv_data.socket = socket; + priv_data.file_socket = socket; LOGI("# incoming file request."); - __set_file_transfer_cb(priv_data.socket); + __set_file_transfer_cb(priv_data.file_socket); incoming_file_name = file_path; std::size_t found = incoming_file_name.find_last_of("/"); @@ -225,11 +323,136 @@ void conn_terminated(sap_peer_agent_h peer_agent, service_app_exit(); } +static void _reset_sticker_data() +{ + sticker_data.file_path.clear(); + sticker_data.group.clear(); + sticker_data.keyword.clear(); + sticker_data.disp_type.clear(); + sticker_data.description.clear(); +} + void on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned int payload_length, void *buffer, void *user_data) /* message exchange on_receive callback (sap_agent_data_received_cb) */ { LOGI("received data: %s, len:%d", (char *)buffer, payload_length); + + JsonParser *parser = json_parser_new(); + GError *err_msg = NULL; + JsonNode *root = NULL; + JsonObject *root_obj = NULL; + string msg_id; + const char *json_msgid = NULL; + + json_parser_load_from_data(parser, (char *)buffer, -1, &err_msg); + if (err_msg) { + LOGE("failed to load json file. error message: %s", err_msg->message); + goto cleanup; + } + + root = json_parser_get_root(parser); + if (root == NULL) { + LOGE("failed to get root"); + goto cleanup; + } + + root_obj = json_node_get_object(root); + if (root_obj == NULL) { + LOGE("failed to get object"); + goto cleanup; + } + + json_msgid = json_object_get_string_member(root_obj, "msgId"); + msg_id = string(json_msgid ? json_msgid : ""); + if (msg_id == STICKER_SYNC_START_RSP) { + LOGD("msg : %s", msg_id.c_str()); + const char *json_result = json_object_get_string_member(root_obj, "result"); + string result = string(json_result ? json_result : ""); + int result_code = json_object_get_int_member(root_obj, "resultCode"); + LOGD("result : %s, resultCode : %d", result.c_str(), result_code); + } else if (msg_id == STICKER_SEND_START_REQ) { + LOGD("msg : %s", msg_id.c_str()); + rec_file_cnt = 0; + t_id = json_object_get_int_member(root_obj, "tID"); + JsonArray *file_list = json_object_get_array_member(root_obj, "list"); + if (file_list) { + int arr_len = json_array_get_length(file_list); + for (int i = 0; i < arr_len; i++) { + JsonObject *file_obj = json_array_get_object_element(file_list, i); + int file_len = json_object_get_int_member(file_obj, "size"); + const char *json_filename = json_object_get_string_member(file_obj, "fileName"); + string file_name = string(json_filename ? json_filename : ""); + + if (file_len > 0) { + LOGD("fileName : %s, len : %d", file_name.c_str(), file_len); + } else { + // Delete sticker + LOGD("fileName : %s, len : %d", file_name.c_str(), file_len); + } + } + } + + JsonObject *j_object = json_object_new(); + if (j_object == NULL) { + LOGE("Unable to json_object_new"); + goto cleanup; + } + + json_object_set_string_member(j_object, "msgId", STICKER_SEND_START_RSP); + json_object_set_int_member(j_object, "tID", t_id); + json_object_set_string_member(j_object, "result", "success"); + + if (_send_json_data(j_object) == FALSE) + LOGE("Failed to send message"); + + json_object_unref(j_object); + } else if (msg_id == STICKER_SEND_FACE_DATA) { + LOGD("msg : %s", msg_id.c_str()); + _reset_sticker_data(); + + const char *type_data = json_object_get_string_member(root_obj, "type"); + if (type_data) + sticker_data.disp_type = string(type_data); + + const char *category = json_object_get_string_member(root_obj, "category"); + if (category) { + sticker_data.group = string(category); + sticker_data.keyword = string(category); + } + } else if (msg_id == STICKER_SEND_STOP_REQ) { + LOGD("msg : %s", msg_id.c_str()); + const char *json_reason = json_object_get_string_member(root_obj, "reason"); + string reason = string(json_reason ? json_reason : ""); + int file_len = json_object_get_int_member(root_obj, "count"); + + JsonObject *j_object = json_object_new(); + if (j_object == NULL) { + LOGE("Unable to json_object_new"); + goto cleanup; + } + + json_object_set_string_member(j_object, "msgId", STICKER_SEND_STOP_RSP); + json_object_set_int_member(j_object, "tID", t_id); + + if (reason == "complete" && rec_file_cnt != file_len) + json_object_set_string_member(j_object, "result", "failure"); + else + json_object_set_string_member(j_object, "result", "success"); + + if (_send_json_data(j_object) == FALSE) + LOGE("Failed to send message"); + + json_object_unref(j_object); + } else + LOGW("unknown msg id : %s", msg_id.c_str()); + +cleanup: + if (err_msg) + g_error_free(err_msg); + + if (parser) + g_object_unref(parser); } static void on_conn_req(sap_peer_agent_h peer_agent, @@ -237,10 +460,12 @@ static void on_conn_req(sap_peer_agent_h peer_agent, sap_service_connection_result_e result, void *user_data) { - sap_peer_agent_accept_service_connection(peer_agent); - sap_peer_agent_set_service_connection_terminated_cb(peer_agent, conn_terminated, NULL); - - sap_socket_set_data_received_cb(socket, on_data_received, peer_agent); + if (result == SAP_CONNECTION_SUCCESS) { + priv_data.socket = socket; + sap_peer_agent_accept_service_connection(peer_agent); + sap_peer_agent_set_service_connection_terminated_cb(peer_agent, conn_terminated, NULL); + sap_socket_set_data_received_cb(socket, on_data_received, peer_agent); + } } static void on_agent_initialized(sap_agent_h agent, -- 2.7.4 From fdd038cee5479c940d83df6d87c4677472c4c298 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Wed, 4 Mar 2020 09:21:41 +0900 Subject: [PATCH 16/16] Show error message on connection request callback Change-Id: I1f7a2b11495f7f6740ace2cd935774f529d6d08b Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 49734f1..e388ef0 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -460,11 +460,40 @@ static void on_conn_req(sap_peer_agent_h peer_agent, sap_service_connection_result_e result, void *user_data) { - if (result == SAP_CONNECTION_SUCCESS) { + switch (result) + { + case SAP_CONNECTION_SUCCESS: + LOGI("Connection success"); priv_data.socket = socket; sap_peer_agent_accept_service_connection(peer_agent); sap_peer_agent_set_service_connection_terminated_cb(peer_agent, conn_terminated, NULL); sap_socket_set_data_received_cb(socket, on_data_received, peer_agent); + break; + case SAP_CONNECTION_ALREADY_EXIST: + priv_data.socket = socket; + LOGI("Connection Already Exist"); + break; + case SAP_CONNECTION_FAILURE_DEVICE_UNREACHABLE: + LOGW("Connection failure device unreachable"); + break; + case SAP_CONNECTION_FAILURE_INVALID_PEERAGENT: + LOGW("Connection failure invalid peer agent"); + break; + case SAP_CONNECTION_FAILURE_NETWORK: + LOGW("Connection failure network"); + break; + case SAP_CONNECTION_FAILURE_PEERAGENT_NO_RESPONSE: + LOGW("Connection failure peer agent no response"); + break; + case SAP_CONNECTION_FAILURE_PEERAGENT_REJECTED: + LOGW("Connection failure peer agent rejected"); + break; + case SAP_CONNECTION_FAILURE_UNKNOWN: + LOGW("Connection failure unknown"); + break; + default: + LOGW("Connection failure. error code : %d", result); + break; } } -- 2.7.4