From fdd038cee5479c940d83df6d87c4677472c4c298 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Wed, 4 Mar 2020 09:21:41 +0900 Subject: [PATCH 01/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 02/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 03/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 04/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 05/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 06/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 07/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 08/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 09/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 10/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 11/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 From 072b486a1a6e8211835ebd70d0243f3ec6e91dd9 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Wed, 26 Feb 2020 16:37:45 +0900 Subject: [PATCH 12/16] Support to request sticker sync periodically Change-Id: I73467303f4a1cfec69b02a6c1ee4a4410cde0e58 Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 2 + receiver/CMakeLists.txt | 4 ++ receiver/inc/sync_alarm.h | 28 +++++++++++ receiver/src/ft.cpp | 22 ++++++++- receiver/src/main.cpp | 67 +++++++++++++++++++++----- receiver/src/sync_alarm.cpp | 107 +++++++++++++++++++++++++++++++++++++++++ receiver/tizen-manifest.xml | 5 ++ 7 files changed, 221 insertions(+), 14 deletions(-) create mode 100644 receiver/inc/sync_alarm.h create mode 100644 receiver/src/sync_alarm.cpp diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 97e6304..967fe41 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -28,6 +28,8 @@ BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(capi-appfw-service-application) BuildRequires: pkgconfig(capi-message-port) +BuildRequires: pkgconfig(capi-appfw-alarm) +BuildRequires: pkgconfig(capi-system-device) BuildRequires: pkgconfig(sap-client-stub-api) BuildRequires: pkgconfig(vconf) BuildRequires: hash-signer diff --git a/receiver/CMakeLists.txt b/receiver/CMakeLists.txt index 9cd44fb..73d4503 100644 --- a/receiver/CMakeLists.txt +++ b/receiver/CMakeLists.txt @@ -6,6 +6,7 @@ SET(SRCS src/ft.cpp src/sticker_info.cpp src/message.cpp + src/sync_alarm.cpp ) INCLUDE(FindPkgConfig) @@ -14,6 +15,9 @@ pkg_check_modules(pkgs_test REQUIRED dlog capi-appfw-service-application capi-message-port + capi-appfw-app-common + capi-appfw-alarm + capi-system-device sap-client-stub-api json-glib-1.0 vconf diff --git a/receiver/inc/sync_alarm.h b/receiver/inc/sync_alarm.h new file mode 100644 index 0000000..e46515c --- /dev/null +++ b/receiver/inc/sync_alarm.h @@ -0,0 +1,28 @@ +/* + * 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 + +#ifndef __ALARM_H__ +#define __ALARM_H__ + +#define APP_CONTROL_OPERATION_SYNC_ALARM "http://tizen.org/appcontrol/operation/sticker_sync_alarm" +#define SYNC_ALARM_DELAY 0 +#define SYNC_ALARM_INTERVAL 12*60*60 + +bool sync_alarm_register(const char *operation, int delay, int period); +bool sync_alarm_exist(); + +#endif /* __ALARM_H__ */ diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index fae0991..c8c7bdb 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -36,6 +36,7 @@ #include "log.h" #include "sticker_info.h" #include "message.h" +#include "sync_alarm.h" #define ACCESSORY_SERVICE_PROFILE_ID "/sample/filetransfersender" #define ACCESSORY_SERVICE_CHANNEL_ID 107 @@ -80,7 +81,7 @@ struct sticker_info { static struct sap_info_s priv_data = { 0 }; static struct sticker_info sticker_data; -static struct sync_request pending_sync_request; +static struct sync_request pending_sync_request, current_sync_request; enum { SYNC_START_RSP_SUCCESS = 1000, @@ -303,6 +304,11 @@ void request_sticker_data(const char *mode, const char *category, const char *ty LOGI("Push sync request"); } + else { + current_sync_request.mode = string(mode ? mode : "manual"); + current_sync_request.category = string(category? category : "arsticker"); + current_sync_request.type = string(type ? type : "input"); + } json_object_unref(j_object); } @@ -522,6 +528,15 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in } json_object_set_string_member(j_object, "result", "success"); + + if (current_sync_request.mode == string("oobe")) { + LOGD("alarm exist : %d", sync_alarm_exist()); + sync_alarm_register(APP_CONTROL_OPERATION_SYNC_ALARM, SYNC_ALARM_DELAY, SYNC_ALARM_INTERVAL); + } + else if (current_sync_request.mode == string("manual")) { + if (!sync_alarm_exist()) + sync_alarm_register(APP_CONTROL_OPERATION_SYNC_ALARM, SYNC_ALARM_DELAY, SYNC_ALARM_INTERVAL); + } } if (_send_json_data(j_object) == FALSE) @@ -530,6 +545,10 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in send_message("sync_stop_result", reason.c_str()); json_object_unref(j_object); + + current_sync_request.mode.clear(); + current_sync_request.category.clear(); + current_sync_request.type.clear(); } else LOGW("unknown msg id : %s", msg_id.c_str()); @@ -608,6 +627,7 @@ _on_service_connection_created(sap_peer_agent_h peer_agent, 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(); diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index 6f728fe..1a2ad84 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -1,10 +1,15 @@ #include #include #include +#include +#include #include "main.h" #include "ft.h" #include "log.h" +#include "sync_alarm.h" + +#define MINIMUM_BATTERY 15 static bool app_create(void *data) { @@ -25,35 +30,68 @@ static void app_control(app_control_h app_control, void *data) char* mode = NULL; char* category = NULL; char* type = NULL; + char* operation = NULL; + char* alarm_data = NULL; int res; + // operation + int ret = app_control_get_operation(app_control, &operation); + if (ret == APP_CONTROL_ERROR_NONE) { + LOGD("operation: %s", operation); + + if (operation && (strncmp(operation, APP_CONTROL_OPERATION_SYNC_ALARM, strlen(APP_CONTROL_OPERATION_SYNC_ALARM)) == 0)) { + ret = app_control_get_extra_data(app_control, APP_CONTROL_DATA_ALARM_ID, &alarm_data); + if (ret != APP_CONTROL_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "Function app_control_get_extra_data() failed."); + goto cleanup; + } + + LOGD("alarm data : %s", alarm_data); + + int battery_percentage = 0; + int ret = device_battery_get_percent(&battery_percentage); + if (ret == DEVICE_ERROR_NONE) { + LOGD("battery percent : %d", battery_percentage); + if (battery_percentage >= MINIMUM_BATTERY) { + request_sticker_data("auto", "arsticker", "input"); + request_sticker_data("auto", "bitmoji", "input"); + } + else { + LOGD("No sync request due to insufficient battery"); + } + } + else { + LOGW("Failed to get battery percent. error : %d", ret); + } + + goto cleanup; + } + } + else { + LOGW("Failed to get operation. error : %d", ret); + } + // 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) - { + if (APP_CONTROL_ERROR_NONE == res && NULL != request) { + if (strcmp(request, "sync") == 0) { + LOGI("[sync request] mode : %s, category : %s, type : %s", mode, category, type); + 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) - { + 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) - { + 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); } @@ -61,9 +99,12 @@ static void app_control(app_control_h app_control, void *data) { LOGW("Unknown command : %s", request); } - } + cleanup: + if (NULL != operation) + free(operation); + if (NULL != request) free(request); diff --git a/receiver/src/sync_alarm.cpp b/receiver/src/sync_alarm.cpp new file mode 100644 index 0000000..d4879d8 --- /dev/null +++ b/receiver/src/sync_alarm.cpp @@ -0,0 +1,107 @@ +/* + * 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 +#include + +#include "log.h" + +static int recurring_alarm_id = -1; + +static bool +on_foreach_registered_alarm(int alarm_id, void *user_data) +{ + bool *result = (bool *)user_data; + + LOGD("alarm id : %d", alarm_id); + + *result = *result | 0x1; + + return false; +} + +bool sync_alarm_register(const char *operation, int delay, int period) +{ + int ret; + app_control_h app_control = NULL; + char *app_id = NULL; + bool result = false; + + ret = app_control_create(&app_control); + if (ret != APP_CONTROL_ERROR_NONE) + { + LOGE("Function app_control_create() failed."); + return false; + } + + ret = app_control_set_operation(app_control, operation); + if (ret != APP_CONTROL_ERROR_NONE) + { + LOGE("Function app_control_set_operation() failed."); + goto cleanup; + } + + if (app_get_id(&app_id) != APP_ERROR_NONE) { + goto cleanup; + } + + LOGD("app id : %s", app_id); + if (!app_id) { + goto cleanup; + } + + ret = app_control_set_app_id(app_control, app_id); + if (ret != APP_CONTROL_ERROR_NONE) + { + LOGE("Function app_control_set_app_id() failed."); + goto cleanup; + } + + alarm_cancel_all(); + + ret = alarm_schedule_after_delay(app_control, delay, period, &recurring_alarm_id); + if (ret != ALARM_ERROR_NONE) + LOGE("Function alarm_schedule_after_delay() failed."); + else + LOGD("Function alarm_schedule_after_delay() succeed. delay : %d, interval : %d", delay, period); + + result = true; + +cleanup: + if (app_id) + free(app_id); + + if (app_control) { + ret = app_control_destroy(app_control); + if (ret != APP_CONTROL_ERROR_NONE) + LOGE("Function app_control_destroy() failed."); + else + LOGD("Set recurring alarm with id: %i", recurring_alarm_id); + } + + return result; +} + +bool sync_alarm_exist() +{ + bool result = false; + int ret = alarm_foreach_registered_alarm(on_foreach_registered_alarm, &result); + if (ret != ALARM_ERROR_NONE) + LOGD("Listing error : %d", ret); + + return result; +} \ No newline at end of file diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index 0d73867..b53fdc6 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -5,6 +5,8 @@ + + @@ -12,6 +14,9 @@ http://tizen.org/privilege/content.write http://tizen.org/privilege/mediastorage http://tizen.org/privilege/appdir.shareddata + http://tizen.org/privilege/alarm.set + http://tizen.org/privilege/alarm.get + http://tizen.org/privilege/appmanager.launch -- 2.7.4 From f971508dcec80337abb1e2d90ae1f1caae2045c6 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Tue, 10 Mar 2020 19:32:20 +0900 Subject: [PATCH 13/16] Fix wrong log to display mode, category, and type Change-Id: I3aa7aac680e1902726acebc7b1ee2644aa8fcec8 Signed-off-by: Jihoon Kim --- receiver/src/main.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index 1a2ad84..3ad20b5 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -76,22 +76,26 @@ static void app_control(app_control_h app_control, void *data) res = app_control_get_extra_data(app_control, "request", &request); if (APP_CONTROL_ERROR_NONE == res && NULL != request) { if (strcmp(request, "sync") == 0) { - LOGI("[sync request] mode : %s, category : %s, type : %s", mode, category, type); + bool param_error = false; if (app_control_get_extra_data(app_control, "mode", &mode) != APP_CONTROL_ERROR_NONE) { LOGE("No given mode"); - goto cleanup; + param_error = true; } if (app_control_get_extra_data(app_control, "category", &category) != APP_CONTROL_ERROR_NONE) { LOGE("No given category"); - goto cleanup; + param_error = true; } if (app_control_get_extra_data(app_control, "type", &type) != APP_CONTROL_ERROR_NONE) { LOGE("No given type"); - goto cleanup; + param_error = true; } + LOGI("[sync request] mode : %s, category : %s, type : %s", mode, category, type); + if (param_error) + goto cleanup; + if (mode && category && type) request_sticker_data(mode, category, type); } -- 2.7.4 From 85be69d04adab2258bc4caad5ee7c15d53699836 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Tue, 10 Mar 2020 17:07:18 +0900 Subject: [PATCH 14/16] Add oobe mode for initializing Change-Id: Ib8921c4517ddfd85611fa65731a9a724745b4721 Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 6 +----- receiver/src/main.cpp | 5 +++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index c8c7bdb..53427fb 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -529,11 +529,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in json_object_set_string_member(j_object, "result", "success"); - if (current_sync_request.mode == string("oobe")) { - LOGD("alarm exist : %d", sync_alarm_exist()); - sync_alarm_register(APP_CONTROL_OPERATION_SYNC_ALARM, SYNC_ALARM_DELAY, SYNC_ALARM_INTERVAL); - } - else if (current_sync_request.mode == string("manual")) { + if (current_sync_request.mode == string("manual")) { if (!sync_alarm_exist()) sync_alarm_register(APP_CONTROL_OPERATION_SYNC_ALARM, SYNC_ALARM_DELAY, SYNC_ALARM_INTERVAL); } diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index 3ad20b5..394f38f 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -99,6 +99,11 @@ static void app_control(app_control_h app_control, void *data) if (mode && category && type) request_sticker_data(mode, category, type); } + else if (strcmp(request, "oobe") == 0) { + LOGI("[OOBE] register sync alarm"); + sync_alarm_register(APP_CONTROL_OPERATION_SYNC_ALARM, SYNC_ALARM_DELAY, SYNC_ALARM_INTERVAL); + service_app_exit(); + } else { LOGW("Unknown command : %s", request); -- 2.7.4 From 19b7e372fb1cc17a60ae84b7d43271fb5057df23 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Wed, 11 Mar 2020 15:14:34 +0900 Subject: [PATCH 15/16] Remove category in app_control Change-Id: I1f88218aff1e8534167a0aea335cd4bc1c6e01ac Signed-off-by: Jihoon Kim --- receiver/src/main.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index 394f38f..115d278 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -28,7 +28,6 @@ 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; char* operation = NULL; char* alarm_data = NULL; @@ -82,22 +81,17 @@ static void app_control(app_control_h app_control, void *data) param_error = true; } - if (app_control_get_extra_data(app_control, "category", &category) != APP_CONTROL_ERROR_NONE) { - LOGE("No given category"); - param_error = true; - } - if (app_control_get_extra_data(app_control, "type", &type) != APP_CONTROL_ERROR_NONE) { LOGE("No given type"); param_error = true; } - LOGI("[sync request] mode : %s, category : %s, type : %s", mode, category, type); + LOGI("[sync request] mode : %s, type : %s", mode, type); if (param_error) goto cleanup; - if (mode && category && type) - request_sticker_data(mode, category, type); + if (mode && type) + request_sticker_data(mode, "arsticker", type); } else if (strcmp(request, "oobe") == 0) { LOGI("[OOBE] register sync alarm"); @@ -120,9 +114,6 @@ cleanup: if (NULL != mode) free(mode); - if (NULL != category) - free(category); - if (NULL != type) free(type); } -- 2.7.4 From cb91fa6fbccd6a5dd8c32c1c3b5f3c08c2d148a6 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Wed, 11 Mar 2020 18:23:46 +0900 Subject: [PATCH 16/16] Update package version to 0.1.20 Change-Id: Ic1cc1ff1362b67c0c589c43db03ee88c72f278dc 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 967fe41..c562a85 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.19 +Version: 0.1.20 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index b53fdc6..cbd4cfe 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -1,5 +1,5 @@ - + -- 2.7.4