From 1f7fe8f256483a4afd7875e22aba692f317498c1 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 2 Mar 2020 10:39:22 +0900 Subject: [PATCH 01/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 02/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 03/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 04/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 05/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 06/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 From e3ddab16da3e55280f802cbbcee7363ac8b48b92 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 5 Mar 2020 20:44:50 +0900 Subject: [PATCH 07/16] Change way to connect in sticker-receiver Previously, mobile device connects to wearable. From now on, sticker-reciever connect to mobile device to sync sticker data. Change-Id: I7ce6b8664a88a5b0a900369fed52078f3adb3731 Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 171 ++++++++++++++++++++++++++++++++++++++++++++++++-- receiver/src/main.cpp | 55 +++++++++++++++- 2 files changed, 219 insertions(+), 7 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index e388ef0..b926aca 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -48,12 +48,19 @@ using namespace std; -struct priv { +struct sap_info_s { sap_agent_h agent; sap_socket_h socket; + sap_peer_agent_h peer_agent; sap_file_transaction_h file_socket; }; +struct sync_request { + string mode; + string category; + string type; +}; + static void _reset_sticker_data(); struct sticker_info { @@ -69,8 +76,9 @@ struct sticker_info { } }; -static struct priv priv_data = { 0 }; +static struct sap_info_s priv_data = { 0 }; static struct sticker_info sticker_data; +static struct sync_request pending_sync_request; gboolean file_on_progress = 0; static string incoming_file_name; @@ -266,8 +274,13 @@ void request_sticker_data(const char *mode, const char *category, const char *ty 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"); + if (_send_json_data(j_object) == FALSE) { + pending_sync_request.mode = string(mode ? mode : "manual"); + pending_sync_request.category = string(category? category : "arsticker"); + pending_sync_request.type = string(type ? type : "input"); + + LOGI("Push sync request"); + } json_object_unref(j_object); } @@ -304,6 +317,9 @@ void conn_terminated(sap_peer_agent_h peer_agent, sap_service_connection_terminated_reason_e result, void *user_data) { + sap_info_s *priv = NULL; + priv = (sap_info_s *)user_data; + switch (result) { case SAP_CONNECTION_TERMINATED_REASON_PEER_DISCONNECTED: @@ -320,6 +336,9 @@ void conn_terminated(sap_peer_agent_h peer_agent, break; } + sap_socket_destroy(priv->socket); + priv->socket = NULL; + service_app_exit(); } @@ -382,6 +401,9 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in 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"); + if (!json_filename) { + json_filename = json_object_get_string_member(file_obj, "filename"); + } string file_name = string(json_filename ? json_filename : ""); if (file_len > 0) { @@ -466,7 +488,7 @@ static void on_conn_req(sap_peer_agent_h peer_agent, 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_peer_agent_set_service_connection_terminated_cb(peer_agent, conn_terminated, &priv_data); sap_socket_set_data_received_cb(socket, on_data_received, peer_agent); break; case SAP_CONNECTION_ALREADY_EXIST: @@ -497,6 +519,144 @@ static void on_conn_req(sap_peer_agent_h peer_agent, } } +static void +_on_service_connection_created(sap_peer_agent_h peer_agent, + sap_socket_h socket, + sap_service_connection_result_e result, + void *user_data) +{ + sap_info_s *priv = (sap_info_s *)user_data; + + switch (result) + { + case SAP_CONNECTION_SUCCESS: + sap_peer_agent_set_service_connection_terminated_cb(priv->peer_agent, + conn_terminated, + priv); + + sap_socket_set_data_received_cb(socket, on_data_received, peer_agent); + priv->socket = socket; + LOGI("Connection Established"); + + if (!pending_sync_request.mode.empty()) { + LOGD("[Request to sync sticker] mode: %s, category: %s, type : %s", pending_sync_request.mode.c_str(), + pending_sync_request.category.c_str(), + pending_sync_request.type.c_str()); + + request_sticker_data(pending_sync_request.mode.c_str(), pending_sync_request.category.c_str(), pending_sync_request.type.c_str()); + pending_sync_request.mode.clear(); + pending_sync_request.category.clear(); + pending_sync_request.type.clear(); + } + + break; + + case SAP_CONNECTION_ALREADY_EXIST: + priv->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 peer agent unknown"); + break; + + case SAP_CONNECTION_IN_PROGRESS: + LOGW("Connection in progress"); + break; + + case SAP_CONNECTION_PEER_AGENT_NOT_SUPPORTED: + LOGW("Connection peer agent not supported"); + break; + } +} + +static gboolean +_create_service_connection(gpointer user_data) +{ + sap_info_s *priv = (sap_info_s *)user_data; + int result = sap_agent_request_service_connection(priv->agent, + priv->peer_agent, + _on_service_connection_created, + priv); + + LOGD("request connection result : %d", result); + + return FALSE; +} + +static void +_on_peer_agent_updated(sap_peer_agent_h peer_agent, + sap_peer_agent_status_e peer_status, + sap_peer_agent_found_result_e result, + void *user_data) +{ + sap_info_s *priv = (sap_info_s *)user_data; + + switch (result) + { + case SAP_PEER_AGENT_FOUND_RESULT_DEVICE_NOT_CONNECTED: + LOGW("SAP_PEER_AGENT_FOUND_RESULT_DEVICE_NOT_CONNECTED"); + break; + + case SAP_PEER_AGENT_FOUND_RESULT_FOUND: + if (peer_status == SAP_PEER_AGENT_STATUS_AVAILABLE) + { + LOGD("SAP_PEER_AGENT_FOUND_RESULT_FOUND"); + priv->peer_agent = peer_agent; + g_idle_add(_create_service_connection, priv); + } + else + { + sap_peer_agent_destroy(peer_agent); + } + break; + + case SAP_PEER_AGENT_FOUND_RESULT_SERVICE_NOT_FOUND: + LOGW("SAP_PEER_AGENT_FOUND_RESULT_SERVICE_NOT_FOUND"); + break; + + case SAP_PEER_AGENT_FOUND_RESULT_TIMEDOUT: + LOGW("SAP_PEER_AGENT_FOUND_RESULT_TIMEDOUT"); + break; + + case SAP_PEER_AGENT_FOUND_RESULT_INTERNAL_ERROR: + LOGW("SAP_PEER_AGENT_FOUND_RESULT_INTERNAL_ERROR"); + break; + + default: + break; + } +} + +static gboolean +_find_peer_agent(gpointer user_data) +{ + sap_info_s *priv = (sap_info_s *)user_data; + sap_agent_find_peer_agent(priv->agent, _on_peer_agent_updated, priv); + + return FALSE; +} + static void on_agent_initialized(sap_agent_h agent, sap_agent_initialized_result_e result, void *user_data) @@ -566,6 +726,7 @@ static void _on_device_status_changed(sap_device_status_e status, break; case SAP_DEVICE_STATUS_ATTACHED: LOGD("Attached calling find peer now"); + g_idle_add(_find_peer_agent, &priv_data); break; default: LOGE("unknown status (%d)", status); diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index 3bf6300..6191a28 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -1,8 +1,10 @@ +#include +#include +#include + #include "main.h" #include "ft.h" #include "log.h" -#include -#include static bool app_create(void *data) { @@ -19,6 +21,55 @@ static bool app_create(void *data) static void app_control(app_control_h app_control, void *data) { /* Handle the launch request. */ + char* request = NULL; + char* mode = NULL; + char* category = NULL; + char* type = NULL; + + int res; + + // sync request + res = app_control_get_extra_data(app_control, "request", &request); + if (APP_CONTROL_ERROR_NONE == res && NULL != request) + { + if (strcmp(request, "sync") == 0) + { + if (app_control_get_extra_data(app_control, "mode", &mode) != APP_CONTROL_ERROR_NONE) + { + LOGE("No given mode"); + goto cleanup; + } + + if (app_control_get_extra_data(app_control, "category", &category) != APP_CONTROL_ERROR_NONE) + { + LOGE("No given category"); + goto cleanup; + } + + if (app_control_get_extra_data(app_control, "type", &type) != APP_CONTROL_ERROR_NONE) + { + LOGE("No given type"); + goto cleanup; + } + + LOGI("[sync request] mode : %s, category : %s, type : %s", mode, category, type); + + if (mode && category && type) + request_sticker_data(mode, category, type); + } + } +cleanup: + if (NULL != request) + free(request); + + if (NULL != mode) + free(mode); + + if (NULL != category) + free(category); + + if (NULL != type) + free(type); } static void app_terminate(void *data) -- 2.7.4 From 12ff94b22ef8b0c32a0993e9cb3fef8a009936b6 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Wed, 4 Mar 2020 16:33:06 +0900 Subject: [PATCH 08/16] Notify total sync progress Change-Id: I190b9c1ab519b80abd3dbf1af91613eea2dd30d2 Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 1 + receiver/CMakeLists.txt | 2 + receiver/inc/message.h | 26 +++++++++++++ receiver/src/ft.cpp | 18 +++++++++ receiver/src/message.cpp | 88 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 135 insertions(+) create mode 100644 receiver/inc/message.h create mode 100644 receiver/src/message.cpp diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 269d1fb..d0a5352 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -27,6 +27,7 @@ BuildRequires: pkgconfig(sqlite3) %if 0%{?sec_product_feature_profile_wearable} BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(capi-appfw-service-application) +BuildRequires: pkgconfig(capi-message-port) BuildRequires: pkgconfig(sap-client-stub-api) BuildRequires: hash-signer diff --git a/receiver/CMakeLists.txt b/receiver/CMakeLists.txt index 247230a..7838d26 100644 --- a/receiver/CMakeLists.txt +++ b/receiver/CMakeLists.txt @@ -5,6 +5,7 @@ SET(SRCS src/main.cpp src/ft.cpp src/sticker_info.cpp + src/message.cpp ) INCLUDE(FindPkgConfig) @@ -12,6 +13,7 @@ pkg_check_modules(pkgs_test REQUIRED capi-base-common dlog capi-appfw-service-application + capi-message-port sap-client-stub-api json-glib-1.0 ) diff --git a/receiver/inc/message.h b/receiver/inc/message.h new file mode 100644 index 0000000..392f1cd --- /dev/null +++ b/receiver/inc/message.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2020 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. + */ +#include +#include + +#ifndef __MESSAGE_H__ +#define __MESSAGE_H__ + +bool message_sink_init(message_port_message_cb callback, void *user_data); +void message_sink_shutdown(void); +bool send_message(const char *cmd, const char *data); + +#endif /* __MESSAGE_H__ */ diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index b926aca..7e22b1c 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -34,6 +34,7 @@ #include "ft.h" #include "log.h" #include "sticker_info.h" +#include "message.h" #define ACCESSORY_SERVICE_PROFILE_ID "/sample/filetransfersender" #define ACCESSORY_SERVICE_CHANNEL_ID 107 @@ -84,6 +85,7 @@ gboolean file_on_progress = 0; static string incoming_file_name; static int t_id = 0; static int rec_file_cnt = 0; +static int total_file_count = 0; static gboolean _send_json_data(JsonObject *obj) { @@ -132,6 +134,19 @@ cleanup: return result ? FALSE : TRUE; } +static void notify_sync_progress(unsigned int file_progress) +{ + if (total_file_count == 0) + return; + + double total_progress = (((double)rec_file_cnt / (double)total_file_count) + (1.0/(double)total_file_count*file_progress/100))*100; + + LOGI("recv : %d, total : %d, file_progress : %d, %u%%", rec_file_cnt, total_file_count, file_progress, (unsigned int)total_progress); + char progress_str[32]; + snprintf(progress_str, sizeof(progress_str), "%u", (unsigned int)total_progress); + send_message("sync_progress", progress_str); +} + static void _on_send_completed(sap_file_transaction_h file_transaction, sap_ft_transfer_e result, const char *file_path, @@ -216,6 +231,7 @@ static void _on_sending_file_in_progress(sap_file_transaction_h file_transaction void *user_data) { LOGI("# progress %d", percentage_progress); + notify_sync_progress(percentage_progress); } static void __set_file_transfer_cb(sap_file_transaction_h file_socket) @@ -392,6 +408,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in 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()); + total_file_count = 0; 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"); @@ -408,6 +425,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in if (file_len > 0) { LOGD("fileName : %s, len : %d", file_name.c_str(), file_len); + total_file_count++; } else { // Delete sticker LOGD("fileName : %s, len : %d", file_name.c_str(), file_len); diff --git a/receiver/src/message.cpp b/receiver/src/message.cpp new file mode 100644 index 0000000..4513000 --- /dev/null +++ b/receiver/src/message.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2020 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. + */ + +#include + +#include "message.h" +#include "log.h" + +#define REMOTE_APP_ID "com.samsung.w-input-selector" +#define MESSAGE_PORT_REMOTE_NAME REMOTE_APP_ID"_msg_port_rcv" + +static int port_id = -1; + +bool message_sink_init(message_port_message_cb callback, void *user_data) +{ + port_id = message_port_register_local_port(MESSAGE_PORT_REMOTE_NAME, callback, user_data); + if (port_id < 0) + { + LOGW("Function message_port_register_local_port() failed."); + return false; + } + + return true; +} + +void message_sink_shutdown(void) +{ + int ret; + bool exists = false; + + port_id = -1; + + ret = message_port_check_remote_port(REMOTE_APP_ID, MESSAGE_PORT_REMOTE_NAME, &exists); + if (exists) + { + ret = message_port_unregister_local_port(port_id); + if (ret != MESSAGE_PORT_ERROR_NONE) + LOGE("Function message_port_unregister_local_port() failed."); + } + else if (ret != MESSAGE_PORT_ERROR_NONE) + { + LOGE("Function message_port_check_remote_port() failed."); + } +} + +bool send_message(const char *cmd, const char *data) +{ + bool result = false; + int ret; + bool found = false; + + message_port_check_remote_port(REMOTE_APP_ID, MESSAGE_PORT_REMOTE_NAME, &found); + if (!found) { + LOGW("Can't find remote port"); + return false; + } + + bundle *b = bundle_create(); + bundle_add_str(b, "command", cmd); + bundle_add_str(b, "data", data); + ret = message_port_send_message(REMOTE_APP_ID, MESSAGE_PORT_REMOTE_NAME, b); + if (ret != MESSAGE_PORT_ERROR_NONE) { + LOGW("message port send message error. err : %d", ret); + result = false; + } + else + { + LOGI("send message done"); + result = true; + } + + bundle_free(b); + + return result; +} \ No newline at end of file -- 2.7.4 From 89fdf3ac9c9c99dc055315e21c38b4b59555ac9c Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 6 Mar 2020 10:01:59 +0900 Subject: [PATCH 09/16] Update package version to 0.1.16 Change-Id: I19117b7cd18eda7e459a0850f68f3b16d919f4ea Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 2 +- receiver/tizen-manifest.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index d0a5352..0f75508 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.15 +Version: 0.1.16 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index ed96552..6e83709 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -1,5 +1,5 @@ - + -- 2.7.4 From 2340ef19dd62775f8cea4887e3d2d40f8a759b4a Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 6 Mar 2020 13:03:43 +0900 Subject: [PATCH 10/16] Set sync completion flags Change-Id: I8029dd4516aaa849428e7d3ec3591704b6754253 Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 1 + receiver/CMakeLists.txt | 1 + receiver/src/ft.cpp | 22 +++++++++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 0f75508..daabef7 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -29,6 +29,7 @@ BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(capi-appfw-service-application) BuildRequires: pkgconfig(capi-message-port) BuildRequires: pkgconfig(sap-client-stub-api) +BuildRequires: pkgconfig(vconf) BuildRequires: hash-signer Requires(post): signing-client diff --git a/receiver/CMakeLists.txt b/receiver/CMakeLists.txt index 7838d26..9cd44fb 100644 --- a/receiver/CMakeLists.txt +++ b/receiver/CMakeLists.txt @@ -16,6 +16,7 @@ pkg_check_modules(pkgs_test REQUIRED capi-message-port sap-client-stub-api json-glib-1.0 + vconf ) INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/receiver/inc) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 7e22b1c..d1c960f 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "ft.h" #include "log.h" @@ -477,8 +478,27 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in if (reason == "complete" && rec_file_cnt != file_len) json_object_set_string_member(j_object, "result", "failure"); - else + else { + int complete_flags = 0; + if (vconf_get_int(VCONFKEY_STICKER_SYNC_COMPLETE, &complete_flags) == 0) { + if (sticker_data.group == string("arsticker")) + complete_flags |= 0x1; + else if (sticker_data.group == string("bitmoji")) + complete_flags |= 0x2; + + LOGD("sync complete flag : %x", complete_flags); + + if (vconf_set_int(VCONFKEY_STICKER_SYNC_COMPLETE, complete_flags) == 0) + LOGD("Succeed to set sync complete"); + else + LOGW("Fail to set sync complete"); + } + else { + LOGW("Failed to get sticker sync flags"); + } + json_object_set_string_member(j_object, "result", "success"); + } if (_send_json_data(j_object) == FALSE) LOGE("Failed to send message"); -- 2.7.4 From 4d956f366c30967e45d10efe20662d69b29c9dfe Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 6 Mar 2020 13:27:34 +0900 Subject: [PATCH 11/16] Update package version to 0.1.17 Change-Id: I6d172f4f66dcea406d67415fa9948031240bccdb Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 2 +- receiver/tizen-manifest.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index daabef7..0280700 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.16 +Version: 0.1.17 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index 6e83709..980a4aa 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -1,5 +1,5 @@ - + -- 2.7.4 From b620032421913f411ca4dc7860edbd83d19f33f8 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 6 Mar 2020 18:54:36 +0900 Subject: [PATCH 12/16] Add more logs Change-Id: I691840b100107265cf9f9003b4e9d0d1c7942a3d Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 3 +-- receiver/src/main.cpp | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index d1c960f..764d552 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -142,7 +142,7 @@ static void notify_sync_progress(unsigned int file_progress) double total_progress = (((double)rec_file_cnt / (double)total_file_count) + (1.0/(double)total_file_count*file_progress/100))*100; - LOGI("recv : %d, total : %d, file_progress : %d, %u%%", rec_file_cnt, total_file_count, file_progress, (unsigned int)total_progress); + LOGI("(%2d / %2d), file progress : %3u%%, total progress : %3u%%", rec_file_cnt, total_file_count, file_progress, (unsigned int)total_progress); char progress_str[32]; snprintf(progress_str, sizeof(progress_str), "%u", (unsigned int)total_progress); send_message("sync_progress", progress_str); @@ -231,7 +231,6 @@ static void _on_sending_file_in_progress(sap_file_transaction_h file_transaction unsigned short int percentage_progress, void *user_data) { - LOGI("# progress %d", percentage_progress); notify_sync_progress(percentage_progress); } diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index 6191a28..6f728fe 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -57,6 +57,11 @@ static void app_control(app_control_h app_control, void *data) if (mode && category && type) request_sticker_data(mode, category, type); } + else + { + LOGW("Unknown command : %s", request); + } + } cleanup: if (NULL != request) -- 2.7.4 From effe5a7d5011fbb42eaa5bc2cec7ab5ac2ab22b3 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Mon, 9 Mar 2020 13:02:06 +0900 Subject: [PATCH 13/16] Send response and result to requester application Change-Id: I7860eaee2dc6fe3253fed0d4b6324e83797fe521 Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 24 ++++++++++++++++++++++++ receiver/src/message.cpp | 4 +++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 764d552..c8d83eb 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -82,6 +82,12 @@ static struct sap_info_s priv_data = { 0 }; static struct sticker_info sticker_data; static struct sync_request pending_sync_request; +enum { + SYNC_START_RSP_SUCCESS = 1000, + SYNC_START_RSP_NO_STICKER = 1001, + SYNC_START_RSP_EXIST_STICKER = 1002 +}; + gboolean file_on_progress = 0; static string incoming_file_name; static int t_id = 0; @@ -406,6 +412,22 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in 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); + + string response_to_app; + switch (result_code) { + case SYNC_START_RSP_SUCCESS: + case SYNC_START_RSP_EXIST_STICKER: + response_to_app = "success"; + break; + case SYNC_START_RSP_NO_STICKER: + response_to_app = "no_sticker"; + break; + default: + response_to_app = "unknown_error"; + break; + } + + send_message("sync_start_response", response_to_app.c_str()); } else if (msg_id == STICKER_SEND_START_REQ) { LOGD("msg : %s", msg_id.c_str()); total_file_count = 0; @@ -502,6 +524,8 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in if (_send_json_data(j_object) == FALSE) LOGE("Failed to send message"); + send_message("sync_stop_result", reason.c_str()); + json_object_unref(j_object); } else LOGW("unknown msg id : %s", msg_id.c_str()); diff --git a/receiver/src/message.cpp b/receiver/src/message.cpp index 4513000..f67b29e 100644 --- a/receiver/src/message.cpp +++ b/receiver/src/message.cpp @@ -62,6 +62,8 @@ bool send_message(const char *cmd, const char *data) int ret; bool found = false; + LOGD("command: %s, data: %s", cmd, data); + message_port_check_remote_port(REMOTE_APP_ID, MESSAGE_PORT_REMOTE_NAME, &found); if (!found) { LOGW("Can't find remote port"); @@ -78,7 +80,7 @@ bool send_message(const char *cmd, const char *data) } else { - LOGI("send message done"); + LOGI("Succeed to send message."); result = true; } -- 2.7.4 From 6925b1f23e169b3c20dfca754f7fcba7ed334192 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Mon, 9 Mar 2020 16:19:05 +0900 Subject: [PATCH 14/16] Update package version to 0.1.18 Change-Id: Ia8918ad0db06842948ff6f43542d9ac99ccba449 Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 2 +- receiver/tizen-manifest.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 0280700..1abd1c0 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.17 +Version: 0.1.18 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index 980a4aa..8309056 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -1,5 +1,5 @@ - + -- 2.7.4 From e4ef3a0421e0238f0febd7e44d3e89da0fbc73b8 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 9 Mar 2020 17:16:35 +0900 Subject: [PATCH 15/16] Add a code for removing sticker data Change-Id: I70ba9a3ec0f887a8c6eaf4e144d7754cf56739ce --- receiver/inc/sticker_info.h | 1 + receiver/src/ft.cpp | 9 +++++--- receiver/src/sticker_info.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/receiver/inc/sticker_info.h b/receiver/inc/sticker_info.h index 7cf88fe..bda6616 100644 --- a/receiver/inc/sticker_info.h +++ b/receiver/inc/sticker_info.h @@ -4,5 +4,6 @@ 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); +void delete_sticker_data(const char *fileName); #endif /* __STICKER_INF_H__ */ diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index c8d83eb..fae0991 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -446,11 +446,14 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in string file_name = string(json_filename ? json_filename : ""); if (file_len > 0) { - LOGD("fileName : %s, len : %d", file_name.c_str(), file_len); + LOGD("Add file : %s, len : %d", file_name.c_str(), file_len); total_file_count++; } else { - // Delete sticker - LOGD("fileName : %s, len : %d", file_name.c_str(), file_len); + LOGD("Delete file : %s, len : %d", file_name.c_str(), file_len); + if (create_sticker_provider_handle() == STICKER_ERROR_NONE) { + delete_sticker_data(file_name.c_str()); + destroy_sticker_provider_handle(); + } } } } diff --git a/receiver/src/sticker_info.cpp b/receiver/src/sticker_info.cpp index a391fc2..1ac2247 100644 --- a/receiver/src/sticker_info.cpp +++ b/receiver/src/sticker_info.cpp @@ -3,10 +3,14 @@ #include #include #include +#include #include "log.h" +using namespace std; + static sticker_provider_h sticker_provider = NULL; +static bool need_to_retrive = false; sticker_data_h set_sticker_data(sticker_data_uri_type_e type, const char* uri, const char* keyword, @@ -106,3 +110,47 @@ void destroy_sticker_provider_handle(void) sticker_provider_destroy(sticker_provider); sticker_provider = NULL; } + +static void _sticker_foreach_cb(sticker_data_h data_handle, void *user_data) +{ + int ret; + char *del_file = (char *)user_data; + sticker_data_uri_type_e type; + char *uri = NULL; + + if (!need_to_retrive) + return; + + ret = sticker_data_get_uri(data_handle, &type, &uri); + if (ret != STICKER_ERROR_NONE) + LOGE("Failed to get sticker uri"); + + int result = (string(uri)).find(del_file); + if (result >= 0) { + LOGI("Delete sticker (%s)", uri); + need_to_retrive = false; + + ret = sticker_provider_delete_data(sticker_provider, data_handle); + if (ret != STICKER_ERROR_NONE) + LOGE("Failed to delete sticker"); + } +} + +void delete_sticker_data(const char *fileName) +{ + int ret; + int offset = 0; + int count = 0; + int result = 0; + need_to_retrive = true; + + while (result == count && need_to_retrive) { + count = 20; + ret = sticker_provider_data_foreach_all(sticker_provider, offset, count, &result, _sticker_foreach_cb, (void *)fileName); + offset += result; + if (ret != STICKER_ERROR_NONE) { + LOGE("Failed to retrieve sticker"); + return; + } + } +} \ No newline at end of file -- 2.7.4 From ac5dfc1d4595dfeb4697143246c769d60ab9fce9 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 9 Mar 2020 17:18:19 +0900 Subject: [PATCH 16/16] Update package version to 0.1.19 Change-Id: I0976c20df26b65d3151f579ab9cc36bf1c6da6ec --- packaging/capi-ui-sticker.spec | 2 +- receiver/tizen-manifest.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 1abd1c0..97e6304 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.18 +Version: 0.1.19 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index 8309056..0d73867 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -1,5 +1,5 @@ - + -- 2.7.4