From 04404d91a21104a5abe8d048a739425775475795 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 10 Apr 2020 19:36:23 +0900 Subject: [PATCH 01/16] Update package version to 0.1.32 Change-Id: I630b6ac296dcaad0ff47e7d69981091fd7ebac5e 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 eb79cd5..6c728fa 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.31 +Version: 0.1.32 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index cf0b55e..efed9ad 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -1,5 +1,5 @@ - + -- 2.7.4 From eb8901c263076a7e36eb9822fb9f595900c14aaf Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Mon, 13 Apr 2020 11:14:20 +0900 Subject: [PATCH 02/16] Remove unnecessary error logs Change-Id: Ib1333d15087741edc3155e9be7efb3312149fba7 Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 34763da..55c3f38 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -415,12 +415,10 @@ 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) - if (!request_sticker_data(mode, "arsticker", type)) - LOGW("Failed to request ar_sticker sync"); + request_sticker_data(mode, "arsticker", type); if (feature_flag & VCONFKEY_STICKER_FEATURE_BITMOJI) - if (!request_sticker_data(mode, "bitmoji", type)) - LOGW("Failed to request bitmoji sync"); + request_sticker_data(mode, "bitmoji", type); } else LOGW("Failed to get value of VCONFKEY_STICKER_SUPPORTED_FEATURE"); -- 2.7.4 From 483b8e05c9c4b67e26ee552defac632c109b02fc Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 10 Apr 2020 20:29:47 +0900 Subject: [PATCH 03/16] Fixed an issue sending errors during synchronization Change-Id: I24d6009d2bf039b42780ff62c0f1dcf423a0af16 Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 62 insertions(+), 16 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 55c3f38..eb4e297 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -87,6 +87,7 @@ 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 int sync_complete_flags = 0; static void save_last_sync_time() { @@ -100,7 +101,7 @@ static void save_last_sync_time() } } -static void set_sync_complete() +static void set_sync_first_complete() { int complete_flags = 0; if (vconf_get_int(VCONFKEY_STICKER_SYNC_COMPLETE, &complete_flags) == 0 && complete_flags == 0) { @@ -110,7 +111,11 @@ static void set_sync_complete() else LOGW("Fail to set sync complete"); } +} +static void set_sync_complete() +{ + set_sync_first_complete(); save_last_sync_time(); } @@ -571,6 +576,60 @@ static void quit() service_app_exit(); } +static void send_sync_start_response(int result_code) +{ + int feature_flag = 0; + string response_to_app; + switch (result_code) { + case SYNC_START_RSP_SUCCESS: + { + response_to_app = "success"; + if (current_request.category == string("arsticker")) + sync_complete_flags |= VCONFKEY_STICKER_FEATURE_AREMOJI; + else if (current_request.category == string("bitmoji")) + sync_complete_flags |= VCONFKEY_STICKER_FEATURE_BITMOJI; + } + break; + case SYNC_START_RSP_NO_STICKER: + response_to_app = "no_sticker"; + break; + default: + response_to_app = "unknown_error"; + break; + } + + LOGD("result code : %d, sync complete flag : %d", result_code, sync_complete_flags); + +#ifdef VCONFKEY_STICKER_SUPPORTED_FEATURE + if (vconf_get_int(VCONFKEY_STICKER_SUPPORTED_FEATURE, &feature_flag) != 0) + { + LOGW("Failed to read support feature"); + return; + } + + LOGD("feature : %d, current request category : %s", feature_flag, current_request.category.c_str()); + if (feature_flag == VCONFKEY_STICKER_FEATURE_AREMOJI || + feature_flag == VCONFKEY_STICKER_FEATURE_BITMOJI) + { + LOGD("only standalone sync mode"); + send_message("sync_start_response", response_to_app.c_str()); + } + else { + if (current_request.category == string("arsticker")) + { + if (result_code == SYNC_START_RSP_SUCCESS) + send_message("sync_start_response", response_to_app.c_str()); + } + else if (current_request.category == string("bitmoji")) + { + if (sync_complete_flags == 0 || + sync_complete_flags == VCONFKEY_STICKER_FEATURE_BITMOJI) + send_message("sync_start_response", response_to_app.c_str()); + } + } +#endif +} + 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) */ @@ -640,24 +699,11 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in 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: - 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()); + send_sync_start_response(result_code); if (result_code != SYNC_START_RSP_SUCCESS) { - set_sync_progressing(FALSE); if (!process_request_queue()) { + set_sync_progressing(FALSE); if (result_code == SYNC_START_RSP_NO_STICKER) save_last_sync_time(); -- 2.7.4 From 49de48fbff52178b3582d7912c336068da18f239 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Mon, 13 Apr 2020 14:39:36 +0900 Subject: [PATCH 04/16] Update package version to 0.1.33 Change-Id: Iccd3988c52eb94f0984f4e2996b37e0acbf9543b 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 6c728fa..1bfd88b 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.32 +Version: 0.1.33 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index efed9ad..624126f 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -1,5 +1,5 @@ - + -- 2.7.4 From a0ad6afd4cd651b848ef2b8a8c5bc9f3db6f05d4 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 13 Apr 2020 19:26:45 +0900 Subject: [PATCH 05/16] Add missing condition check code Change-Id: I736566ac02f1c70b8ae302a93228a236bb3005a9 --- server/stickerd_data_manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/stickerd_data_manager.c b/server/stickerd_data_manager.c index 251e9c0..d82b2cf 100644 --- a/server/stickerd_data_manager.c +++ b/server/stickerd_data_manager.c @@ -767,7 +767,7 @@ int stickerd_insert_sticker_info_by_json(GVariant *parameters, GVariant **reply_ goto free_memory; sticker_info->thumbnail = _get_string_from_object(info_object, "thumbnail"); - if (sticker_info->thumbnail) { + if (sticker_info->thumbnail && sticker_info->thumbnail[0] != '\0') { if (_check_file_exist(sticker_info->app_id, sticker_info->thumbnail) == 0) { sticker_info->thumbnail = _convert_sticker_uri(sticker_info->thumbnail, sticker_info->app_id); if (!sticker_info->thumbnail) -- 2.7.4 From 32bd8d402850917ee150661c0e03a29f35ecb75e Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 13 Apr 2020 10:25:56 +0900 Subject: [PATCH 06/16] Add missing parameter to event callback Change-Id: I2fcad31c0c17dacc8703f83c82c5a574a2608ca1 --- include/sticker_consumer.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/sticker_consumer.h b/include/sticker_consumer.h index fb6985d..7231f26 100644 --- a/include/sticker_consumer.h +++ b/include/sticker_consumer.h @@ -98,13 +98,18 @@ typedef void (*sticker_consumer_keyword_list_foreach_cb)(const char *keyword, vo /** * @brief Called when the stickers are inserted, deleted, or updated. * @since_tizen 5.5 + * @remarks @a data_handle should not be freed and can be used only in the callback. + * If you want to use it outside of the callback, you need to use a clone which can be obtained sticker_data_clone(). + * When the @a event_type is STICKER_CONSUMER_EVENT_TYPE_DELETE, sticker data can be obtained using @a data_handle, + * but unable to access file because it has been deleted. * @param[in] event_type The event type of sticker + * @param[in] data_handle The sticker data handle * @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); +typedef void (*sticker_consumer_event_cb)(sticker_consumer_event_type_e event_type, sticker_data_h data_handle, void *user_data); /** * @brief Creates a sticker consumer handle. -- 2.7.4 From f31d31c3cb45b89edf4d743026b0e0c24fb52777 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 13 Apr 2020 14:24:08 +0900 Subject: [PATCH 07/16] Support the event callback to send sticker DB changes Change-Id: I43d08448b3d67794f2ea7f7ccfdd4b8a9a9d3508 --- client/sticker_dbus.c | 82 ++++++++++++++++++----- client/sticker_dbus.h | 3 +- client/sticker_defs.h | 6 ++ consumer/sticker_consumer.c | 2 +- provider/sticker_provider.c | 3 +- server/stickerd_data_manager.c | 147 +++++++++++++++++++++++++++++++++++++---- server/stickerd_data_manager.h | 1 + server/stickerd_db_manager.c | 85 ++++++++++++++++++++++++ server/stickerd_db_manager.h | 1 + server/stickerd_dbus.c | 16 ++++- server/stickerd_dbus.h | 4 +- 11 files changed, 312 insertions(+), 38 deletions(-) diff --git a/client/sticker_dbus.c b/client/sticker_dbus.c index f8a4b72..412a143 100644 --- a/client/sticker_dbus.c +++ b/client/sticker_dbus.c @@ -26,6 +26,7 @@ #define STICKER_DIRECTORY tzplatform_mkpath(TZ_SYS_SHARE, "sticker-data") static int is_server_started = 0; +static CLIENT_LIB last_req_lib = STICKER_CLIENT_LIB_NONE; static void _server_appeared_cb(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data) { @@ -74,18 +75,14 @@ static int _dbus_init(GDBusConnection **gdbus_connection) return STICKER_CLIENT_ERROR_NONE; } -static void _get_sticker_info_from_gvariant(GVariant *body, sticker_data_h sticker_data) +static void _get_sticker_info_from_gvariant(GVariantIter *info_iter, GVariantIter *keyword_iter, sticker_data_h sticker_data) { STICKER_DAT_TYPE key; GVariant *value = NULL; - GVariantIter *info_iter = NULL; - GVariantIter *keyword_iter = NULL; char *keyword = NULL; - g_variant_get(body, "(a{iv}a(s))", &info_iter, &keyword_iter); - if (!info_iter || !keyword_iter) { - LOGD("failed to get iter"); + LOGW("failed to get iter"); return; } @@ -206,6 +203,29 @@ static void _handle_sticker_consumer_cb(GDBusConnection *connection, return; } + if (g_strcmp0(signal_name, "send_sticker_changed_event") == 0) { + if (consumer_handle->event_cb != NULL) { + sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s)); + if (sticker_data) { + int event_type; + GVariantIter *info_iter = NULL; + GVariantIter *keyword_iter = NULL; + + g_variant_get(parameters, "(ia{iv}a(s))", &event_type, &info_iter, &keyword_iter); + _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data); + consumer_handle->event_cb((sticker_consumer_event_type_e)event_type, sticker_data, consumer_handle->event_cb_user_data); + + if (info_iter) + g_variant_iter_free(info_iter); + + if (keyword_iter) + g_variant_iter_free(keyword_iter); + + _free_sticker_data(sticker_data); + } + } + } + #if 0 // Receive the sticker information by asynchronous communication. if (g_strcmp0(signal_name, "send_group_list") == 0) { if (consumer_handle->group_foreach_cb != NULL) @@ -446,14 +466,13 @@ static int _send_async_message(GDBusConnection *gdbus_connection, GVariant *body return ret; } -static int _monitor_register(GDBusConnection *gdbus_connection, int *server_watcher_id) +static int _monitor_register(GDBusConnection *gdbus_connection, int *server_watcher_id, CLIENT_LIB lib) { int ret; GDBusMessage *reply = NULL; GVariant *reply_body = NULL; - ret = _send_sync_message(gdbus_connection, g_variant_new("()"), &reply, "sticker_service_register"); - + ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", (int)lib), &reply, "sticker_service_register"); if (ret != STICKER_CLIENT_ERROR_NONE) { LOGE("_send_sync_message() failed : %d", ret); return ret; @@ -476,7 +495,7 @@ static void _on_name_appeared(GDBusConnection *connection, { if (is_server_started == 0) { int *watcher_id = (int *)user_data; - _monitor_register(connection, watcher_id); + _monitor_register(connection, watcher_id, last_req_lib); } } @@ -493,6 +512,7 @@ int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, void *data) { int ret; + last_req_lib = lib; ret = _dbus_init(gdbus_connection); if (ret != STICKER_CLIENT_ERROR_NONE) { @@ -506,7 +526,7 @@ int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id return ret; } - ret = _monitor_register(*gdbus_connection, server_watcher_id); + ret = _monitor_register(*gdbus_connection, server_watcher_id, lib); if (ret != STICKER_CLIENT_ERROR_NONE) { LOGE("_monitor_register() failed : %d", ret); return ret; @@ -532,12 +552,12 @@ int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id return STICKER_CLIENT_ERROR_NONE; } -int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id) +int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id, CLIENT_LIB lib) { int ret; if (server_watcher_id) { - ret = _send_async_message(gdbus_connection, g_variant_new("(i)", *server_watcher_id), "sticker_service_unregister"); + ret = _send_async_message(gdbus_connection, g_variant_new("(ii)", (int)lib, *server_watcher_id), "sticker_service_unregister"); if (ret != STICKER_CLIENT_ERROR_NONE) { LOGE("Failed to unregister sticker service"); return ret; @@ -663,6 +683,7 @@ int sticker_dbus_delete_sticker_info_by_uri(GDBusConnection *gdbus_connection, c int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data) { int ret; + bool is_updated = false; GDBusMessage *reply = NULL; GVariant *reply_body = NULL; sticker_data_h origin_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s)); @@ -675,7 +696,17 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "get_sticker_info"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); - _get_sticker_info_from_gvariant(reply_body, origin_data); + GVariantIter *info_iter = NULL; + GVariantIter *keyword_iter = NULL; + + g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter); + _get_sticker_info_from_gvariant(info_iter, keyword_iter, origin_data); + + if (info_iter) + g_variant_iter_free(info_iter); + + if (keyword_iter) + g_variant_iter_free(keyword_iter); } else { LOGW("failed to get sticker info"); free(origin_data); @@ -721,6 +752,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ free(conv_path); goto cleanup; } + is_updated = true; } free(conv_path); } @@ -732,6 +764,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ LOGE("failed to update sticker type"); goto cleanup; } + is_updated = true; } if (sticker_data->thumbnail) { @@ -749,6 +782,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ free(conv_path); goto cleanup; } + is_updated = true; } free(conv_path); } @@ -761,6 +795,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ LOGE("failed to update sticker description"); goto cleanup; } + is_updated = true; } if (sticker_data->group && strcmp(sticker_data->group, origin_data->group) != 0) { @@ -770,6 +805,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ LOGE("failed to update sticker group"); goto cleanup; } + is_updated = true; } if (sticker_data->disp_type != 0 && sticker_data->disp_type != origin_data->disp_type) { @@ -779,6 +815,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ LOGE("failed to update sticker display type"); goto cleanup; } + is_updated = true; } if (sticker_data->keyword) { @@ -788,9 +825,14 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ ret = _send_sync_message(gdbus_connection, g_variant_new("(ia(s))", sticker_data->sticker_info_id, keyword_builder), &reply, "update_sticker_keyword"); if (ret != STICKER_CLIENT_ERROR_NONE) LOGE("failed to update sticker keyword"); + else + is_updated = true; g_variant_builder_unref(keyword_builder); } + if (is_updated) + ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "send_update_event"); + cleanup: _free_sticker_data(origin_data); @@ -808,15 +850,25 @@ int sticker_dbus_get_sticker_info_by_record_id(GDBusConnection *gdbus_connection int ret; GDBusMessage *reply = NULL; GVariant *reply_body = NULL; + GVariantIter *info_iter = NULL; + GVariantIter *keyword_iter = NULL; ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "get_sticker_info"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); sticker_data->sticker_info_id = record_id; - _get_sticker_info_from_gvariant(reply_body, sticker_data); + + g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter); + _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data); if (reply_body) g_variant_unref(reply_body); + + if (info_iter) + g_variant_iter_free(info_iter); + + if (keyword_iter) + g_variant_iter_free(keyword_iter); } if (reply) diff --git a/client/sticker_dbus.h b/client/sticker_dbus.h index a6d5437..4115e1d 100644 --- a/client/sticker_dbus.h +++ b/client/sticker_dbus.h @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -47,7 +48,7 @@ enum sticker_client_error { int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id, int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, void *data); -int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id); +int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id, CLIENT_LIB lib); int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data); int sticker_dbus_insert_sticker_info_by_json(GDBusConnection *gdbus_connection, const char *app_id, const char *json_path); int sticker_dbus_delete_sticker_info(GDBusConnection *gdbus_connection, int record_id); diff --git a/client/sticker_defs.h b/client/sticker_defs.h index 01cae60..69167ec 100644 --- a/client/sticker_defs.h +++ b/client/sticker_defs.h @@ -69,6 +69,12 @@ typedef enum { STICKER_DATA_TYPE_DISP_TYPE, } STICKER_DAT_TYPE; +typedef enum { + STICKER_EVENT_TYPE_INSERT, + STICKER_EVENT_TYPE_DELETE, + STICKER_EVENT_TYPE_UPDATE, +} STICKER_EVENT_TYPE; + #ifdef __cplusplus } #endif diff --git a/consumer/sticker_consumer.c b/consumer/sticker_consumer.c index 1c9de90..91de924 100644 --- a/consumer/sticker_consumer.c +++ b/consumer/sticker_consumer.c @@ -189,7 +189,7 @@ EXPORT_API int sticker_consumer_destroy(sticker_consumer_h consumer_handle) LOGD("consumer_handle : %p", consumer_handle); ret = sticker_dbus_shutdown(consumer_handle->gdbus_connection, &consumer_handle->server_watcher_id, - &consumer_handle->server_monitor_id, &consumer_handle->monitor_id); + &consumer_handle->server_monitor_id, &consumer_handle->monitor_id, STICKER_CLIENT_LIB_CONSUMER); if (ret != STICKER_ERROR_NONE) { LOGE("Failed to finalize dbus : %d", ret); free(consumer_handle); diff --git a/provider/sticker_provider.c b/provider/sticker_provider.c index 98f1005..b16db5e 100644 --- a/provider/sticker_provider.c +++ b/provider/sticker_provider.c @@ -107,7 +107,7 @@ EXPORT_API int sticker_provider_destroy(sticker_provider_h provider_handle) LOGD("provider_handle : %p", provider_handle); ret = sticker_dbus_shutdown(provider_handle->gdbus_connection, &provider_handle->server_watcher_id, - &provider_handle->server_monitor_id, &provider_handle->monitor_id); + &provider_handle->server_monitor_id, &provider_handle->monitor_id, STICKER_CLIENT_LIB_PROVIDER); if (ret != STICKER_ERROR_NONE) { LOGE("Failed to finalize dbus : %d", ret); free(provider_handle); @@ -151,7 +151,6 @@ EXPORT_API int sticker_provider_insert_data(sticker_provider_h provider_handle, else return STICKER_ERROR_OPERATION_FAILED; } - return STICKER_ERROR_NONE; } diff --git a/server/stickerd_data_manager.c b/server/stickerd_data_manager.c index d82b2cf..23c09e0 100644 --- a/server/stickerd_data_manager.c +++ b/server/stickerd_data_manager.c @@ -44,6 +44,7 @@ static GHashTable *_monitoring_hash = NULL; static char error_buffer[MAX_ERROR_BUFFER]; +static GList *consumer_list = NULL; extern GMainLoop *main_loop; static void _check_watcher_exist() @@ -52,6 +53,8 @@ static void _check_watcher_exist() LOGD("Terminate sticker daemon"); g_hash_table_destroy(_monitoring_hash); _monitoring_hash = NULL; + g_list_free_full(consumer_list, free); + consumer_list = NULL; g_main_loop_quit(main_loop); } } @@ -77,6 +80,9 @@ static void _on_name_vanished(GDBusConnection *connection, delete_monitoring_list(&_monitoring_hash, info->bus_name, info->watcher_id); } + if (g_list_find(consumer_list, info->bus_name)) + consumer_list = g_list_remove(consumer_list, info->bus_name); + if (info->bus_name) free(info->bus_name); free(info); @@ -95,14 +101,17 @@ static void _stickerd_client_dbus_method_call_handler(GDBusConnection *conn, con if (_monitoring_hash == NULL) _monitoring_hash = g_hash_table_new(g_direct_hash, g_direct_equal); + if (consumer_list == NULL) + consumer_list = g_list_alloc(); + GVariant *reply_body = NULL; int ret = STICKERD_SERVER_ERROR_OPERATION_FAILED; if (g_strcmp0(method_name, "sticker_service_register") == 0) { ret = stickerd_server_register(parameters, &reply_body, sender, - _on_name_appeared, _on_name_vanished, &_monitoring_hash); + _on_name_appeared, _on_name_vanished, &_monitoring_hash, &consumer_list); } else if (g_strcmp0(method_name, "sticker_service_unregister") == 0) { - ret = stickerd_server_unregister(parameters, &reply_body, sender, &_monitoring_hash); + ret = stickerd_server_unregister(parameters, &reply_body, sender, &_monitoring_hash, &consumer_list); } else if (g_strcmp0(method_name, "insert_sticker_info") == 0) { ret = stickerd_insert_sticker_info(parameters, &reply_body); } else if (g_strcmp0(method_name, "update_sticker_info_by_json") == 0) { @@ -153,6 +162,8 @@ static void _stickerd_client_dbus_method_call_handler(GDBusConnection *conn, con 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); + } else if (g_strcmp0(method_name, "send_update_event") == 0) { + ret = stickerd_send_update_event(parameters, &reply_body); } if (ret == STICKERD_SERVER_ERROR_NONE) { @@ -178,10 +189,12 @@ int stickerd_register_dbus_interface(void) " " " " " " + " " " " " " " " + " " " " " " @@ -328,6 +341,10 @@ int stickerd_register_dbus_interface(void) " " " " " " + + " " + " " + " " " " " "; @@ -538,6 +555,70 @@ cleanup: } } +static void _set_keyword_builder(char *keyword, GVariantBuilder *keyword_builder) +{ + if (!keyword) { + LOGE("keyword doesn't exist"); + return; + } + + g_variant_builder_add(keyword_builder, "(s)", (const char *)keyword); +} + +static GVariant* _get_sticker_g_variant(STICKER_EVENT_TYPE type, sticker_info_db *sticker_info) +{ + GVariantBuilder *info_builder; + GVariantBuilder *keyword_builder; + + info_builder = g_variant_builder_new(G_VARIANT_TYPE("a{iv}")); + g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_APP_ID, g_variant_new_string((const gchar *)sticker_info->app_id)); + g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI_TYPE, g_variant_new_int32(sticker_info->type)); + g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI, g_variant_new_string((const gchar *)sticker_info->uri)); + g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_THUMBNAIL, g_variant_new_string((const gchar *)sticker_info->thumbnail)); + g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DESCRIPTION, g_variant_new_string((const gchar *)sticker_info->description)); + g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_GROUP, g_variant_new_string((const gchar *)sticker_info->group)); + g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DATE, g_variant_new_string((const gchar *)sticker_info->date)); + g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DISP_TYPE, g_variant_new_int32(sticker_info->display_type)); + + keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)")); + g_list_foreach(sticker_info->keyword, (GFunc) _set_keyword_builder, keyword_builder); + + GVariant *body = g_variant_new("(ia{iv}a(s))", (int)type, info_builder, keyword_builder); + g_variant_builder_unref(info_builder); + g_variant_builder_unref(keyword_builder); + + if (body) + return body; + else + return NULL; +} + +void _get_consumer_busname(gpointer data, gpointer user_data) +{ + if (data == NULL) + return; + + int ret; + char *cmd = "send_sticker_changed_event"; + char *sender = (char *)data; + GVariant *body = (GVariant *)user_data; + + ret = stickerd_send_dbus_message(body, sender, cmd, STICKER_CLIENT_LIB_CONSUMER); + if (ret != STICKERD_SERVER_ERROR_NONE) + LOGE("Failed to send sticker changed event"); +} + +static void _send_sticker_changed_event(STICKER_EVENT_TYPE type, sticker_info_db *sticker_info) +{ + GVariant *body = _get_sticker_g_variant(type, sticker_info); + + if (body) + g_list_foreach(consumer_list, _get_consumer_busname, body); + + if (body) + g_variant_unref(body); +} + int stickerd_insert_sticker_info(GVariant *parameters, GVariant **reply_body) { int ret; @@ -635,7 +716,8 @@ int stickerd_insert_sticker_info(GVariant *parameters, GVariant **reply_body) if (*reply_body == NULL) { LOGE("Failed to create reply_body"); ret = STICKERD_SERVER_ERROR_OPERATION_FAILED; - } + } else + _send_sticker_changed_event(STICKER_EVENT_TYPE_INSERT, sticker_info); cleanup: if (value) @@ -794,7 +876,8 @@ int stickerd_insert_sticker_info_by_json(GVariant *parameters, GVariant **reply_ if (ret != STICKERD_SERVER_ERROR_NONE) { LOGE("Failed to insert sticker info"); ret = STICKERD_SERVER_ERROR_OPERATION_FAILED; - } + } else + _send_sticker_changed_event(STICKER_EVENT_TYPE_INSERT, sticker_info); free_memory: free(sticker_info); @@ -833,10 +916,20 @@ int stickerd_del_sticker_info(GVariant *parameters, GVariant **reply_body) g_variant_get(parameters, "(i)", &record_id); + sticker_info_db *sticker_info = (sticker_info_db *)calloc(1, sizeof(sticker_info_db)); + if (sticker_info) + stickerd_db_get_sticker_info_by_record_id(record_id, sticker_info); + ret = stickerd_db_delete_sticker_info(record_id); if (ret != STICKERD_SERVER_ERROR_NONE) { LOGE("Failed to delete sticker info"); return STICKERD_SERVER_ERROR_OPERATION_FAILED; + } else { + if (sticker_info && sticker_info->uri) { + _send_sticker_changed_event(STICKER_EVENT_TYPE_DELETE, sticker_info); + free(sticker_info); + sticker_info = NULL; + } } return ret; @@ -855,10 +948,20 @@ int stickerd_del_sticker_info_by_uri(GVariant *parameters, GVariant **reply_body g_variant_get(parameters, "(&s)", &uri); + sticker_info_db *sticker_info = (sticker_info_db *)calloc(1, sizeof(sticker_info_db)); + if (sticker_info) + stickerd_db_get_sticker_info_by_uri(uri, sticker_info); + ret = stickerd_db_delete_sticker_info_by_uri(uri); if (ret != STICKERD_SERVER_ERROR_NONE) { LOGE("Failed to delete sticker info"); return STICKERD_SERVER_ERROR_OPERATION_FAILED; + } else { + if (sticker_info && sticker_info->uri) { + _send_sticker_changed_event(STICKER_EVENT_TYPE_DELETE, sticker_info); + free(sticker_info); + sticker_info = NULL; + } } return ret; @@ -1040,16 +1143,6 @@ int stickerd_update_sticker_keyword(GVariant *parameters, GVariant **reply_body) return ret; } -static void _set_keyword_builder(char *keyword, GVariantBuilder *keyword_builder) -{ - if (!keyword) { - LOGE("keyword doesn't exist"); - return; - } - - g_variant_builder_add(keyword_builder, "(s)", (const char *)keyword); -} - int stickerd_get_sticker_info(GVariant *parameters, GVariant **reply_body) { int ret; @@ -1628,4 +1721,30 @@ int stickerd_get_recent_sticker_info(GVariant *parameters, GVariant **reply_body g_variant_builder_unref(id_builder); return ret; +} + +int stickerd_send_update_event(GVariant *parameters, GVariant **reply_body) +{ + int ret = STICKERD_SERVER_ERROR_NONE; + 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); + + sticker_info_db *sticker_info = (sticker_info_db *)calloc(1, sizeof(sticker_info_db)); + if (sticker_info) { + ret = stickerd_db_get_sticker_info_by_record_id(record_id, sticker_info); + if (ret == STICKERD_SERVER_ERROR_NONE) { + _send_sticker_changed_event(STICKER_EVENT_TYPE_UPDATE, sticker_info); + free(sticker_info); + sticker_info = NULL; + } + } + + return ret; } \ No newline at end of file diff --git a/server/stickerd_data_manager.h b/server/stickerd_data_manager.h index ea90752..6b54c68 100644 --- a/server/stickerd_data_manager.h +++ b/server/stickerd_data_manager.h @@ -50,6 +50,7 @@ int stickerd_update_sticker_disp_type(GVariant *parameters, GVariant **reply_bod 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); +int stickerd_send_update_event(GVariant *parameters, GVariant **reply_body); #ifdef __cplusplus } diff --git a/server/stickerd_db_manager.c b/server/stickerd_db_manager.c index 9536c65..ecf8f33 100644 --- a/server/stickerd_db_manager.c +++ b/server/stickerd_db_manager.c @@ -100,6 +100,7 @@ #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 ?" +#define STICKER_DB_GET_STICKER_INFO_BY_URI "SELECT * FROM sticker_info WHERE uri = ?" typedef enum { @@ -1004,4 +1005,88 @@ cleanup: sqlite3_close(db); return STICKERD_SERVER_ERROR_DB_FAILED; +} + +int stickerd_db_get_sticker_info_by_uri(char *uri, sticker_info_db *sticker_info) +{ + int ret; + int record_id; + 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_GET_STICKER_INFO_BY_URI, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + LOGE("fail to get sticker information : %s", sqlite3_errmsg(db)); + goto cleanup; + } + + sqlite3_bind_text(stmt, 1, uri, -1, SQLITE_TRANSIENT); + + ret = sqlite3_step(stmt); + if (ret == SQLITE_ERROR) { + LOGE("sqlite3_step() failed : ret(%d)", ret); + goto cleanup; + } + + record_id = sticker_info->display_type = sqlite3_column_int(stmt, 0); + + const unsigned char *tmp_app_id = sqlite3_column_text(stmt, 1); + if (tmp_app_id) + sticker_info->app_id = strdup((const char *)tmp_app_id); + + sticker_info->type = sqlite3_column_int(stmt, 2); + + const unsigned char *tmp_uri = sqlite3_column_text(stmt, 3); + if (tmp_uri) + sticker_info->uri = strdup((const char *)tmp_uri); + + const unsigned char *tmp_thumbnail = sqlite3_column_text(stmt, 4); + if (tmp_thumbnail) + sticker_info->thumbnail = strdup((const char *)tmp_thumbnail); + + const unsigned char *tmp_description = sqlite3_column_text(stmt, 5); + if (tmp_description) + sticker_info->description = strdup((const char *)tmp_description); + + const unsigned char *tmp_group = sqlite3_column_text(stmt, 6); + if (tmp_group) + sticker_info->group = strdup((const char *)tmp_group); + + const unsigned char *tmp_date = sqlite3_column_text(stmt, 7); + if (tmp_date) + sticker_info->date = strdup((const char *)tmp_date); + + sticker_info->display_type = sqlite3_column_int(stmt, 8); + + sqlite3_finalize(stmt); + stmt = NULL; + + ret = sqlite3_prepare_v2(db, STICKER_DB_GET_KEYWORD_INFO_BY_RECORD_ID, -1, &stmt, NULL); + if (ret != SQLITE_OK) { + LOGE("fail to get sticker keyword : %s", sqlite3_errmsg(db)); + goto cleanup; + } + + sqlite3_bind_int(stmt, 1, record_id); + + while (sqlite3_step(stmt) == SQLITE_ROW) { + const unsigned char *keyword = sqlite3_column_text(stmt, 0); + if (keyword) + sticker_info->keyword = g_list_append(sticker_info->keyword, strdup((const char *)keyword)); + } + + 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 38e13b5..83bf132 100644 --- a/server/stickerd_db_manager.h +++ b/server/stickerd_db_manager.h @@ -62,6 +62,7 @@ int stickerd_db_get_record_id(sticker_info_db_type type, GList **id_list, void * 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); +int stickerd_db_get_sticker_info_by_uri(char *uri, sticker_info_db *sticker_info); #ifdef __cplusplus } diff --git a/server/stickerd_dbus.c b/server/stickerd_dbus.c index 6184033..d125daf 100644 --- a/server/stickerd_dbus.c +++ b/server/stickerd_dbus.c @@ -32,13 +32,16 @@ static GDBusConnection *_gdbus_connection; extern GMainLoop *main_loop; int stickerd_server_register(GVariant *parameters, GVariant **reply_body, const gchar *sender, GBusNameAppearedCallback name_appeared_handler, - GBusNameVanishedCallback name_vanished_handler, GHashTable **monitoring_hash) + GBusNameVanishedCallback name_vanished_handler, GHashTable **monitoring_hash, GList **consumer_list) { int ret = STICKERD_SERVER_ERROR_NONE; char *m_info_bus_name = NULL; char *list_bus_name = NULL; monitoring_info_s *m_info = NULL; GList *monitoring_list = NULL; + int c_lib; + + g_variant_get(parameters, "(i)", &c_lib); if (reply_body == NULL) return STICKERD_SERVER_ERROR_INVALID_PARAMETER; @@ -80,6 +83,9 @@ int stickerd_server_register(GVariant *parameters, GVariant **reply_body, const goto cleanup; } + if ((CLIENT_LIB)c_lib == STICKER_CLIENT_LIB_CONSUMER) + *consumer_list = g_list_append(*consumer_list, strdup((const char *)sender)); + LOGD("sender: %s, watcher: %d", sender, m_info->watcher_id); monitoring_list = g_list_append(monitoring_list, list_bus_name); if (g_hash_table_lookup(*monitoring_hash, GUINT_TO_POINTER(m_info->watcher_id)) == NULL) @@ -104,11 +110,15 @@ cleanup: return ret; } -int stickerd_server_unregister(GVariant *parameters, GVariant **reply_body, const gchar *sender, GHashTable **monitoring_hash) +int stickerd_server_unregister(GVariant *parameters, GVariant **reply_body, const gchar *sender, GHashTable **monitoring_hash, GList **consumer_list) { int watcher_id = 0; + int c_lib; + + g_variant_get(parameters, "(ii)", &c_lib, &watcher_id); - g_variant_get(parameters, "(i)", &watcher_id); + if ((CLIENT_LIB)c_lib == STICKER_CLIENT_LIB_CONSUMER) + *consumer_list = g_list_remove(*consumer_list, sender); if (g_hash_table_lookup(*monitoring_hash, GUINT_TO_POINTER(watcher_id)) != NULL) { g_bus_unwatch_name(watcher_id); diff --git a/server/stickerd_dbus.h b/server/stickerd_dbus.h index e8ad143..2f684ae 100644 --- a/server/stickerd_dbus.h +++ b/server/stickerd_dbus.h @@ -31,8 +31,8 @@ typedef struct monitoring_info { } monitoring_info_s; int stickerd_server_register(GVariant *parameters, GVariant **reply_body, const gchar *sender, GBusNameAppearedCallback name_appeared_handler, - GBusNameVanishedCallback name_vanished_handler, GHashTable **monitoring_hash); -int stickerd_server_unregister(GVariant *parameters, GVariant **reply_body, const gchar *sender, GHashTable **monitoring_hash); + GBusNameVanishedCallback name_vanished_handler, GHashTable **monitoring_hash, GList **consumer_list); +int stickerd_server_unregister(GVariant *parameters, GVariant **reply_body, const gchar *sender, GHashTable **monitoring_hash, GList **consumer_list); int stickerd_server_register_dbus_interface(char *introspection_xml, GDBusInterfaceVTable interface_vtable); int delete_monitoring_list(GHashTable **monitoring_hash, const char *sender, int monitoring_id); int stickerd_send_dbus_message(GVariant *body, const char *dest, char *cmd, CLIENT_LIB lib); -- 2.7.4 From 39e1a8004a118977a91af8aaed7b3c717bf6db36 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Tue, 14 Apr 2020 13:59:18 +0900 Subject: [PATCH 08/16] Update package version to 0.1.34 Change-Id: Ic4db1fc0d5cb8389b728b7d3cc88985eaa596bcf --- 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 1bfd88b..4df16d5 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.33 +Version: 0.1.34 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index 624126f..124cd9c 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -1,5 +1,5 @@ - + -- 2.7.4 From b93c3268d6af1edb6c50c4b0c6ca64b864d084e3 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Thu, 16 Apr 2020 13:39:38 +0900 Subject: [PATCH 09/16] Set the display type of the sticker Change-Id: I86ecc4aa8c13e5d1f0f64d0b9ba5551447a7f00f --- receiver/inc/sticker_info.h | 2 +- receiver/src/ft.cpp | 3 ++- receiver/src/sticker_info.cpp | 19 ++++++++++++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/receiver/inc/sticker_info.h b/receiver/inc/sticker_info.h index 3a70556..9784b5a 100644 --- a/receiver/inc/sticker_info.h +++ b/receiver/inc/sticker_info.h @@ -17,7 +17,7 @@ #ifndef __STICKER_INFO_H__ #define __STICKER_INFO_H__ -void insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc, const char *thumbnail); +void insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc, const char *thumbnail, const char *disp_type); int create_sticker_provider_handle(void); void destroy_sticker_provider_handle(void); void delete_sticker_data(const char *fileName); diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index eb4e297..2d231d0 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -223,7 +223,8 @@ static void _on_transfer_completed(sap_file_transaction_h file_transaction, sticker_data.thumbnail_path.clear(); } - insert_sticker_data(sticker_data.file_path.c_str(), sticker_data.keyword.c_str(), sticker_data.group.c_str(), sticker_data.description.c_str(), sticker_data.thumbnail_path.c_str()); + insert_sticker_data(sticker_data.file_path.c_str(), sticker_data.keyword.c_str(), sticker_data.group.c_str(), sticker_data.description.c_str(), + sticker_data.thumbnail_path.c_str(), sticker_data.disp_type.c_str()); destroy_sticker_provider_handle(); if (unlink(sticker_data.file_path.c_str()) == -1) diff --git a/receiver/src/sticker_info.cpp b/receiver/src/sticker_info.cpp index 38c9709..2d5e58d 100644 --- a/receiver/src/sticker_info.cpp +++ b/receiver/src/sticker_info.cpp @@ -26,7 +26,7 @@ static sticker_provider_h sticker_provider = NULL; sticker_data_h set_sticker_data(sticker_data_uri_type_e type, const char* uri, const char* keyword, -int len, const char* group, const char* thumbnail, const char* description) +int len, const char* group, const char* thumbnail, const char* description, sticker_data_display_type_e disp_type) { sticker_data_h sticker_data; int ret; @@ -78,16 +78,29 @@ int len, const char* group, const char* thumbnail, const char* description) LOGE("Failed to set description"); } + /* Sets the display type of the sticker.*/ + ret = sticker_data_set_display_type(sticker_data, disp_type); + if (ret != STICKER_ERROR_NONE) { + /* Error handling */ + LOGE("Failed to set display type"); + } + return sticker_data; } void -insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc, const char *thumbnail) +insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc, const char *thumbnail, const char *disp_type) { sticker_data_h data_handle; int ret; + sticker_data_display_type_e display_type; + + if (strcmp(disp_type, "input") == 0) + display_type = STICKER_DATA_DISP_EMOJI; + else + display_type = STICKER_DATA_DISP_WALLPAPER; - data_handle = set_sticker_data(STICKER_DATA_URI_LOCAL_PATH, filepath, keyword, 1, group, thumbnail, desc); + data_handle = set_sticker_data(STICKER_DATA_URI_LOCAL_PATH, filepath, keyword, 1, group, thumbnail, desc, display_type); ret = sticker_provider_insert_data(sticker_provider, data_handle); if (ret != STICKER_ERROR_NONE) { -- 2.7.4 From 95678ac2cbfa3fec8ae61f60d342f0100ab855f0 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Thu, 16 Apr 2020 14:21:55 +0900 Subject: [PATCH 10/16] Add missing break Change-Id: I81a8f3db9dc0667ba94fcc4b66e61b54c14e5d4d --- server/stickerd_db_manager.c | 1 + 1 file changed, 1 insertion(+) diff --git a/server/stickerd_db_manager.c b/server/stickerd_db_manager.c index ecf8f33..f3acdbd 100644 --- a/server/stickerd_db_manager.c +++ b/server/stickerd_db_manager.c @@ -160,6 +160,7 @@ 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; + break; case STICKER_DB_STICKER_RECENT_HISTORY: query = STICKER_DB_GET_RECENT_HISTORY; break; -- 2.7.4 From 549a87a10673bd7f83d7d1e89a992794f04f2b05 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Tue, 14 Apr 2020 13:18:52 +0900 Subject: [PATCH 11/16] Prevent memory leak Change-Id: I89922a5fbe23851036c8633d285a9ca473ad31aa --- server/stickerd_data_manager.c | 108 +++++++++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 41 deletions(-) diff --git a/server/stickerd_data_manager.c b/server/stickerd_data_manager.c index 23c09e0..2bb0012 100644 --- a/server/stickerd_data_manager.c +++ b/server/stickerd_data_manager.c @@ -619,6 +619,49 @@ static void _send_sticker_changed_event(STICKER_EVENT_TYPE type, sticker_info_db g_variant_unref(body); } +static void _free_sticker_data(sticker_info_db *sticker_data) +{ + if (!sticker_data) + return; + + if (sticker_data->app_id) { + free(sticker_data->app_id); + sticker_data->app_id = NULL; + } + + if (sticker_data->uri) { + free(sticker_data->uri); + sticker_data->uri = NULL; + } + + if (sticker_data->thumbnail) { + free(sticker_data->thumbnail); + sticker_data->thumbnail = NULL; + } + + if (sticker_data->keyword) { + g_list_free_full(sticker_data->keyword, free); + sticker_data->keyword = NULL; + } + + if (sticker_data->group) { + free(sticker_data->group); + sticker_data->group = NULL; + } + + if (sticker_data->description) { + free(sticker_data->description); + sticker_data->description = NULL; + } + + if (sticker_data->date) { + free(sticker_data->date); + sticker_data->date = NULL; + } + + free(sticker_data); +} + int stickerd_insert_sticker_info(GVariant *parameters, GVariant **reply_body) { int ret; @@ -825,7 +868,7 @@ int stickerd_insert_sticker_info_by_json(GVariant *parameters, GVariant **reply_ continue; } - sticker_info->app_id = app_id; + sticker_info->app_id = strdup(app_id); sticker_info->type = _get_int_from_object(info_object, "type"); if (sticker_info->type < 1) goto free_memory; @@ -880,7 +923,7 @@ int stickerd_insert_sticker_info_by_json(GVariant *parameters, GVariant **reply_ _send_sticker_changed_event(STICKER_EVENT_TYPE_INSERT, sticker_info); free_memory: - free(sticker_info); + _free_sticker_data(sticker_info); sticker_info = NULL; } } @@ -923,13 +966,15 @@ int stickerd_del_sticker_info(GVariant *parameters, GVariant **reply_body) ret = stickerd_db_delete_sticker_info(record_id); if (ret != STICKERD_SERVER_ERROR_NONE) { LOGE("Failed to delete sticker info"); - return STICKERD_SERVER_ERROR_OPERATION_FAILED; + ret = STICKERD_SERVER_ERROR_OPERATION_FAILED; } else { - if (sticker_info && sticker_info->uri) { + if (sticker_info && sticker_info->uri) _send_sticker_changed_event(STICKER_EVENT_TYPE_DELETE, sticker_info); - free(sticker_info); - sticker_info = NULL; - } + } + + if (sticker_info) { + _free_sticker_data(sticker_info); + sticker_info = NULL; } return ret; @@ -955,13 +1000,15 @@ int stickerd_del_sticker_info_by_uri(GVariant *parameters, GVariant **reply_body ret = stickerd_db_delete_sticker_info_by_uri(uri); if (ret != STICKERD_SERVER_ERROR_NONE) { LOGE("Failed to delete sticker info"); - return STICKERD_SERVER_ERROR_OPERATION_FAILED; + ret = STICKERD_SERVER_ERROR_OPERATION_FAILED; } else { - if (sticker_info && sticker_info->uri) { + if (sticker_info && sticker_info->uri) _send_sticker_changed_event(STICKER_EVENT_TYPE_DELETE, sticker_info); - free(sticker_info); - sticker_info = NULL; - } + } + + if (sticker_info) { + _free_sticker_data(sticker_info); + sticker_info = NULL; } return ret; @@ -1159,29 +1206,7 @@ int stickerd_get_sticker_info(GVariant *parameters, GVariant **reply_body) ret = stickerd_db_get_sticker_info_by_record_id(record_id, sticker_info); if (ret != STICKERD_SERVER_ERROR_NONE) { LOGE("Failed to get sticker info"); - - if (sticker_info->app_id) - free(sticker_info->app_id); - - if (sticker_info->uri) - free(sticker_info->uri); - - if (sticker_info->thumbnail) - free(sticker_info->thumbnail); - - if (sticker_info->keyword) - free(sticker_info->keyword); - - if (sticker_info->group) - free(sticker_info->group); - - if (sticker_info->description) - free(sticker_info->description); - - if (sticker_info->date) - free(sticker_info->date); - - free(sticker_info); + _free_sticker_data(sticker_info); sticker_info = NULL; return STICKERD_SERVER_ERROR_OPERATION_FAILED; } @@ -1205,13 +1230,14 @@ int stickerd_get_sticker_info(GVariant *parameters, GVariant **reply_body) if (*reply_body == NULL) { LOGE("Failed to create reply_body"); - free(sticker_info); + _free_sticker_data(sticker_info); sticker_info = NULL; return STICKERD_SERVER_ERROR_OPERATION_FAILED; } - free(sticker_info); + _free_sticker_data(sticker_info); sticker_info = NULL; + return ret; } @@ -1739,11 +1765,11 @@ int stickerd_send_update_event(GVariant *parameters, GVariant **reply_body) sticker_info_db *sticker_info = (sticker_info_db *)calloc(1, sizeof(sticker_info_db)); if (sticker_info) { ret = stickerd_db_get_sticker_info_by_record_id(record_id, sticker_info); - if (ret == STICKERD_SERVER_ERROR_NONE) { + if (ret == STICKERD_SERVER_ERROR_NONE) _send_sticker_changed_event(STICKER_EVENT_TYPE_UPDATE, sticker_info); - free(sticker_info); - sticker_info = NULL; - } + + _free_sticker_data(sticker_info); + sticker_info = NULL; } return ret; -- 2.7.4 From 375c08bbe56fb3faf5e3ce78d11dec8601a3bfa3 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Thu, 16 Apr 2020 19:42:01 +0900 Subject: [PATCH 12/16] Fix issue detected by static analysis tool Change-Id: I1f9c417f1c11bc72d214d45a27ffe78695371301 --- server/stickerd_data_manager.c | 2 +- server/stickerd_db_manager.c | 2 ++ sticker-parser/sticker-parser.c | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/server/stickerd_data_manager.c b/server/stickerd_data_manager.c index 2bb0012..9e6455c 100644 --- a/server/stickerd_data_manager.c +++ b/server/stickerd_data_manager.c @@ -874,7 +874,7 @@ int stickerd_insert_sticker_info_by_json(GVariant *parameters, GVariant **reply_ goto free_memory; sticker_info->uri = _get_string_from_object(info_object, "uri"); - if (!sticker_info->uri) + if (!sticker_info->uri || sticker_info->uri[0] != '\0') goto free_memory; if (sticker_info->type == 1) { diff --git a/server/stickerd_db_manager.c b/server/stickerd_db_manager.c index f3acdbd..ad78560 100644 --- a/server/stickerd_db_manager.c +++ b/server/stickerd_db_manager.c @@ -211,12 +211,14 @@ static int _recover_db(void) if (ret != SQLITE_OK) { LOGE("Failed to create sticker_whitelist_info table : %s", err); ret = STICKERD_SERVER_ERROR_DB_FAILED; + 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; } is_corrupted = FALSE; diff --git a/sticker-parser/sticker-parser.c b/sticker-parser/sticker-parser.c index a3f96b5..9d73dd3 100644 --- a/sticker-parser/sticker-parser.c +++ b/sticker-parser/sticker-parser.c @@ -605,7 +605,7 @@ static int __get_sticker_info_from_json(const char *appid, const char *file_path goto free_memory; char *rel_thumbnail = __get_string_from_object(info_object, "thumbnail"); - if (rel_thumbnail) { + if (rel_thumbnail && rel_thumbnail[0] != '\0') { thumbnail_path = __convert_sticker_uri(rel_thumbnail, appid, app_path); free(rel_thumbnail); } -- 2.7.4 From a4bcf716d4504a4808e4f2dcf24ed9a09e1698ea Mon Sep 17 00:00:00 2001 From: InHong Han Date: Thu, 16 Apr 2020 20:03:36 +0900 Subject: [PATCH 13/16] Add code for the DB recovery Change-Id: Iea229d68322b3c45affbaadea9aa556db4e9a6cc --- server/stickerd_db_manager.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/stickerd_db_manager.c b/server/stickerd_db_manager.c index ad78560..6e3ace3 100644 --- a/server/stickerd_db_manager.c +++ b/server/stickerd_db_manager.c @@ -318,6 +318,9 @@ static sqlite3 *_db_open(void) sqlite3 *db = NULL; char *err = NULL; + if (is_corrupted && _recover_db() != SQLITE_OK) + return NULL; + ret = sqlite3_open(STICKER_DB_PATH, &db); if (ret != SQLITE_OK) { LOGE("Failed to open db : %s", sqlite3_errmsg(db)); -- 2.7.4 From e01c8f0e27241603a1d08fa6e0763bd3f6bb9522 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Thu, 16 Apr 2020 16:12:23 +0900 Subject: [PATCH 14/16] Update package version to 0.1.35 Change-Id: Ib2f937c77c6eef1e4dfa2979561c1a5547d3dbf0 --- 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 4df16d5..d8a7044 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.34 +Version: 0.1.35 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index 124cd9c..083dee3 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -1,5 +1,5 @@ - + -- 2.7.4 From d6dac8b4ddc23c04ea5a648063fe21e0ac206bab Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 13 Apr 2020 12:28:03 +0900 Subject: [PATCH 15/16] Change API description by API review Change-Id: I18a16d9cdc031af5fae04ff8d7e5dd4ae6b20526 --- doc/sticker_doc.h | 2 ++ include/sticker_consumer.h | 16 ++++++++-------- include/sticker_data.h | 7 ++++++- include/sticker_provider.h | 15 ++++++++------- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/doc/sticker_doc.h b/doc/sticker_doc.h index 4c3b325..9938252 100644 --- a/doc/sticker_doc.h +++ b/doc/sticker_doc.h @@ -25,6 +25,8 @@ * * @section CAPI_UIX_STICKER_MODULE_OVERVIEW Overview * Using sticker library, a sticker application can provide sticker information to applications that want to read the sticker information as the standard specification. + * A sticker is an image (possibly animated) that is used in an IM conversation. + * The Sticker API covers the exchange of sticker data between applications. How the images are used depends on a particular sticker consumer application. * * @section CAPI_UIX_STICKER_MODULE_FEATURE Related Feature * This API is related with the following feature:\n diff --git a/include/sticker_consumer.h b/include/sticker_consumer.h index 7231f26..8ac5845 100644 --- a/include/sticker_consumer.h +++ b/include/sticker_consumer.h @@ -40,9 +40,9 @@ extern "C" { * @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_INSERT, /**< A sticker data has been added */ + STICKER_CONSUMER_EVENT_TYPE_DELETE, /**< A sticker data has been removed */ + STICKER_CONSUMER_EVENT_TYPE_UPDATE, /**< A sticker data has been updated */ } sticker_consumer_event_type_e; /** @@ -100,9 +100,9 @@ typedef void (*sticker_consumer_keyword_list_foreach_cb)(const char *keyword, vo * @since_tizen 5.5 * @remarks @a data_handle should not be freed and can be used only in the callback. * If you want to use it outside of the callback, you need to use a clone which can be obtained sticker_data_clone(). - * When the @a event_type is STICKER_CONSUMER_EVENT_TYPE_DELETE, sticker data can be obtained using @a data_handle, - * but unable to access file because it has been deleted. - * @param[in] event_type The event type of sticker + * When the @a event_type is #STICKER_CONSUMER_EVENT_TYPE_DELETE, sticker data can be obtained using @a data_handle, + * but the files have been already deleted. + * @param[in] event_type The event type * @param[in] data_handle The sticker data handle * @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() @@ -289,7 +289,7 @@ int sticker_consumer_keyword_list_foreach_all(sticker_consumer_h consumer_handle int sticker_consumer_data_foreach_by_display_type(sticker_consumer_h consumer_handle, int offset, int count, int *result, sticker_data_display_type_e type, sticker_consumer_data_foreach_cb callback, void *user_data); /** - * @brief Retrieves all group name in the sticker database using display type. + * @brief Retrieves all group names assigned to stickers with a matching display @a type. * @since_tizen 5.5 * @param[in] consumer_handle The sticker consumer handle * @param[in] type The display type of the sticker for getting sticker data @@ -306,7 +306,7 @@ 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 + * @brief Adds entry 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 diff --git a/include/sticker_data.h b/include/sticker_data.h index e27197c..088c386 100644 --- a/include/sticker_data.h +++ b/include/sticker_data.h @@ -50,7 +50,12 @@ typedef enum { */ typedef enum { STICKER_DATA_DISP_EMOJI = 1, /**< Emoji type */ - STICKER_DATA_DISP_WALLPAPER, /**< Wallpaper type */ + /** + * @brief Wallpaper type + * @details The stickers of the wallpaper type are intended to be used by + * a wallpaper application and usually have larger size. + */ + STICKER_DATA_DISP_WALLPAPER, } sticker_data_display_type_e; /** diff --git a/include/sticker_provider.h b/include/sticker_provider.h index 8271ad7..cdfbac4 100644 --- a/include/sticker_provider.h +++ b/include/sticker_provider.h @@ -98,7 +98,7 @@ int sticker_provider_destroy(sticker_provider_h provider_handle); * @brief Inserts a sticker data to the sticker database. * @since_tizen 5.5 * @remarks All data except thumbnail, description, display_type must be set in the @a data_handle to insert the sticker data. - * If the uri type is #STICKER_DATA_URI_LOCAL_PATH, the sticker file is copied to a sticker directory. + * If the URI type is #STICKER_DATA_URI_LOCAL_PATH, the sticker file is copied to a sticker directory. * It is recommended to delete your sticker file after inserting a sticker data. * @param[in] provider_handle The sticker provider handle * @param[in] data_handle The sticker data handle to be saved @@ -115,15 +115,15 @@ int sticker_provider_destroy(sticker_provider_h provider_handle); int sticker_provider_insert_data(sticker_provider_h provider_handle, sticker_data_h data_handle); /** - * @brief Inserts a sticker data using json file. + * @brief Inserts a sticker data using JSON file. * @details @a json_path must be a relative path like '/data/message_sticker.json'. * @since_tizen 5.5 - * @remarks All data except thumbnail, description, display_type must be set in the json file to insert the sticker data. + * @remarks All data except thumbnail, description, display_type must be set in the JSON file to insert the sticker data. * @a json_path must have a non-null value and must be an existing file. If not, the error as invalid parameter will be returned. - * If the uri type is #STICKER_DATA_URI_LOCAL_PATH, the sticker file is copied to a sticker directory. + * If the URI type is #STICKER_DATA_URI_LOCAL_PATH, the sticker file is copied to a sticker directory. * It is recommended to delete your sticker files after inserting a sticker data. * @param[in] provider_handle The sticker provider handle - * @param[in] json_path The path of json file containing sticker information to be saved + * @param[in] json_path The path of JSON file containing sticker information to be saved * @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 @@ -135,7 +135,7 @@ int sticker_provider_insert_data(sticker_provider_h provider_handle, sticker_dat * @see sticker_provider_insert_finished_cb() * * @code - //json file format + //JSON file format { "sticker": [ @@ -201,7 +201,8 @@ int sticker_provider_update_data(sticker_provider_h provider_handle, sticker_dat int sticker_provider_delete_data(sticker_provider_h provider_handle, sticker_data_h data_handle); /** - * @brief Deletes a sticker data in the sticker database using URI. + * @brief Deletes a sticker data with the given @a uri from the sticker database. + * @details If the database does not have a sticker that matches the given @a uri, the STICKER_ERROR_NO_SUCH_FILE error is returned. * @since_tizen 5.5 * @param[in] provider_handle The sticker provider handle * @param[in] uri The URI of the sticker data to be deleted -- 2.7.4 From b4afaa38da9381afd44996131a02552ced299628 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Tue, 21 Apr 2020 13:12:40 +0900 Subject: [PATCH 16/16] Update package version to 0.1.36 Change-Id: I7124c7d00b2e329a82344f799ea55d3d0d32874b --- 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 d8a7044..79937e3 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.35 +Version: 0.1.36 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 diff --git a/receiver/tizen-manifest.xml b/receiver/tizen-manifest.xml index 083dee3..f8cea18 100644 --- a/receiver/tizen-manifest.xml +++ b/receiver/tizen-manifest.xml @@ -1,5 +1,5 @@ - + -- 2.7.4