From f039d017f8e39e00463789e74196cb11a074051d Mon Sep 17 00:00:00 2001 From: InHong Han Date: Thu, 2 Apr 2020 10:58:28 +0900 Subject: [PATCH 01/16] Remove unnecessary variable Change-Id: I8e745998dfe86181d30f7ac995081c448dff05f4 --- sticker-parser/sticker-parser.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/sticker-parser/sticker-parser.c b/sticker-parser/sticker-parser.c index 21debd2..86ebd3e 100644 --- a/sticker-parser/sticker-parser.c +++ b/sticker-parser/sticker-parser.c @@ -348,21 +348,17 @@ cleanup: return ret; } -static char* __convert_sticker_uri(const char *uri, const char *appid, const char *app_path) +static char* __convert_sticker_uri(char *uri, const char *appid, const char *app_path) { int ret; - char *rel_path = strdup(uri); - __remove_app_path(rel_path, app_path); - int len = strlen(STICKER_DIRECTORY) + strlen(appid) + strlen(rel_path) + 2; + __remove_app_path(uri, app_path); + int len = strlen(STICKER_DIRECTORY) + strlen(appid) + strlen(uri) + 2; char *new_path = (char *)calloc(len, sizeof(char)); - if (new_path == NULL) { - free(rel_path); - rel_path = NULL; + if (new_path == NULL) return NULL; - } - snprintf(new_path, len, "%s/%s%s",STICKER_DIRECTORY, appid, rel_path); + snprintf(new_path, len, "%s/%s%s",STICKER_DIRECTORY, appid, uri); if (access(new_path, F_OK) == 0) { LOGE("sticker file already exists"); @@ -393,9 +389,6 @@ static char* __convert_sticker_uri(const char *uri, const char *appid, const cha LOGE("failed to change ownership"); cleanup: - free(rel_path); - rel_path = NULL; - if (ret == 0) { return new_path; } else { -- 2.7.4 From 932ccfe230aafd5b4a70b539d1fa9ef05e2b9cc9 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 2 Apr 2020 19:04:03 +0900 Subject: [PATCH 02/16] Update package version to 0.1.29 Change-Id: I4129f447e8872be19cf71a0dfd96aa445e9e5530 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 6ef42ef..8f3c329 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.28 +Version: 0.1.29 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index 681a2d8..3467ca4 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -1,5 +1,5 @@ - + -- 2.7.4 From 474e1a94341e3cddf32569807f940a978d0eed4e Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 2 Apr 2020 19:16:57 +0900 Subject: [PATCH 03/16] Rename internal function name Change-Id: I6ab09f08590dd242c1bee3b48d62ae16f73260e3 Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 3e78566..2541bec 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -165,10 +165,10 @@ static void notify_sync_progress(unsigned int file_progress) send_message("sync_progress", NULL); } -static void _on_send_completed(sap_file_transaction_h file_transaction, - sap_ft_transfer_e result, - const char *file_path, - void *user_data) +static void _on_transfer_completed(sap_file_transaction_h file_transaction, + sap_ft_transfer_e result, + const char *file_path, + void *user_data) { if (priv_data.file_socket) { sap_file_transfer_destroy(file_transaction); @@ -265,9 +265,9 @@ static void _on_send_completed(sap_file_transaction_h file_transaction, sticker_data.reset(); } -static void _on_sending_file_in_progress(sap_file_transaction_h file_transaction, - unsigned short int percentage_progress, - void *user_data) +static void _on_transfer_file_in_progress(sap_file_transaction_h file_transaction, + unsigned short int percentage_progress, + void *user_data) { notify_sync_progress(percentage_progress); } @@ -275,9 +275,9 @@ static void _on_sending_file_in_progress(sap_file_transaction_h file_transaction static void __set_file_transfer_cb(sap_file_transaction_h file_socket) { LOGI("# set callbacks"); - sap_file_transfer_set_progress_cb(file_socket, _on_sending_file_in_progress, NULL); + sap_file_transfer_set_progress_cb(file_socket, _on_transfer_file_in_progress, NULL); - sap_file_transfer_set_done_cb(file_socket, _on_send_completed, NULL); + sap_file_transfer_set_done_cb(file_socket, _on_transfer_completed, NULL); } void accept_file() @@ -441,10 +441,10 @@ void reject_file() file_on_progress = FALSE; } -static void _on_receive_file_cb(sap_peer_agent_h peer_agent_h, - sap_file_transaction_h socket, - const char *file_path, - void *user_data) +static void _on_transfer_file_cb(sap_peer_agent_h peer_agent_h, + sap_file_transaction_h socket, + const char *file_path, + void *user_data) { file_on_progress = TRUE; priv_data.file_socket = socket; @@ -927,7 +927,7 @@ static void on_agent_initialized(sap_agent_h agent, priv_data.agent = agent; - sap_file_transfer_set_incoming_file_cb(agent, _on_receive_file_cb, NULL); + sap_file_transfer_set_incoming_file_cb(agent, _on_transfer_file_cb, NULL); sap_agent_set_service_connection_requested_cb(agent, on_conn_req, NULL); break; -- 2.7.4 From 965796b7cb2aa923a11553cf981ac24c564bdc72 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Mon, 6 Apr 2020 18:27:47 +0900 Subject: [PATCH 04/16] Add the way to notify through event publish Change-Id: Ie2c4ee63ddfa278b65fd775d813814934350795d Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 1 + receiver/CMakeLists.txt | 1 + receiver/src/message.cpp | 38 ++++++++++++++++++++++++++++---------- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 8f3c329..3ad6b90 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -11,6 +11,7 @@ Source3: capi-ui-sticker.conf BuildRequires: cmake, coreutils BuildRequires: pkgconfig(capi-appfw-app-common) BuildRequires: pkgconfig(capi-appfw-package-manager) +BuildRequires: pkgconfig(capi-appfw-event) BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(cynara-session) diff --git a/receiver/CMakeLists.txt b/receiver/CMakeLists.txt index 49b6d42..d415064 100644 --- a/receiver/CMakeLists.txt +++ b/receiver/CMakeLists.txt @@ -18,6 +18,7 @@ pkg_check_modules(pkgs_test REQUIRED capi-message-port capi-appfw-app-common capi-appfw-alarm + capi-appfw-event capi-system-device sap-client-stub-api json-glib-1.0 diff --git a/receiver/src/message.cpp b/receiver/src/message.cpp index 0ca7d32..79b04fd 100644 --- a/receiver/src/message.cpp +++ b/receiver/src/message.cpp @@ -15,11 +15,14 @@ */ #include +#include #include "message.h" #include "log.h" #include "config.h" +#define EVENT_NAME "event.org.tizen.sticker-receiver.user_event" + static int port_id = -1; bool message_sink_init(message_port_message_cb callback, void *user_data) @@ -62,24 +65,39 @@ bool send_message(const char *cmd, const char *data) 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"); - return false; - } - bundle *b = bundle_create(); bundle_add_str(b, "command", cmd); if (data) 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); + + message_port_check_remote_port(REMOTE_APP_ID, MESSAGE_PORT_REMOTE_NAME, &found); + if (found) { + 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("Succeed to send message."); + result = true; + } + } + else + { + LOGW("Can't find remote port"); + result = false; + } + + ret = event_publish_app_event(EVENT_NAME, b); + if (ret != EVENT_ERROR_NONE) { result = false; + LOGE("Failed to send message by event publish. error : %d", ret); } else { - LOGI("Succeed to send message."); + LOGD("Succeed to send message through event publish"); result = true; } -- 2.7.4 From 808dfe7d2d6a87378e7356f683595c27660cc816 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Mon, 6 Apr 2020 20:16:18 +0900 Subject: [PATCH 05/16] Update package version to 0.1.30 Change-Id: Icbdff6b4da025a510e140519c4243ec194954fd8 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 3ad6b90..377419e 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.29 +Version: 0.1.30 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index 3467ca4..0765a66 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -1,5 +1,5 @@ - + -- 2.7.4 From 592e29fcfcd0e9d50b47aeb86f474a6b77f3e239 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Tue, 7 Apr 2020 09:25:45 +0900 Subject: [PATCH 06/16] Remove unused functions Change-Id: I71e4ad9659a4eb8a15b9663969397c2690abec43 Signed-off-by: Jihoon Kim --- receiver/inc/message.h | 2 -- receiver/src/message.cpp | 34 ---------------------------------- 2 files changed, 36 deletions(-) diff --git a/receiver/inc/message.h b/receiver/inc/message.h index 791a9aa..597ee7a 100644 --- a/receiver/inc/message.h +++ b/receiver/inc/message.h @@ -20,8 +20,6 @@ #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/message.cpp b/receiver/src/message.cpp index 79b04fd..e1c4689 100644 --- a/receiver/src/message.cpp +++ b/receiver/src/message.cpp @@ -23,40 +23,6 @@ #define EVENT_NAME "event.org.tizen.sticker-receiver.user_event" -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; -- 2.7.4 From fd25e5acd6236e6845379036742c6ad9521befb5 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 27 Mar 2020 19:38:13 +0900 Subject: [PATCH 07/16] Wake up and send sync request when charging Change-Id: Iedf39ef144311eac828479f2a9d716bf82b7089e Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 3 +- receiver/CMakeLists.txt | 4 +- receiver/inc/config.h | 3 +- receiver/inc/ft.h | 4 + receiver/inc/sync_alarm.h | 27 ------- receiver/src/ft.cpp | 79 ++++++++++++++++--- receiver/src/main.cpp | 171 +++++++++++++++++++++++++++-------------- receiver/src/sync_alarm.cpp | 108 -------------------------- receiver/tizen-manifest.xml | 4 + 9 files changed, 197 insertions(+), 206 deletions(-) delete mode 100644 receiver/inc/sync_alarm.h delete mode 100644 receiver/src/sync_alarm.cpp diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 377419e..7d6cc1d 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -29,11 +29,12 @@ 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-appfw-preference) BuildRequires: pkgconfig(capi-system-device) BuildRequires: pkgconfig(sap-client-stub-api) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(capi-media-thumbnail-util) +BuildRequires: pkgconfig(ecore) BuildRequires: hash-signer Requires(post): signing-client diff --git a/receiver/CMakeLists.txt b/receiver/CMakeLists.txt index d415064..c9f9fc4 100644 --- a/receiver/CMakeLists.txt +++ b/receiver/CMakeLists.txt @@ -7,7 +7,6 @@ SET(SRCS src/ft.cpp src/sticker_info.cpp src/message.cpp - src/sync_alarm.cpp ) INCLUDE(FindPkgConfig) @@ -17,13 +16,14 @@ pkg_check_modules(pkgs_test REQUIRED capi-appfw-service-application capi-message-port capi-appfw-app-common - capi-appfw-alarm capi-appfw-event + capi-appfw-preference capi-system-device sap-client-stub-api json-glib-1.0 vconf capi-media-thumbnail-util + ecore ) INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/receiver/inc) diff --git a/receiver/inc/config.h b/receiver/inc/config.h index 454bd5d..10b742f 100644 --- a/receiver/inc/config.h +++ b/receiver/inc/config.h @@ -20,8 +20,7 @@ #define ACCESSORY_SERVICE_PROFILE_ID "/sample/filetransfersender" #define ACCESSORY_SERVICE_CHANNEL_ID 107 -#define SYNC_ALARM_DELAY 0 -#define SYNC_ALARM_INTERVAL 12*60*60 +#define SYNC_INTERVAL 12*60*60 #define REMOTE_APP_ID "com.samsung.w-input-selector" #define MESSAGE_PORT_REMOTE_NAME REMOTE_APP_ID"_msg_port_rcv" diff --git a/receiver/inc/ft.h b/receiver/inc/ft.h index c20f0af..90d506f 100644 --- a/receiver/inc/ft.h +++ b/receiver/inc/ft.h @@ -29,9 +29,13 @@ void reject_file(void); void accept_file(void); gboolean initialize_sap(void); void deinitialize_sap(void); +gboolean is_init_sap(); +void request_all_sticker_data(const char *mode, const char *type); bool request_sticker_data(const char *mode, const char *category, const char *type); void request_sticker_feature(); void send_disconnect_message(); +bool get_job_progress(); + #endif /* __FT_H__ */ diff --git a/receiver/inc/sync_alarm.h b/receiver/inc/sync_alarm.h deleted file mode 100644 index 8f025ca..0000000 --- a/receiver/inc/sync_alarm.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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" - -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 2541bec..aaef4c3 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -33,6 +33,8 @@ #include #include #include +#include +#include #include "ft.h" #include "log.h" @@ -40,8 +42,8 @@ #include "../inc/sticker_data.h" #include "sticker_request.h" #include "message.h" -#include "sync_alarm.h" #include "config.h" +#include "receiver_preference.h" #define STICKER_SYNC_FEATURE_REQ "sticker-sync-feature-req" #define STICKER_SYNC_FEATURE_RSP "sticker-sync-feature-rsp" @@ -84,20 +86,37 @@ static int t_id = 0; static int rec_file_cnt_in_group = 0; static int total_file_count_in_group = 0; static int sync_success_cnt = 0; +static gboolean job_progress = FALSE; -static void set_first_sync_complete() +static void save_last_sync_time() +{ + // save last sync time in preference + double current_time = ecore_time_get(); + if (preference_set_double(LAST_SYNC_TIME, current_time) == PREFERENCE_ERROR_NONE) { + LOGI("Succeed to set last sync time : %f", current_time); + } + else { + LOGW("Failed to set last sync time"); + } +} + +static void set_sync_complete() { int complete_flags = 0; if (vconf_get_int(VCONFKEY_STICKER_SYNC_COMPLETE, &complete_flags) == 0 && complete_flags == 0) { + // first sync if (vconf_set_int(VCONFKEY_STICKER_SYNC_COMPLETE, VCONFKEY_STICKER_SYNC_COMPLETE_DONE) == 0) LOGD("Succeed to set sync complete"); else LOGW("Fail to set sync complete"); } + + save_last_sync_time(); } static void set_sync_progressing(gboolean flag) { + job_progress = flag; #ifdef VCONFKEY_STICKER_SYNC_STATE LOGD("sync progressing : %d", flag); if (vconf_set_int(VCONFKEY_STICKER_SYNC_STATE, flag ? VCONFKEY_STICKER_SYNC_STATE_IN_PROGRESS : VCONFKEY_STICKER_SYNC_STATE_WAITING) == 0) @@ -280,6 +299,11 @@ static void __set_file_transfer_cb(sap_file_transaction_h file_socket) sap_file_transfer_set_done_cb(file_socket, _on_transfer_completed, NULL); } +bool get_job_progress() +{ + return job_progress; +} + void accept_file() { int ret; @@ -338,6 +362,7 @@ bool request_sticker_data(const char *mode, const char *category, const char *ty JsonObject *j_object = NULL; if (!priv_data.socket) { + job_progress = TRUE; StickerRequest pending_request; pending_request.req_type = REQUEST_TYPE_SYNC; pending_request.mode = string(mode ? mode : "manual"); @@ -383,11 +408,32 @@ bool request_sticker_data(const char *mode, const char *category, const char *ty return result; } +void request_all_sticker_data(const char *mode, const char *type) +{ +#ifdef VCONFKEY_STICKER_SUPPORTED_FEATURE + int feature_flag = 0; + if (vconf_get_int(VCONFKEY_STICKER_SUPPORTED_FEATURE, &feature_flag) == 0) + { + if (feature_flag & VCONFKEY_STICKER_FEATURE_AREMOJI) + request_sticker_data(mode, "arsticker", type); + + if (feature_flag & VCONFKEY_STICKER_FEATURE_BITMOJI) + request_sticker_data(mode, "bitmoji", type); + } + else + LOGW("Failed to get value of VCONFKEY_STICKER_SUPPORTED_FEATURE"); +#else + request_sticker_data(mode, "arsticker", type); + request_sticker_data(mode, "bitmoji", type); +#endif +} + void request_sticker_feature() { JsonObject *j_object = NULL; if (!priv_data.socket) { + job_progress = TRUE; StickerRequest pending_request; pending_request.req_type = REQUEST_TYPE_FEATURE_REQ; ReqQueue.push(pending_request); @@ -407,6 +453,9 @@ void request_sticker_feature() if (_send_json_data(j_object) == FALSE) { LOGE("Failed to send STICKER_SYNC_FEATURE_REQ"); } + else { + job_progress = TRUE; + } json_object_unref(j_object); @@ -576,6 +625,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in #endif if (!process_request_queue()) { + job_progress = FALSE; send_disconnect_message(); service_app_exit(); } @@ -604,6 +654,10 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in if (result_code != SYNC_START_RSP_SUCCESS) { set_sync_progressing(FALSE); if (!process_request_queue()) { + if (result_code == SYNC_START_RSP_NO_STICKER) + save_last_sync_time(); + + job_progress = FALSE; send_disconnect_message(); service_app_exit(); } @@ -689,7 +743,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in { if (current_request.category == string("arsticker")) { - set_first_sync_complete(); + set_sync_complete(); set_sync_progressing(FALSE); } } @@ -697,7 +751,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in { if (current_request.category == string("bitmoji")) { - set_first_sync_complete(); + set_sync_complete(); set_sync_progressing(FALSE); } } @@ -721,13 +775,9 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in send_message("sync_stop_result", reason.c_str()); if (!process_request_queue()) { - if (sync_success_cnt > 0 && current_request.mode == string("manual")) { - if (!sync_alarm_exist()) - sync_alarm_register(APP_CONTROL_OPERATION_SYNC_ALARM, SYNC_ALARM_DELAY, SYNC_ALARM_INTERVAL); - } - sync_success_cnt = 0; + job_progress = FALSE; send_disconnect_message(); service_app_exit(); } @@ -1012,6 +1062,11 @@ gboolean initialize_sap(void) { sap_agent_h agent = NULL; + if (priv_data.agent) { + LOGW("duplicate initialize"); + return FALSE; + } + sap_agent_create(&agent); priv_data.agent = agent; @@ -1025,6 +1080,7 @@ gboolean initialize_sap(void) void deinitialize_sap(void) { + LOGD("deinitialize"); if (priv_data.agent) { int ret = sap_agent_deinitialize(priv_data.agent, on_agent_deinitialized, NULL); switch (ret) { @@ -1046,3 +1102,8 @@ void deinitialize_sap(void) priv_data.agent = NULL; } } + +gboolean is_init_sap() +{ + return priv_data.agent ? TRUE : FALSE; +} \ No newline at end of file diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index aa65584..2006985 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -17,15 +17,20 @@ #include #include #include -#include +#include #include #include +#include +#include +#include #include "main.h" #include "ft.h" #include "log.h" #include "config.h" -#include "sync_alarm.h" +#include "receiver_preference.h" + +using namespace std; static bool app_create(void *data) { @@ -34,11 +39,66 @@ static bool app_create(void *data) If this function returns true, the main loop of application starts If this function returns false, the application is terminated */ - initialize_sap(); + LOGD(""); return true; } +static bool check_battery_condition() +{ + int battery_percentage = 0; + int ret; + + // check battery percentage + ret = device_battery_get_percent(&battery_percentage); + if (ret != DEVICE_ERROR_NONE) + { + LOGW("No sync. Failed to get battery percent. error : %d", ret); + return false; + } + + LOGI("battery percent : %d", battery_percentage); + if (battery_percentage >= MINIMUM_BATTERY) + return true; + else + { + LOGI("No sync due to insufficient battery"); + return false; + } +} + +static bool check_sync_time_condition() +{ + double last_sync_time; + int feature_flag = 0; + bool result = false; + +#ifdef VCONFKEY_STICKER_SUPPORTED_FEATURE + // Check whether oobe has been done + if (vconf_get_int(VCONFKEY_STICKER_SUPPORTED_FEATURE, &feature_flag) == 0 && feature_flag > 0) + { + if (preference_get_double(LAST_SYNC_TIME, &last_sync_time) != PREFERENCE_ERROR_NONE) + { + LOGD("Can't get last sync time."); + return true; + } + + // compare time + LOGD("current time : %f, last_sync_time : %f", ecore_time_get(), last_sync_time); + if (ecore_time_get() - last_sync_time > SYNC_INTERVAL) + result = true; + else + result = false; + } + else + { + result = false; + } +#endif /* VCONFKEY_STICKER_SUPPORTED_FEATURE */ + + return result; +} + static void app_control(app_control_h app_control, void *data) { /* Handle the launch request. */ @@ -46,53 +106,56 @@ static void app_control(app_control_h app_control, void *data) char* mode = NULL; char* type = NULL; char* operation = NULL; - char* alarm_data = NULL; - + char* event_value = NULL; + char* uri = NULL; + const char *event_uri = "event://tizen.system.event.battery_charger_status"; int res; - int battery_percentage = 0; - bool battery_charging = false; // 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 ret = device_battery_is_charging(&battery_charging); - if (ret != DEVICE_ERROR_NONE) { - LOGW("No sync. Can't get battery charging status"); - goto cleanup; - } - - if (!battery_charging) { - LOGI("No sync due to no battery charging status"); - goto cleanup; - } - - ret = device_battery_get_percent(&battery_percentage); - if (ret != DEVICE_ERROR_NONE) { - LOGW("No sync. Failed to get battery percent. error : %d", ret); - goto cleanup; - } + if (!operation) { + goto cleanup; + } - LOGI("battery percent : %d", battery_percentage); - if (battery_percentage >= MINIMUM_BATTERY) { - request_sticker_data("auto", "arsticker", "input"); - request_sticker_data("auto", "bitmoji", "input"); - } - else { - LOGI("No sync due to insufficient battery"); + if (strcmp(operation, APP_CONTROL_OPERATION_LAUNCH_ON_EVENT) == 0) + { + ret = app_control_get_uri(app_control, &uri); + if (ret == APP_CONTROL_ERROR_NONE && uri) + { + if (strncmp(uri, event_uri, strlen(event_uri) + 1) == 0) + { + ret = app_control_get_extra_data(app_control, "battery_charger_status", &event_value); + if (ret == APP_CONTROL_ERROR_NONE && event_value) + { + if (string(event_value) == "connected") + { + if (!is_init_sap()) { + if (check_sync_time_condition()) { + if (check_battery_condition()) { + initialize_sap(); + request_all_sticker_data("auto", "input"); + } + } + else { + if (!get_job_progress()) + { + LOGD("exit"); + service_app_exit(); + } + } + } + else { + LOGD("continue doing current job"); + } + } + free(event_value); + } + } + free(uri); } - - goto cleanup; } } else { @@ -119,30 +182,23 @@ static void app_control(app_control_h app_control, void *data) goto cleanup; if (mode && type) { -#ifdef VCONFKEY_STICKER_SUPPORTED_FEATURE - int feature_flag = 0; - if (vconf_get_int(VCONFKEY_STICKER_SUPPORTED_FEATURE, &feature_flag) == 0) { - if (feature_flag & VCONFKEY_STICKER_FEATURE_AREMOJI) - request_sticker_data(mode, "arsticker", type); - - if (feature_flag & VCONFKEY_STICKER_FEATURE_BITMOJI) - request_sticker_data(mode, "bitmoji", type); - } else - LOGW("Failed to get value of VCONFKEY_STICKER_SUPPORTED_FEATURE"); -#else - request_sticker_data(mode, "arsticker", type); - request_sticker_data(mode, "bitmoji", type); -#endif + if (!is_init_sap()) { + initialize_sap(); + request_all_sticker_data(mode, 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); + initialize_sap(); request_sticker_feature(); } else { LOGW("Unknown command : %s", request); + if (!is_init_sap()) + { + service_app_exit(); + } } } @@ -163,6 +219,7 @@ cleanup: static void app_terminate(void *data) { /* Release all resources. */ + LOGD(""); deinitialize_sap(); } diff --git a/receiver/src/sync_alarm.cpp b/receiver/src/sync_alarm.cpp deleted file mode 100644 index ec7079e..0000000 --- a/receiver/src/sync_alarm.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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" -#include "config.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 0765a66..402974f 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -8,6 +8,10 @@ + + + + http://developer.samsung.com/tizen/privilege/accessoryprotocol -- 2.7.4 From 1ab0ed3dae806ec5c08c731d6e7ec99c17d500c7 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Wed, 8 Apr 2020 18:01:06 +0900 Subject: [PATCH 08/16] Add missing header file Change-Id: Idce8ed00100a1da70dbfee22416a22fab5c7cb8f Signed-off-by: Jihoon Kim --- receiver/inc/receiver_preference.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 receiver/inc/receiver_preference.h diff --git a/receiver/inc/receiver_preference.h b/receiver/inc/receiver_preference.h new file mode 100644 index 0000000..140b171 --- /dev/null +++ b/receiver/inc/receiver_preference.h @@ -0,0 +1,22 @@ +/* + * 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. + */ + +#ifndef __RECEIVER_PREFERENCE_H__ +#define __RECEIVER_PREFERENCE_H__ + +#define LAST_SYNC_TIME "LastSyncTime" + +#endif /* __RECEIVER_PREFERENCE_H__ */ -- 2.7.4 From dac20334a76302b59f544e8d683a5135853f4f12 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Wed, 8 Apr 2020 17:56:00 +0900 Subject: [PATCH 09/16] Fix the issue that sticker synchronization is failed when REQUEST_SYNC message is received Change-Id: I059241ca2f9ef5262c02f7b8b14fb6b32c0ae964 --- receiver/src/ft.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index aaef4c3..ef2b771 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -415,10 +415,12 @@ void request_all_sticker_data(const char *mode, const char *type) if (vconf_get_int(VCONFKEY_STICKER_SUPPORTED_FEATURE, &feature_flag) == 0) { if (feature_flag & VCONFKEY_STICKER_FEATURE_AREMOJI) - request_sticker_data(mode, "arsticker", type); + if (!request_sticker_data(mode, "arsticker", type)) + LOGW("Failed to request ar_sticker sync"); if (feature_flag & VCONFKEY_STICKER_FEATURE_BITMOJI) - request_sticker_data(mode, "bitmoji", type); + if (!request_sticker_data(mode, "bitmoji", type)) + LOGW("Failed to request bitmoji sync"); } else LOGW("Failed to get value of VCONFKEY_STICKER_SUPPORTED_FEATURE"); @@ -599,8 +601,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in json_msgid = json_object_get_string_member(root_obj, "msgId"); msg_id = string(json_msgid ? json_msgid : ""); if (msg_id == STICKER_REQUEST_SYNC_REQ) { - if (!request_sticker_data(current_request.mode.c_str(), current_request.category.c_str(), current_request.type.c_str())) - LOGW("Failed to request sticker sync"); + request_all_sticker_data("auto", "input"); } else if (msg_id == STICKER_SYNC_FEATURE_RSP) { LOGD("msg : %s", msg_id.c_str()); #ifdef VCONFKEY_STICKER_SUPPORTED_FEATURE -- 2.7.4 From 3c5c87061e6c614f1e3eadd07af87cab341c8761 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Wed, 8 Apr 2020 21:56:58 +0900 Subject: [PATCH 10/16] Modified to set VCONFKEY_STICKER_SYNC_STATE when bitmoji sync is finished Change-Id: Ia2c2e65bc0e78fdd7d819f329eb1ff345cf40300 --- receiver/src/ft.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index ef2b771..9288b72 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -775,6 +775,10 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in send_message("sync_stop_result", reason.c_str()); + current_request.mode.clear(); + current_request.category.clear(); + current_request.type.clear(); + if (!process_request_queue()) { sync_success_cnt = 0; @@ -782,10 +786,6 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in send_disconnect_message(); service_app_exit(); } - - current_request.mode.clear(); - current_request.category.clear(); - current_request.type.clear(); } else LOGW("unknown msg id : %s", msg_id.c_str()); -- 2.7.4 From 9a8bfc673c34838f14393f1f003411fa850b3ed9 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Wed, 8 Apr 2020 21:58:46 +0900 Subject: [PATCH 11/16] Update package version to 0.1.31 Change-Id: Idcd893834e1eaf5fc2c0024033b2096092b23ab2 --- 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 7d6cc1d..faae811 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.30 +Version: 0.1.31 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index 402974f..cf0b55e 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -1,5 +1,5 @@ - + -- 2.7.4 From a7ac397bc9415d1fcb91e445fc2a0eabe702075f Mon Sep 17 00:00:00 2001 From: InHong Han Date: Tue, 7 Apr 2020 18:21:24 +0900 Subject: [PATCH 12/16] Add a new table into DB for checking recent history Change-Id: I78725d047ab6b5e1c24a4c49b63ab69bde6d17d7 --- server/stickerd_db_manager.c | 21 +++++++++++++++++++++ sticker-parser/sticker-parser.c | 13 +++++++++++++ 2 files changed, 34 insertions(+) diff --git a/server/stickerd_db_manager.c b/server/stickerd_db_manager.c index 3adda1b..7e6c8e1 100644 --- a/server/stickerd_db_manager.c +++ b/server/stickerd_db_manager.c @@ -51,12 +51,20 @@ * | whitelist_id | provider_id | consumer_id | * +------------+---------------+-------------+ * + * sticker_recent_history_info + * +------------+-----------------+-------+-----------+ + * | INT | INT | INT | TEXT | + * +------------+-----------------+-------+-----------+ + * | history_id | sticker_info_id | count | timestamp | + * +------------+-----------------+-------+-----------+ + * */ #define STICKER_DB_PATH tzplatform_mkpath(TZ_SYS_DB, ".sticker_info.db") #define STICKER_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_info(sticker_info_id INTEGER PRIMARY KEY AUTOINCREMENT, app_id TEXT NOT NULL, type INTEGER NOT NULL, uri TEXT NOT NULL, thumbnail TEXT, description TEXT, group_name TEXT NOT NULL, date TEXT NOT NULL, display_type INTEGER)" #define STICKER_KEYWORD_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_keyword_info(keyword_id INTEGER PRIMARY KEY AUTOINCREMENT, sticker_info_id INTEGER, keyword TEXT NOT NULL, FOREIGN KEY (sticker_info_id) REFERENCES sticker_info(sticker_info_id) ON DELETE CASCADE)" #define STICKER_WHITELIST_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_whitelist_info(whitelist_id INTEGER PRIMARY KEY AUTOINCREMENT, provider_id TEXT NOT NULL, consumer_id TEXT NOT NULL)" +#define STICKER_RECENT_HISTORY_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_recent_history_info(history_id INTEGER PRIMARY KEY AUTOINCREMENT, sticker_info_id INTEGER, count INTEGER NOT NULL, timestamp TEXT NOT NULL, FOREIGN KEY (sticker_info_id) REFERENCES sticker_info(sticker_info_id) ON DELETE CASCADE)" #define STICKER_DB_INSERT_STICKER_INFO "INSERT INTO sticker_info (app_id, type, uri, thumbnail, description, group_name, date, display_type) VALUES (?, ?, ?, ?, ?, ?, DateTime('now','localtime'), ?)" #define STICKER_DB_INSERT_STICKER_KEYWORD_INFO "INSERT INTO sticker_keyword_info (sticker_info_id, keyword) VALUES (?, ?)" @@ -197,6 +205,12 @@ static int _recover_db(void) ret = STICKERD_SERVER_ERROR_DB_FAILED; } + ret = sqlite3_exec(db, STICKER_RECENT_HISTORY_INFO_CREATE_TABLE, NULL, NULL, &err); + if (ret != SQLITE_OK) { + LOGE("Failed to create sticker_recent_history_info table : %s", err); + ret = STICKERD_SERVER_ERROR_DB_FAILED; + } + is_corrupted = FALSE; cleanup: @@ -255,6 +269,13 @@ int stickerd_db_init(void) goto cleanup; } + ret = sqlite3_exec(db, STICKER_RECENT_HISTORY_INFO_CREATE_TABLE, NULL, NULL, &err); + if (ret != SQLITE_OK) { + LOGE("Failed to create sticker_recent_history_info table : %s", err); + ret = STICKERD_SERVER_ERROR_DB_FAILED; + goto cleanup; + } + ret = sqlite3_exec(db, "PRAGMA journal_mode = WAL", NULL, NULL, &err); if (ret != SQLITE_OK) { LOGE("Failed to set journal_mode : %s", err); diff --git a/sticker-parser/sticker-parser.c b/sticker-parser/sticker-parser.c index 86ebd3e..a3f96b5 100644 --- a/sticker-parser/sticker-parser.c +++ b/sticker-parser/sticker-parser.c @@ -44,6 +44,7 @@ #define STICKER_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_info(sticker_info_id INTEGER PRIMARY KEY AUTOINCREMENT, app_id TEXT NOT NULL, type INTEGER NOT NULL, uri TEXT NOT NULL, thumbnail TEXT, description TEXT, group_name TEXT NOT NULL, date TEXT NOT NULL, display_type INTEGER)" #define STICKER_KEYWORD_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_keyword_info(keyword_id INTEGER PRIMARY KEY AUTOINCREMENT, sticker_info_id INTEGER, keyword TEXT NOT NULL, FOREIGN KEY (sticker_info_id) REFERENCES sticker_info(sticker_info_id) ON DELETE CASCADE)" #define STICKER_WHITELIST_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_whitelist_info(whitelist_id INTEGER PRIMARY KEY AUTOINCREMENT, provider_id TEXT NOT NULL, consumer_id TEXT NOT NULL)" +#define STICKER_RECENT_HISTORY_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_recent_history_info(history_id INTEGER PRIMARY KEY AUTOINCREMENT, sticker_info_id INTEGER, count INTEGER NOT NULL, timestamp TEXT NOT NULL, FOREIGN KEY (sticker_info_id) REFERENCES sticker_info(sticker_info_id) ON DELETE CASCADE)" #define UIFW_ID 502 #define APPFW_ID 301 #define MAX_ERROR_BUFFER 256 @@ -130,6 +131,12 @@ static void __recover_db() goto cleanup; } + ret = sqlite3_exec(db, STICKER_RECENT_HISTORY_INFO_CREATE_TABLE, NULL, NULL, &err); + if (ret != SQLITE_OK) { + LOGE("Failed to create sticker_recent_history_info table : %s", err); + goto cleanup; + } + is_corrupted = FALSE; cleanup: @@ -186,6 +193,12 @@ static void __db_init() goto cleanup; } + ret = sqlite3_exec(db, STICKER_RECENT_HISTORY_INFO_CREATE_TABLE, NULL, NULL, &err); + if (ret != SQLITE_OK) { + LOGE("Failed to create sticker_recent_history_info table : %s", err); + goto cleanup; + } + ret = sqlite3_exec(db, "PRAGMA journal_mode = WAL", NULL, NULL, &err); if (ret != SQLITE_OK) { LOGE("Failed to set journal_mode : %s", err); -- 2.7.4 From 152404a751b572f8d2777ad72ba8cca201e62aff Mon Sep 17 00:00:00 2001 From: InHong Han Date: Tue, 7 Apr 2020 18:36:03 +0900 Subject: [PATCH 13/16] Add APIs for managing recent stickers history Change-Id: I9f1ae1c9bf066822e497bc5a4c03eaefb12f58d4 --- client/sticker_dbus.c | 36 ++++++++++++++++++++++ client/sticker_dbus.h | 2 ++ consumer/sticker_consumer.c | 66 +++++++++++++++++++++++++++++++++++++++ include/sticker_consumer.h | 37 ++++++++++++++++++++++ server/stickerd_data_manager.c | 70 ++++++++++++++++++++++++++++++++++++++++++ server/stickerd_data_manager.h | 2 ++ server/stickerd_db_manager.c | 70 ++++++++++++++++++++++++++++++++++++++++++ server/stickerd_db_manager.h | 2 ++ 8 files changed, 285 insertions(+) diff --git a/client/sticker_dbus.c b/client/sticker_dbus.c index 5460c71..c6aaaea 100644 --- a/client/sticker_dbus.c +++ b/client/sticker_dbus.c @@ -1108,4 +1108,40 @@ int sticker_dbus_check_file_exists(GDBusConnection *gdbus_connection, const char g_object_unref(reply); return ret; +} + +int sticker_dbus_insert_recent_sticker_info(GDBusConnection *gdbus_connection, int record_id) +{ + int ret; + GDBusMessage *reply = NULL; + + ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "insert_recent_sticker_info"); + if (ret != STICKER_CLIENT_ERROR_NONE) + LOGE("failed to insert recent sticker info"); + + if (reply) + g_object_unref(reply); + + return ret; +} + +int sticker_dbus_get_recent_sticker_list(GDBusConnection *gdbus_connection, int count, GVariantIter **id_iter) +{ + int ret; + GDBusMessage *reply = NULL; + GVariant *reply_body = NULL; + + ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", count), &reply, "get_recent_sticker_info"); + if (ret == STICKER_CLIENT_ERROR_NONE) { + reply_body = g_dbus_message_get_body(reply); + g_variant_get(reply_body, "(a(i))", &(*id_iter)); + } + + if (reply_body) + g_variant_unref(reply_body); + + if (reply) + g_object_unref(reply); + + return ret; } \ No newline at end of file diff --git a/client/sticker_dbus.h b/client/sticker_dbus.h index 610cfe1..a6d5437 100644 --- a/client/sticker_dbus.h +++ b/client/sticker_dbus.h @@ -65,6 +65,8 @@ int sticker_dbus_get_sticker_info_by_keyword(GDBusConnection *gdbus_connection, int sticker_dbus_get_sticker_info_by_display_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_display_type_e type, int offset, int count, GVariantIter **id_iter); int sticker_dbus_get_group_list_by_display_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_display_type_e type, GList **group_list); int sticker_dbus_check_file_exists(GDBusConnection *gdbus_connection, const char *uri, int *result); +int sticker_dbus_insert_recent_sticker_info(GDBusConnection *gdbus_connection, int record_id); +int sticker_dbus_get_recent_sticker_list(GDBusConnection *gdbus_connection, int count, GVariantIter **id_iter); #ifdef __cplusplus } diff --git a/consumer/sticker_consumer.c b/consumer/sticker_consumer.c index 5211f36..15ea7fc 100644 --- a/consumer/sticker_consumer.c +++ b/consumer/sticker_consumer.c @@ -531,4 +531,70 @@ cleanup: g_list_free_full(list, free); return ret; +} + +EXPORT_API int sticker_consumer_add_recent_data(sticker_consumer_h consumer_handle, sticker_data_h data_handle) +{ + CHECK_STICKER_FEATURE(); + + int ret; + + if (!consumer_handle || !data_handle || (data_handle->sticker_info_id > 0) || !data_handle->uri) + return STICKER_ERROR_INVALID_PARAMETER; + + ret = sticker_dbus_insert_recent_sticker_info(consumer_handle->gdbus_connection, data_handle->sticker_info_id); + if (ret != STICKER_ERROR_NONE) { + LOGE("Failed to add recent sticker information : %d", ret); + return STICKER_ERROR_OPERATION_FAILED; + } + + return STICKER_ERROR_NONE; +} + +EXPORT_API int sticker_consumer_get_recent_data_list(sticker_consumer_h consumer_handle, int count, int *result, sticker_consumer_data_foreach_cb callback, void *user_data) +{ + CHECK_STICKER_FEATURE(); + + int ret; + int info_id; + int sticker_count = 0; + GVariantIter *id_iter = NULL; + + if (!consumer_handle || (count <= 0) || !result || !callback) + return STICKER_ERROR_INVALID_PARAMETER; + + ret = sticker_dbus_get_recent_sticker_list(consumer_handle->gdbus_connection, count, &id_iter); + if (ret != STICKER_ERROR_NONE) { + LOGE("Failed to get recent sticker information : %d", ret); + ret = STICKER_ERROR_OPERATION_FAILED; + goto cleanup; + } + + if (id_iter) { + while (g_variant_iter_loop (id_iter, "(i)", &info_id)) { + sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s)); + if (!sticker_data) { + ret = STICKER_ERROR_OUT_OF_MEMORY; + goto cleanup; + } + + ret = sticker_dbus_get_sticker_info_by_record_id(consumer_handle->gdbus_connection, sticker_data, info_id); + if (ret == STICKER_ERROR_NONE) { + sticker_count++; + callback(sticker_data, user_data); + _free_sticker_data(sticker_data); + } else { + _free_sticker_data(sticker_data); + goto cleanup; + } + } + } + + *result = sticker_count; + +cleanup: + if (id_iter) + g_variant_iter_free(id_iter); + + return ret; } \ No newline at end of file diff --git a/include/sticker_consumer.h b/include/sticker_consumer.h index ac2428e..a143e00 100644 --- a/include/sticker_consumer.h +++ b/include/sticker_consumer.h @@ -279,6 +279,43 @@ int sticker_consumer_data_foreach_by_display_type(sticker_consumer_h consumer_ha int sticker_consumer_group_list_foreach_by_display_type(sticker_consumer_h consumer_handle, sticker_data_display_type_e type, sticker_consumer_group_list_foreach_cb callback, void *user_data); /** + * @brief Add history to recently used stickers list + * @since_tizen 5.5 + * @param[in] consumer_handle The sticker consumer handle + * @param[in] data_handle The sticker data handle + * @return 0 on success, otherwise a negative error value + * @retval #STICKER_ERROR_NONE Successful + * @retval #STICKER_ERROR_NOT_SUPPORTED Not supported + * @retval #STICKER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STICKER_ERROR_OPERATION_FAILED Operation failed + * @see sticker_consumer_get_recent_list() + */ +int sticker_consumer_add_recent_data(sticker_consumer_h consumer_handle, sticker_data_h data_handle); + +/** + * @brief Gets recently used stickers list. + * @details The most recently used stickers are delivered in order. + * @since_tizen 5.5 + * @remarks It is not an error if @a result is smaller than @a count. + * @param[in] consumer_handle The sticker consumer handle + * @param[in] count The number of stickers that you want to receive. + * If -1, the number of stickers is not restricted + * @param[out] result The number of stickers received (zero indicates that no data was found) + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value + * @retval #STICKER_ERROR_NONE Successful + * @retval #STICKER_ERROR_NOT_SUPPORTED Not supported + * @retval #STICKER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STICKER_ERROR_OUT_OF_MEMORY Out of memory + * @retval #STICKER_ERROR_OPERATION_FAILED Operation failed + * @post This function invokes sticker_consumer_data_foreach_cb() repeatedly for getting data. + * @see sticker_consumer_data_foreach_cb() + * @see sticker_consumer_add_recent_data() + */ +int sticker_consumer_get_recent_data_list(sticker_consumer_h consumer_handle, int count, int *result, sticker_consumer_data_foreach_cb callback, void *user_data); + +/** * @} */ diff --git a/server/stickerd_data_manager.c b/server/stickerd_data_manager.c index 3585b8d..251e9c0 100644 --- a/server/stickerd_data_manager.c +++ b/server/stickerd_data_manager.c @@ -149,6 +149,10 @@ static void _stickerd_client_dbus_method_call_handler(GDBusConnection *conn, con ret = stickerd_update_sticker_disp_type(parameters, &reply_body); } else if (g_strcmp0(method_name, "check_file_exists") == 0) { ret = stickerd_check_file_exists(parameters, &reply_body); + } else if (g_strcmp0(method_name, "insert_recent_sticker_info") == 0) { + ret = stickerd_insert_recent_sticker_info(parameters, &reply_body); + } else if (g_strcmp0(method_name, "get_recent_sticker_info") == 0) { + ret = stickerd_get_recent_sticker_info(parameters, &reply_body); } if (ret == STICKERD_SERVER_ERROR_NONE) { @@ -315,6 +319,15 @@ int stickerd_register_dbus_interface(void) " " " " " " + + " " + " " + " " + + " " + " " + " " + " " " " " "; @@ -1558,4 +1571,61 @@ int stickerd_check_file_exists(GVariant *parameters, GVariant **reply_body) } return ret; +} + +int stickerd_insert_recent_sticker_info(GVariant *parameters, GVariant **reply_body) +{ + int ret; + int record_id; + + *reply_body = g_variant_new("()"); + if (*reply_body == NULL) { + LOGE("Failed to create reply_body"); + return STICKERD_SERVER_ERROR_OPERATION_FAILED; + } + + g_variant_get(parameters, "(i)", &record_id); + + ret = stickerd_db_insert_recent_sticker_info(record_id); + if (ret != STICKERD_SERVER_ERROR_NONE) { + LOGE("Failed to insert recent sticker info"); + return STICKERD_SERVER_ERROR_OPERATION_FAILED; + } + + return ret; +} + +int stickerd_get_recent_sticker_info(GVariant *parameters, GVariant **reply_body) +{ + int ret; + int count; + GList *id_list = NULL; + GVariantBuilder *id_builder = NULL; + + g_variant_get(parameters, "(i)", &count); + + ret = stickerd_db_get_record_id(STICKER_DB_STICKER_RECENT_HISTORY, &id_list, NULL, NULL, 0, count); + if (ret != STICKERD_SERVER_ERROR_NONE) { + LOGE("Failed to get recent sticker id"); + if(id_list) + g_list_free_full(id_list, free); + return STICKERD_SERVER_ERROR_OPERATION_FAILED; + } + + id_builder = g_variant_builder_new(G_VARIANT_TYPE("a(i)")); + g_list_foreach(id_list, (GFunc) _set_id_builder, id_builder); + + *reply_body = g_variant_new("(a(i))", id_builder); + if (*reply_body == NULL) { + LOGE("Failed to create reply_body"); + ret = STICKERD_SERVER_ERROR_OPERATION_FAILED; + } + + if (id_list) + g_list_free_full(id_list, free); + + if (id_builder) + g_variant_builder_unref(id_builder); + + return ret; } \ No newline at end of file diff --git a/server/stickerd_data_manager.h b/server/stickerd_data_manager.h index e09e91d..ea90752 100644 --- a/server/stickerd_data_manager.h +++ b/server/stickerd_data_manager.h @@ -48,6 +48,8 @@ int stickerd_get_sticker_info_by_display_type(GVariant *parameters, GVariant **r int stickerd_get_group_list_by_disp_type(GVariant *parameters, GVariant **reply_body); int stickerd_update_sticker_disp_type(GVariant *parameters, GVariant **reply_body); int stickerd_check_file_exists(GVariant *parameters, GVariant **reply_body); +int stickerd_insert_recent_sticker_info(GVariant *parameters, GVariant **reply_body); +int stickerd_get_recent_sticker_info(GVariant *parameters, GVariant **reply_body); #ifdef __cplusplus } diff --git a/server/stickerd_db_manager.c b/server/stickerd_db_manager.c index 3adda1b..79d4c61 100644 --- a/server/stickerd_db_manager.c +++ b/server/stickerd_db_manager.c @@ -60,6 +60,7 @@ #define STICKER_DB_INSERT_STICKER_INFO "INSERT INTO sticker_info (app_id, type, uri, thumbnail, description, group_name, date, display_type) VALUES (?, ?, ?, ?, ?, ?, DateTime('now','localtime'), ?)" #define STICKER_DB_INSERT_STICKER_KEYWORD_INFO "INSERT INTO sticker_keyword_info (sticker_info_id, keyword) VALUES (?, ?)" +#define STICKER_DB_INSERT_RECENT_HISTORY "INSERT INTO sticker_recent_history_info (sticker_info_id, count, timestamp) VALUES (?, 1, DateTime('now','localtime'))" #define STICKER_DB_DELETE_STICKER_INFO "DELETE FROM sticker_info WHERE sticker_info_id = ?" #define STICKER_DB_DELETE_STICKER_KEYWORD_INFO "DELETE FROM sticker_keyword_info WHERE sticker_info_id = ?" @@ -71,6 +72,7 @@ #define STICKER_DB_UPDATE_STICKER_DESCRIPTION "UPDATE sticker_info SET description = ?, date = DateTime('now','localtime') WHERE sticker_info_id = ?" #define STICKER_DB_UPDATE_STICKER_GROUP "UPDATE sticker_info SET group_name = ?, date = DateTime('now','localtime') WHERE sticker_info_id = ?" #define STICKER_DB_UPDATE_STICKER_DISP_TYPE "UPDATE sticker_info SET display_type = ?, date = DateTime('now','localtime') WHERE sticker_info_id = ?" +#define STICKER_DB_UPDATE_RECENT_HISTORY "UPDATE sticker_recent_history_info SET count = count + 1, timestamp = DateTime('now','localtime') WHERE sticker_info_id = ?" #define STICKER_DB_GET_LATEST_RECORD_ID "SELECT sticker_info_id FROM sticker_info ORDER BY sticker_info_id DESC LIMIT 1" #define STICKER_DB_GET_STICKER_INFO_BY_RECORD_ID "SELECT * FROM sticker_info WHERE sticker_info_id = ?" @@ -88,6 +90,8 @@ #define STICKER_DB_GET_RECORD_ID_BY_DISP_TYPE "SELECT sticker_info_id FROM sticker_info WHERE display_type = ? AND app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?)) LIMIT ?, ?" #define STICKER_DB_GET_GROUP_LIST_BY_DISP_TYPE "SELECT DISTINCT group_name FROM sticker_info WHERE display_type = ? AND app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?))" #define STICKER_DB_CHECK_FILE_EXISTS "SELECT EXISTS(SELECT 1 FROM sticker_info WHERE uri = ? LIMIT 1)" +#define STICKER_DB_CHECK_RECENT_HISTORY_EXISTS "SELECT EXISTS(SELECT 1 FROM sticker_recent_history_info WHERE sticker_info_id = ? LIMIT 1)" +#define STICKER_DB_GET_RECENT_HISTORY "SELECT sticker_info_id FROM sticker_recent_history_info ORDER BY datetime(timestamp) DESC LIMIT ?" typedef enum { @@ -147,6 +151,8 @@ static const char *_db_get_query(sticker_info_db_type sticker_type, command_type break; case STICKER_DB_STICKER_DISP_TYPE: query = STICKER_DB_GET_RECORD_ID_BY_DISP_TYPE; + case STICKER_DB_STICKER_RECENT_HISTORY: + query = STICKER_DB_GET_RECENT_HISTORY; break; default : query = ""; @@ -811,6 +817,8 @@ int stickerd_db_get_record_id(sticker_info_db_type type, GList **id_list, void * sqlite3_bind_text(stmt, 1, app_id, -1, SQLITE_TRANSIENT); sqlite3_bind_int(stmt, 2, offset); sqlite3_bind_int(stmt, 3, count); + } else if (type == STICKER_DB_STICKER_RECENT_HISTORY) { + sqlite3_bind_int(stmt, 1, count); } else { if (type == STICKER_DB_STICKER_TYPE || type == STICKER_DB_STICKER_DISP_TYPE) sqlite3_bind_int(stmt, 1, *(int *)data); @@ -913,4 +921,66 @@ cleanup: sqlite3_close(db); return STICKERD_SERVER_ERROR_DB_FAILED; +} + +int stickerd_db_insert_recent_sticker_info(int record_id) +{ + int ret; + sqlite3 *db = NULL; + sqlite3_stmt *stmt = NULL; + + db = _db_open(); + if (!db) + return STICKERD_SERVER_ERROR_DB_FAILED; + + ret = sqlite3_prepare_v2(db, STICKER_DB_CHECK_RECENT_HISTORY_EXISTS, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + LOGE("fail to check recent sticker exists : %s", sqlite3_errmsg(db)); + goto cleanup; + } + + sqlite3_bind_int(stmt, 1, record_id); + + ret = sqlite3_step(stmt); + if (ret == SQLITE_ERROR) { + LOGE("sqlite3_step() failed : ret(%d)", ret); + goto cleanup; + } + + int result = sqlite3_column_int(stmt, 0); + + sqlite3_finalize(stmt); + stmt = NULL; + + if (result) + ret = sqlite3_prepare_v2(db, STICKER_DB_UPDATE_RECENT_HISTORY, -1, &stmt, NULL); + else + ret = sqlite3_prepare_v2(db, STICKER_DB_INSERT_RECENT_HISTORY, -1, &stmt, NULL); + + if (ret != SQLITE_OK) { + LOGE("fail to update recent history : %s", sqlite3_errmsg(db)); + goto cleanup; + } + + sqlite3_bind_int(stmt, 1, record_id); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_OK && ret != SQLITE_DONE) { + LOGE("sqlite3_step() failed : ret(%d)", ret); + goto cleanup; + } else if (sqlite3_changes(db) == 0) { + LOGE("No changes to DB"); + goto cleanup; + } + + sqlite3_finalize(stmt); + sqlite3_close(db); + + return STICKERD_SERVER_ERROR_NONE; + +cleanup: + sqlite3_finalize(stmt); + sqlite3_close(db); + + return STICKERD_SERVER_ERROR_DB_FAILED; } \ No newline at end of file diff --git a/server/stickerd_db_manager.h b/server/stickerd_db_manager.h index 4a14e50..38e13b5 100644 --- a/server/stickerd_db_manager.h +++ b/server/stickerd_db_manager.h @@ -34,6 +34,7 @@ typedef enum { STICKER_DB_STICKER_GROUP, STICKER_DB_STICKER_KEYWORD, STICKER_DB_STICKER_DISP_TYPE, + STICKER_DB_STICKER_RECENT_HISTORY, } sticker_info_db_type; typedef struct { @@ -60,6 +61,7 @@ int stickerd_db_get_sticker_count(int *count, char *app_id); int stickerd_db_get_record_id(sticker_info_db_type type, GList **id_list, void *data, char *app_id, int offset, int count); int stickerd_db_get_group_list_by_display_type(GVariantBuilder *builder, char *app_id, int disp_type); int stickerd_db_check_file_exists(int *result, char *uri); +int stickerd_db_insert_recent_sticker_info(int record_id); #ifdef __cplusplus } -- 2.7.4 From de8ad13fcbd9716bb2fa1189c9c152afdaf7cf68 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Fri, 10 Apr 2020 12:07:42 +0900 Subject: [PATCH 14/16] Add a new API for sending whether sticker DB is changed Change-Id: I6cf48055fbdc83bfe564f11146c20f69e243b2a4 --- consumer/sticker_consumer.c | 26 ++++++++++++++++++++ consumer/sticker_consumer_main.h | 2 ++ include/sticker_consumer.h | 52 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/consumer/sticker_consumer.c b/consumer/sticker_consumer.c index 15ea7fc..1c9de90 100644 --- a/consumer/sticker_consumer.c +++ b/consumer/sticker_consumer.c @@ -597,4 +597,30 @@ cleanup: g_variant_iter_free(id_iter); return ret; +} + +EXPORT_API int sticker_consumer_set_event_callback(sticker_consumer_h consumer_handle, sticker_consumer_event_cb callback, void *user_data) +{ + CHECK_STICKER_FEATURE(); + + if (!consumer_handle || !callback) + return STICKER_ERROR_INVALID_PARAMETER; + + consumer_handle->event_cb = callback; + consumer_handle->event_cb_user_data = user_data; + + return STICKER_ERROR_NONE; +} + +EXPORT_API int sticker_consumer_unset_event_callback(sticker_consumer_h consumer_handle) +{ + CHECK_STICKER_FEATURE(); + + if (!consumer_handle) + return STICKER_ERROR_INVALID_PARAMETER; + + consumer_handle->event_cb = NULL; + consumer_handle->event_cb_user_data = NULL; + + return STICKER_ERROR_NONE; } \ No newline at end of file diff --git a/consumer/sticker_consumer_main.h b/consumer/sticker_consumer_main.h index 5f72eaf..f830204 100644 --- a/consumer/sticker_consumer_main.h +++ b/consumer/sticker_consumer_main.h @@ -32,6 +32,8 @@ struct sticker_consumer_s { int monitor_id; int server_monitor_id; char *app_id; + sticker_consumer_event_cb event_cb; + void *event_cb_user_data; }; #ifdef __cplusplus diff --git a/include/sticker_consumer.h b/include/sticker_consumer.h index a143e00..fb6985d 100644 --- a/include/sticker_consumer.h +++ b/include/sticker_consumer.h @@ -35,6 +35,17 @@ extern "C" { */ /** + * @brief Enumeration for event type. + * + * @since_tizen 5.5 + */ +typedef enum { + STICKER_CONSUMER_EVENT_TYPE_INSERT, /**< Insert event type */ + STICKER_CONSUMER_EVENT_TYPE_DELETE, /**< Delete event type */ + STICKER_CONSUMER_EVENT_TYPE_UPDATE, /**< Update event type */ +} sticker_consumer_event_type_e; + +/** * @brief The sticker consumer handle. * @since_tizen 5.5 */ @@ -85,6 +96,17 @@ typedef void (*sticker_consumer_group_list_foreach_cb)(const char *group, void * typedef void (*sticker_consumer_keyword_list_foreach_cb)(const char *keyword, void *user_data); /** + * @brief Called when the stickers are inserted, deleted, or updated. + * @since_tizen 5.5 + * @param[in] event_type The event type of sticker + * @param[in] user_data The user data passed from sticker_consumer_set_event_callback() + * @pre The callback can be registered using sticker_consumer_set_event_callback() + * @see sticker_consumer_set_event_callback() + * @see sticker_consumer_unset_event_callback() + */ +typedef void (*sticker_consumer_event_cb)(sticker_consumer_event_type_e event_type, void *user_data); + +/** * @brief Creates a sticker consumer handle. * @since_tizen 5.5 * @privlevel public @@ -316,6 +338,36 @@ int sticker_consumer_add_recent_data(sticker_consumer_h consumer_handle, sticker int sticker_consumer_get_recent_data_list(sticker_consumer_h consumer_handle, int count, int *result, sticker_consumer_data_foreach_cb callback, void *user_data); /** + * @brief Registers a callback function to be invoked when the stickers are inserted, deleted, or updated. + * @since_tizen 5.5 + * @param[in] consumer_handle The sticker consumer handle + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value + * @retval #STICKER_ERROR_NONE Successful + * @retval #STICKER_ERROR_NOT_SUPPORTED Not supported + * @retval #STICKER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STICKER_ERROR_OPERATION_FAILED Operation failed + * @see sticker_consumer_event_cb() + * @see sticker_consumer_unset_event_callback() + */ +int sticker_consumer_set_event_callback(sticker_consumer_h consumer_handle, sticker_consumer_event_cb callback, void *user_data); + +/** + * @brief Unregisters a callback function. + * @since_tizen 5.5 + * @param[in] consumer_handle The sticker consumer handle + * @return 0 on success, otherwise a negative error value + * @retval #STICKER_ERROR_NONE Successful + * @retval #STICKER_ERROR_NOT_SUPPORTED Not supported + * @retval #STICKER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STICKER_ERROR_OPERATION_FAILED Operation failed + * @see sticker_consumer_event_cb() + * @see sticker_consumer_set_event_callback() + */ +int sticker_consumer_unset_event_callback(sticker_consumer_h consumer_handle); + +/** * @} */ -- 2.7.4 From 6f1b4554bc68c9c33e09ea290e09a6429bcf94c1 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Fri, 10 Apr 2020 15:06:08 +0900 Subject: [PATCH 15/16] Fix invalid pointer casting Change-Id: Ib6eec53220eb03bd4a561b62e6ab03f2cbb641d6 --- client/sticker_dbus.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/client/sticker_dbus.c b/client/sticker_dbus.c index c6aaaea..f8a4b72 100644 --- a/client/sticker_dbus.c +++ b/client/sticker_dbus.c @@ -933,7 +933,7 @@ int sticker_dbus_get_all_sticker_info(GDBusConnection *gdbus_connection, const c ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", app_id, offset, count), &reply, "get_all_sticker_info"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); - g_variant_get(reply_body, "(a(i))", &(*id_iter)); + g_variant_get(reply_body, "(a(i))", id_iter); } if (reply_body) @@ -954,7 +954,7 @@ int sticker_dbus_get_sticker_info_by_appid(GDBusConnection *gdbus_connection, co ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", app_id, offset, count), &reply, "get_sticker_info_by_appid"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); - g_variant_get(reply_body, "(a(i))", &(*id_iter)); + g_variant_get(reply_body, "(a(i))", id_iter); } if (reply_body) @@ -975,7 +975,7 @@ int sticker_dbus_get_sticker_info_by_type(GDBusConnection *gdbus_connection, con ret = _send_sync_message(gdbus_connection, g_variant_new("(siii)", app_id, (int)type, offset, count), &reply, "get_sticker_info_by_type"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); - g_variant_get(reply_body, "(a(i))", &(*id_iter)); + g_variant_get(reply_body, "(a(i))", id_iter); } if (reply_body) @@ -996,7 +996,7 @@ int sticker_dbus_get_sticker_info_by_group(GDBusConnection *gdbus_connection, co ret = _send_sync_message(gdbus_connection, g_variant_new("(ssii)", app_id, group, offset, count), &reply, "get_sticker_info_by_group"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); - g_variant_get(reply_body, "(a(i))", &(*id_iter)); + g_variant_get(reply_body, "(a(i))", id_iter); } if (reply_body) @@ -1017,7 +1017,7 @@ int sticker_dbus_get_sticker_info_by_keyword(GDBusConnection *gdbus_connection, ret = _send_sync_message(gdbus_connection, g_variant_new("(ssii)", app_id, keyword, offset, count), &reply, "get_sticker_info_by_keyword"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); - g_variant_get(reply_body, "(a(i))", &(*id_iter)); + g_variant_get(reply_body, "(a(i))", id_iter); } if (reply_body) @@ -1038,7 +1038,7 @@ int sticker_dbus_get_sticker_info_by_display_type(GDBusConnection *gdbus_connect ret = _send_sync_message(gdbus_connection, g_variant_new("(siii)", app_id, (int)type, offset, count), &reply, "get_sticker_info_by_disp_type"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); - g_variant_get(reply_body, "(a(i))", &(*id_iter)); + g_variant_get(reply_body, "(a(i))", id_iter); } if (reply_body) @@ -1134,7 +1134,7 @@ int sticker_dbus_get_recent_sticker_list(GDBusConnection *gdbus_connection, int ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", count), &reply, "get_recent_sticker_info"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); - g_variant_get(reply_body, "(a(i))", &(*id_iter)); + g_variant_get(reply_body, "(a(i))", id_iter); } if (reply_body) -- 2.7.4 From e5359c85b9ea99ef5c0c4530cce887742f25498c Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 9 Apr 2020 20:00:00 +0900 Subject: [PATCH 16/16] Reduce duplicated code Change-Id: I60e2527d5c3ecb325988a00f1be3ea8a7e88d4f0 Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 9288b72..34763da 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -566,6 +566,13 @@ static bool process_request_queue() return true; } +static void quit() +{ + job_progress = FALSE; + send_disconnect_message(); + service_app_exit(); +} + void on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned int payload_length, void *buffer, void *user_data) /* message exchange on_receive callback (sap_agent_data_received_cb) */ @@ -626,9 +633,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in #endif if (!process_request_queue()) { - job_progress = FALSE; - send_disconnect_message(); - service_app_exit(); + quit(); } } else if (msg_id == STICKER_SYNC_START_RSP) { LOGD("msg : %s", msg_id.c_str()); @@ -658,9 +663,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in if (result_code == SYNC_START_RSP_NO_STICKER) save_last_sync_time(); - job_progress = FALSE; - send_disconnect_message(); - service_app_exit(); + quit(); } } } else if (msg_id == STICKER_SEND_START_REQ) { @@ -782,9 +785,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in if (!process_request_queue()) { sync_success_cnt = 0; - job_progress = FALSE; - send_disconnect_message(); - service_app_exit(); + quit(); } } else LOGW("unknown msg id : %s", msg_id.c_str()); -- 2.7.4