Support the event callback to send sticker DB changes
[platform/core/uifw/capi-ui-sticker.git] / client / sticker_dbus.c
index 64434b4..412a143 100644 (file)
 #endif
 #define LOG_TAG "STICKER_DBUS"
 
+#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)
 {
     LOGD("name : %s, name_owner : %s", name, name_owner);
 }
 
+//LCOV_EXCL_START
 static void _server_vanished_cb(GDBusConnection *connection, const gchar *name, gpointer user_data)
 {
     LOGD("name : %s", name);
 }
+//LCOV_EXCL_STOP
 
-static int _dbus_init(GDBusConnection **gdbus_connection, guint *server_watcher_id)
+static int _dbus_init(GDBusConnection **gdbus_connection)
 {
     GError *error = NULL;
+    int watch_id = 0;
 
     if (*gdbus_connection == NULL) {
         GDBusConnection *conn = NULL;
@@ -53,17 +59,15 @@ static int _dbus_init(GDBusConnection **gdbus_connection, guint *server_watcher_
     }
 
     LOGD("Connected bus name : %s", g_dbus_connection_get_unique_name(*gdbus_connection));
-    if (*server_watcher_id == 0) {
-        *server_watcher_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
-                            STICKER_DBUS_NAME,
-                            G_BUS_NAME_WATCHER_FLAGS_NONE,
-                            _server_appeared_cb,
-                            _server_vanished_cb,
-                            NULL, NULL);
-    }
+    watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
+                STICKER_DBUS_NAME,
+                G_BUS_NAME_WATCHER_FLAGS_NONE,
+                _server_appeared_cb,
+                _server_vanished_cb,
+                NULL, NULL);
 
-    LOGD("server_watcher_id : %d", *server_watcher_id);
-    if (*server_watcher_id == 0) {
+    LOGD("watch_id : %d", watch_id);
+    if (watch_id == 0) {
         LOGE("Failed to get identifier");
         return STICKER_CLIENT_ERROR_IO_ERROR;
     }
@@ -71,18 +75,14 @@ static int _dbus_init(GDBusConnection **gdbus_connection, guint *server_watcher_
     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;
     }
 
@@ -109,6 +109,9 @@ static void _get_sticker_info_from_gvariant(GVariant *body, sticker_data_h stick
             case STICKER_DATA_TYPE_DATE:
             sticker_data->date = g_variant_dup_string(value, NULL);
             break;
+            case STICKER_DATA_TYPE_DISP_TYPE:
+            sticker_data->disp_type = g_variant_get_int32(value);
+            break;
             default:
             break;
         }
@@ -178,6 +181,7 @@ static void _call_insert_finished_cb(sticker_provider_h provider_handle, GVarian
     }
 }
 
+//LCOV_EXCL_START
 static void _handle_sticker_consumer_cb(GDBusConnection *connection,
                                const gchar *sender_name,
                                const gchar *object_path,
@@ -199,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)
@@ -229,7 +256,7 @@ static void _handle_sticker_consumer_cb(GDBusConnection *connection,
             consumer_handle->data_foreach_by_keyword_cb(sticker_data, consumer_handle->data_foreach_by_keyword_cb_user_data);
         else
             LOGW("No registered callback function");
-    } else if (g_strcmp0(signal_name, "send_sticker_info_by_goup") == 0) {
+    } else if (g_strcmp0(signal_name, "send_sticker_info_by_group") == 0) {
         if (consumer_handle->data_foreach_by_group_cb != NULL)
             consumer_handle->data_foreach_by_group_cb(sticker_data, consumer_handle->data_foreach_by_group_cb_user_data);
         else
@@ -244,6 +271,7 @@ static void _handle_sticker_consumer_cb(GDBusConnection *connection,
     _free_sticker_data(sticker_data);
     #endif
 }
+//LCOV_EXCL_STOP
 
 static void _handle_sticker_provider_cb(GDBusConnection *connection,
                                const gchar *sender_name,
@@ -409,70 +437,53 @@ static int _send_sync_message(GDBusConnection *gdbus_connection, GVariant *body,
     return ret;
 }
 
-static void _gdbus_reply_message_async_cb(GDBusConnection *connection, GAsyncResult *res, gpointer user_data)
-{
-    GDBusMessage *reply = NULL;
-    GError *err = NULL;
-
-    reply = g_dbus_connection_send_message_with_reply_finish(connection, res, &err);
-
-    if (reply) {
-        if (g_dbus_message_to_gerror(reply, &err)) {
-            LOGE("error message = %s, code = %d", err->message, err->code);
-            g_error_free(err);
-            return;
-        }
-    } else {
-        LOGE("There is no reply");
-        return;
-    }
-
-    if (reply)
-        g_object_unref(reply);
-
-    LOGD("Reply message was received");
-    return;
-}
-
 static int _send_async_message(GDBusConnection *gdbus_connection, GVariant *body, char *cmd)
 {
     int ret = STICKER_CLIENT_ERROR_NONE;
     GDBusMessage *msg = NULL;
+    GError *err = NULL;
 
     msg = _get_gbus_message(body, cmd);
     if (msg == NULL)
         return STICKER_CLIENT_ERROR_IO_ERROR;
 
-    g_dbus_connection_send_message_with_reply(
-        gdbus_connection,
-        msg,
-        G_DBUS_SEND_MESSAGE_FLAGS_NONE,
-        -1,
-        NULL,
-        NULL,
-        (GAsyncReadyCallback)_gdbus_reply_message_async_cb,
-        NULL);
+    g_dbus_connection_send_message(gdbus_connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &err);
 
     if (msg)
         g_object_unref(msg);
 
+    if (err != NULL) {
+        ret = STICKER_CLIENT_ERROR_SERVICE_NOT_READY;
+        LOGE("Error occurred when sending message(%s) : %s", cmd, err->message);
+
+        if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
+            ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
+
+        g_error_free(err);
+        return ret;
+    }
+
     return ret;
 }
 
-static int _monitor_register(GDBusConnection *gdbus_connection)
+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");
-    if (reply)
-        g_object_unref(reply);
-
+    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;
     }
 
+    reply_body = g_dbus_message_get_body(reply);
+    g_variant_get(reply_body, "(i)", server_watcher_id);
+
+    if (reply)
+        g_object_unref(reply);
+
     is_server_started = 1;
     return ret;
 }
@@ -482,23 +493,28 @@ static void _on_name_appeared(GDBusConnection *connection,
         const gchar     *name_owner,
         gpointer         user_data)
 {
-    if (is_server_started == 0)
-        _monitor_register(connection);
+    if (is_server_started == 0) {
+        int *watcher_id = (int *)user_data;
+        _monitor_register(connection, watcher_id, last_req_lib);
+    }
 }
 
+//LCOV_EXCL_START
 static void _on_name_vanished(GDBusConnection *connection,
         const gchar     *name,
         gpointer         user_data)
 {
     is_server_started = 0;
 }
+//LCOV_EXCL_STOP
 
-int sticker_dbus_init(GDBusConnection **gdbus_connection, guint *server_watcher_id,
+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, server_watcher_id);
+    ret = _dbus_init(gdbus_connection);
     if (ret != STICKER_CLIENT_ERROR_NONE) {
         LOGE("_dbus_init() failed : %d", ret);
         return ret;
@@ -510,7 +526,7 @@ int sticker_dbus_init(GDBusConnection **gdbus_connection, guint *server_watcher_
         return ret;
     }
 
-    ret = _monitor_register(*gdbus_connection);
+    ret = _monitor_register(*gdbus_connection, server_watcher_id, lib);
     if (ret != STICKER_CLIENT_ERROR_NONE) {
         LOGE("_monitor_register() failed : %d", ret);
         return ret;
@@ -523,7 +539,7 @@ int sticker_dbus_init(GDBusConnection **gdbus_connection, guint *server_watcher_
                 G_BUS_NAME_WATCHER_FLAGS_NONE,
                 _on_name_appeared,
                 _on_name_vanished,
-                NULL,
+                server_watcher_id,
                 NULL);
         if (*server_monitor_id == 0) {
             g_dbus_connection_signal_unsubscribe(*gdbus_connection, *monitor_id);
@@ -536,8 +552,20 @@ int sticker_dbus_init(GDBusConnection **gdbus_connection, guint *server_watcher_
     return STICKER_CLIENT_ERROR_NONE;
 }
 
-int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, 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("(ii)", (int)lib, *server_watcher_id), "sticker_service_unregister");
+        if (ret != STICKER_CLIENT_ERROR_NONE) {
+            LOGE("Failed to unregister sticker service");
+            return ret;
+        }
+
+        *server_watcher_id = 0;
+    }
+
     if (*server_monitor_id) {
         g_bus_unwatch_name(*server_monitor_id);
         *server_monitor_id = 0;
@@ -558,7 +586,7 @@ static void _set_keyword_builder(char *keyword, GVariantBuilder *keyword_builder
         return;
     }
 
-    g_variant_builder_add(keyword_builder, "(s)", strdup((const char *)keyword));
+    g_variant_builder_add(keyword_builder, "(s)", (const char *)keyword);
 }
 
 int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data)
@@ -566,7 +594,6 @@ int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_
     int ret;
     int ret_id = -1;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
     GVariantBuilder *info_builder;
     GVariantBuilder *keyword_builder;
@@ -583,16 +610,12 @@ int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_
     if (sticker_data->description)
         g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DESCRIPTION, g_variant_new_string((const gchar *)sticker_data->description));
     g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_GROUP, g_variant_new_string((const gchar *)sticker_data->group));
+    g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DISP_TYPE, g_variant_new_int32(sticker_data->disp_type));
 
     keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
     g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
 
-    body = g_variant_new("(a{iv}a(s))", info_builder, keyword_builder);
-
-    g_variant_builder_unref(info_builder);
-    g_variant_builder_unref(keyword_builder);
-
-    ret = _send_sync_message(gdbus_connection, body, &reply, "insert_sticker_info");
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(a{iv}a(s))", info_builder, keyword_builder), &reply, "insert_sticker_info");
     if (ret != STICKER_CLIENT_ERROR_NONE) {
         LOGW("Failed to save sticker info");
         return ret;
@@ -603,8 +626,9 @@ int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_
     sticker_data->sticker_info_id = ret_id;
 
     LOGD("ret_id : %d", ret_id);
-    if (body)
-        g_variant_unref(body);
+
+    g_variant_builder_unref(info_builder);
+    g_variant_builder_unref(keyword_builder);
 
     if (reply_body)
         g_variant_unref(reply_body);
@@ -618,16 +642,11 @@ int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_
 int sticker_dbus_insert_sticker_info_by_json(GDBusConnection *gdbus_connection, const char *app_id, const char *json_path)
 {
     int ret;
-    GVariant *body = NULL;
 
-    body = g_variant_new("(ss)", app_id, json_path);
-    ret = _send_async_message(gdbus_connection, body, "update_sticker_info_by_json");
+    ret = _send_async_message(gdbus_connection, g_variant_new("(ss)", app_id, json_path), "update_sticker_info_by_json");
     if (ret != STICKER_CLIENT_ERROR_NONE)
         LOGE("failed to send json path");
 
-    if (body)
-        g_variant_unref(body);
-
     return ret;
 }
 
@@ -635,15 +654,25 @@ int sticker_dbus_delete_sticker_info(GDBusConnection *gdbus_connection, int reco
 {
     int ret;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
 
-    body = g_variant_new("(i)", record_id);
-    ret = _send_sync_message(gdbus_connection, body, &reply, "delete_sticker_info");
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "delete_sticker_info");
     if (ret != STICKER_CLIENT_ERROR_NONE)
         LOGE("failed to delete sticker info");
 
-    if (body)
-        g_variant_unref(body);
+    if (reply)
+        g_object_unref(reply);
+
+    return ret;
+}
+
+int sticker_dbus_delete_sticker_info_by_uri(GDBusConnection *gdbus_connection, const char *uri)
+{
+    int ret;
+    GDBusMessage *reply = NULL;
+
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "delete_sticker_info_by_uri");
+    if (ret != STICKER_CLIENT_ERROR_NONE)
+        LOGE("failed to delete sticker info");
 
     if (reply)
         g_object_unref(reply);
@@ -654,8 +683,8 @@ int sticker_dbus_delete_sticker_info(GDBusConnection *gdbus_connection, int reco
 int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data)
 {
     int ret;
+    bool is_updated = false;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
     sticker_data_h origin_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
 
@@ -664,82 +693,148 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_
         return STICKER_CLIENT_ERROR_OUT_OF_MEMORY;
     }
 
-    body = g_variant_new("(i)", sticker_data->sticker_info_id);
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_sticker_info");
-
+    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);
         if (reply)
             g_object_unref(reply);
-        if (body)
-            g_variant_unref(body);
         return ret;
     }
 
-    if (sticker_data->type != 0 && sticker_data->type != origin_data->type) {
-        LOGD("origin_type : %d, new_type : %d", origin_data->type, sticker_data->type);
-        g_variant_unref(body);
-        body = g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->type);
-        ret = _send_sync_message(gdbus_connection, body, &reply, "update_sticker_type");
-        if (ret != STICKER_CLIENT_ERROR_NONE)
-            LOGE("falied to update sticker type");
+    if (sticker_data->uri) {
+        int len;
+        char *conv_path = NULL;
+        if (sticker_data->type == STICKER_DATA_URI_LOCAL_PATH) {
+            len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->uri) + 2;
+            conv_path = (char *)calloc(len, sizeof(char));
+            if (conv_path)
+                snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->uri);
+        } else
+            conv_path = strdup(sticker_data->uri);
+
+        if (conv_path && (strcmp(conv_path, origin_data->uri) != 0)) {
+            LOGD("origin_uri : %s, new_uri : %s", origin_data->uri, conv_path);
+            int is_exist = 0;
+            ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", sticker_data->uri), &reply, "check_file_exists");
+            if (ret == STICKER_CLIENT_ERROR_NONE) {
+                reply_body = g_dbus_message_get_body(reply);
+                g_variant_get(reply_body, "(i)", &is_exist);
+
+                if (is_exist) {
+                    LOGE("file already exists");
+                    ret = STICKER_CLIENT_ERROR_FILE_EXISTS;
+                    free(conv_path);
+                    goto cleanup;
+                }
+            } else {
+                LOGE("failed to check file exists");
+                free(conv_path);
+                goto cleanup;
+            }
+
+            ret = _send_sync_message(gdbus_connection, g_variant_new("(isis)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->type, sticker_data->uri), &reply, "update_sticker_uri");
+            if (ret != STICKER_CLIENT_ERROR_NONE) {
+                LOGE("failed to update sticker uri");
+                free(conv_path);
+                goto cleanup;
+            }
+            is_updated = true;
+        }
+        free(conv_path);
     }
 
-    if (sticker_data->uri && strcmp(sticker_data->uri, origin_data->uri) != 0) {
-        LOGD("origin_uri : %s, new_uri : %s", origin_data->uri, sticker_data->uri);
-        g_variant_unref(body);
-        body = g_variant_new("(isis)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->type, sticker_data->uri);
-        ret = _send_sync_message(gdbus_connection, body, &reply, "update_sticker_uri");
-        if (ret != STICKER_CLIENT_ERROR_NONE)
-            LOGE("falied to update sticker uri");
+    if (sticker_data->type != 0 && sticker_data->type != origin_data->type) {
+        LOGD("origin_type : %d, new_type : %d", origin_data->type, sticker_data->type);
+        ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->type), &reply, "update_sticker_type");
+        if (ret != STICKER_CLIENT_ERROR_NONE) {
+            LOGE("failed to update sticker type");
+            goto cleanup;
+        }
+        is_updated = true;
     }
 
-    if (sticker_data->thumbnail && strcmp(sticker_data->thumbnail, origin_data->thumbnail) != 0) {
-        LOGD("origin_thumbnail : %s, new_thumbnail : %s", origin_data->thumbnail, sticker_data->thumbnail);
-        g_variant_unref(body);
-        body = g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->thumbnail);
-        ret = _send_sync_message(gdbus_connection, body, &reply, "update_sticker_thumbnail");
-        if (ret != STICKER_CLIENT_ERROR_NONE)
-            LOGE("falied to update sticker thumbnail");
+    if (sticker_data->thumbnail) {
+        int len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->thumbnail) + 2;
+        char *conv_path = (char *)calloc(len, sizeof(char));
+        if (conv_path) {
+            snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->thumbnail);
+            if (strcmp(conv_path, origin_data->thumbnail) != 0)
+            {
+                LOGD("origin_thumbnail : %s, new_thumbnail : %s", origin_data->thumbnail, conv_path);
+                ret = _send_sync_message(gdbus_connection, g_variant_new("(iss)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->thumbnail), &reply, "update_sticker_thumbnail");
+                if (ret != STICKER_CLIENT_ERROR_NONE)
+                {
+                    LOGE("failed to update sticker thumbnail");
+                    free(conv_path);
+                    goto cleanup;
+                }
+                is_updated = true;
+            }
+            free(conv_path);
+        }
     }
 
     if (sticker_data->description && strcmp(sticker_data->description, origin_data->description) != 0) {
         LOGD("origin_description : %s, new_description : %s", origin_data->description, sticker_data->description);
-        g_variant_unref(body);
-        body = g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->description);
-        ret = _send_sync_message(gdbus_connection, body, &reply, "update_sticker_description");
-        if (ret != STICKER_CLIENT_ERROR_NONE)
-            LOGE("falied to update sticker description");
+        ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->description), &reply, "update_sticker_description");
+        if (ret != STICKER_CLIENT_ERROR_NONE) {
+            LOGE("failed to update sticker description");
+            goto cleanup;
+        }
+        is_updated = true;
     }
 
     if (sticker_data->group && strcmp(sticker_data->group, origin_data->group) != 0) {
         LOGD("origin_group : %s, new_group : %s", origin_data->group, sticker_data->group);
-        g_variant_unref(body);
-        body = g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->group);
-        ret = _send_sync_message(gdbus_connection, body, &reply, "update_sticker_group");
-        if (ret != STICKER_CLIENT_ERROR_NONE)
-            LOGE("falied to update sticker group");
+        ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->group), &reply, "update_sticker_group");
+        if (ret != STICKER_CLIENT_ERROR_NONE) {
+            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) {
+        LOGD("origin_disp_type : %d, new_disp_type : %d", origin_data->disp_type, sticker_data->disp_type);
+        ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->disp_type), &reply, "update_sticker_disp_type");
+        if (ret != STICKER_CLIENT_ERROR_NONE) {
+            LOGE("failed to update sticker display type");
+            goto cleanup;
+        }
+        is_updated = true;
     }
 
     if (sticker_data->keyword) {
         GVariantBuilder *keyword_builder;
-        g_variant_unref(body);
         keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
         g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
-        body = g_variant_new("(ia(s))", sticker_data->sticker_info_id, keyword_builder);
-        ret = _send_sync_message(gdbus_connection, body, &reply, "update_sticker_keyword");
+        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("falied to update sticker keyword");
+            LOGE("failed to update sticker keyword");
+        else
+            is_updated = true;
+        g_variant_builder_unref(keyword_builder);
     }
 
-    _free_sticker_data(origin_data);
+    if (is_updated)
+        ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "send_update_event");
 
-    if (body)
-        g_variant_unref(body);
+cleanup:
+    _free_sticker_data(origin_data);
 
     if (reply_body)
         g_variant_unref(reply_body);
@@ -754,23 +849,27 @@ int sticker_dbus_get_sticker_info_by_record_id(GDBusConnection *gdbus_connection
 {
     int ret;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
+    GVariantIter *info_iter = NULL;
+    GVariantIter *keyword_iter = NULL;
 
-    body = g_variant_new("(i)", record_id);
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_sticker_info");
-
+    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 (body)
-        g_variant_unref(body);
+        if (info_iter)
+            g_variant_iter_free(info_iter);
+
+        if (keyword_iter)
+            g_variant_iter_free(keyword_iter);
+    }
 
     if (reply)
         g_object_unref(reply);
@@ -778,12 +877,11 @@ int sticker_dbus_get_sticker_info_by_record_id(GDBusConnection *gdbus_connection
     return ret;
 }
 
-int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, GList **group_list)
+int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, const char *app_id, GList **group_list)
 {
     int ret;
     GDBusMessage *reply = NULL;
     GVariantIter *iter = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
     char *group = NULL;
 
@@ -792,15 +890,13 @@ int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, GList **group
         return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
     }
 
-    body = g_variant_new("()");
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_group_list");
-
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_group_list");
     if (ret == STICKER_CLIENT_ERROR_NONE) {
         reply_body = g_dbus_message_get_body(reply);
         g_variant_get(reply_body, "(a(s))", &iter);
 
         if (!iter) {
-            LOGD("falied to get iter");
+            LOGD("failed to get iter");
             return STICKER_CLIENT_ERROR_OPERATION_FAILED;
         }
 
@@ -811,9 +907,6 @@ int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, GList **group
         g_variant_iter_free(iter);
     }
 
-    if (body)
-        g_variant_unref(body);
-
     if (reply_body)
         g_variant_unref(reply_body);
 
@@ -823,12 +916,11 @@ int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, GList **group
     return ret;
 }
 
-int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, GList **keyword_list)
+int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, const char *app_id, GList **keyword_list)
 {
     int ret;
     GDBusMessage *reply = NULL;
     GVariantIter *iter = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
     char *keyword = NULL;
 
@@ -837,15 +929,13 @@ int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, GList **key
         return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
     }
 
-    body = g_variant_new("()");
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_keyword_list");
-
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_keyword_list");
     if (ret == STICKER_CLIENT_ERROR_NONE) {
         reply_body = g_dbus_message_get_body(reply);
         g_variant_get(reply_body, "(a(s))", &iter);
 
         if (!iter) {
-            LOGD("falied to get iter");
+            LOGD("failed to get iter");
             return STICKER_CLIENT_ERROR_OPERATION_FAILED;
         }
 
@@ -856,9 +946,6 @@ int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, GList **key
         g_variant_iter_free(iter);
     }
 
-    if (body)
-        g_variant_unref(body);
-
     if (reply_body)
         g_variant_unref(reply_body);
 
@@ -872,20 +959,14 @@ int sticker_dbus_get_sticker_count(GDBusConnection *gdbus_connection, const char
 {
     int ret;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
 
-    body = g_variant_new("(s)", app_id);
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_sticker_count");
-
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_sticker_count");
     if (ret == STICKER_CLIENT_ERROR_NONE) {
         reply_body = g_dbus_message_get_body(reply);
         g_variant_get(reply_body, "(i)", count);
     }
 
-    if (body)
-        g_variant_unref(body);
-
     if (reply_body)
         g_variant_unref(reply_body);
 
@@ -895,23 +976,18 @@ int sticker_dbus_get_sticker_count(GDBusConnection *gdbus_connection, const char
     return ret;
 }
 
-int sticker_dbus_get_all_sticker_info(GDBusConnection *gdbus_connection, int offset, int count, GVariantIter **id_iter)
+int sticker_dbus_get_all_sticker_info(GDBusConnection *gdbus_connection, const char *app_id, int offset, int count, GVariantIter **id_iter)
 {
     int ret;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
 
-    body = g_variant_new("(ii)", offset, count);
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_all_sticker_info");
+    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 (body)
-        g_variant_unref(body);
-
     if (reply_body)
         g_variant_unref(reply_body);
 
@@ -925,18 +1001,34 @@ int sticker_dbus_get_sticker_info_by_appid(GDBusConnection *gdbus_connection, co
 {
     int ret;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
 
-    body = g_variant_new("(sii)", app_id, offset, count);
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_sticker_info_by_appid");
+    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 (body)
-        g_variant_unref(body);
+    if (reply_body)
+        g_variant_unref(reply_body);
+
+    if (reply)
+        g_object_unref(reply);
+
+    return ret;
+}
+
+int sticker_dbus_get_sticker_info_by_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_uri_type_e type, int offset, int count, GVariantIter **id_iter)
+{
+    int ret;
+    GDBusMessage *reply = NULL;
+    GVariant *reply_body = NULL;
+
+    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);
+    }
 
     if (reply_body)
         g_variant_unref(reply_body);
@@ -947,22 +1039,38 @@ int sticker_dbus_get_sticker_info_by_appid(GDBusConnection *gdbus_connection, co
     return ret;
 }
 
-int sticker_dbus_get_sticker_info_by_type(GDBusConnection *gdbus_connection, sticker_data_uri_type_e type, int offset, int count, GVariantIter **id_iter)
+int sticker_dbus_get_sticker_info_by_group(GDBusConnection *gdbus_connection, const char *app_id, const char *group, int offset, int count, GVariantIter **id_iter)
 {
     int ret;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
 
-    body = g_variant_new("(iii)", (int)type, offset, count);
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_sticker_info_by_type");
+    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 (body)
-        g_variant_unref(body);
+    if (reply_body)
+        g_variant_unref(reply_body);
+
+    if (reply)
+        g_object_unref(reply);
+
+    return ret;
+}
+
+int sticker_dbus_get_sticker_info_by_keyword(GDBusConnection *gdbus_connection, const char *app_id, const char *keyword, int offset, int count, GVariantIter **id_iter)
+{
+    int ret;
+    GDBusMessage *reply = NULL;
+    GVariant *reply_body = NULL;
+
+    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);
+    }
 
     if (reply_body)
         g_variant_unref(reply_body);
@@ -973,22 +1081,56 @@ int sticker_dbus_get_sticker_info_by_type(GDBusConnection *gdbus_connection, sti
     return ret;
 }
 
-int sticker_dbus_get_sticker_info_by_group(GDBusConnection *gdbus_connection, const char *group, int offset, int count, GVariantIter **id_iter)
+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 ret;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
 
-    body = g_variant_new("(sii)", group, offset, count);
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_sticker_info_by_group");
+    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 (body)
-        g_variant_unref(body);
+    if (reply_body)
+        g_variant_unref(reply_body);
+
+    if (reply)
+        g_object_unref(reply);
+
+    return ret;
+}
+
+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 ret;
+    GDBusMessage *reply = NULL;
+    GVariantIter *iter = NULL;
+    GVariant *reply_body = NULL;
+    char *group = NULL;
+
+    if (group_list == NULL) {
+        LOGE("group_list is invalid");
+        return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
+    }
+
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(si)", app_id, (int)type), &reply, "get_group_list_by_disp_type");
+    if (ret == STICKER_CLIENT_ERROR_NONE) {
+        reply_body = g_dbus_message_get_body(reply);
+        g_variant_get(reply_body, "(a(s))", &iter);
+
+        if (!iter) {
+            LOGD("failed to get iter");
+            return STICKER_CLIENT_ERROR_OPERATION_FAILED;
+        }
+
+        while (g_variant_iter_loop (iter, "(s)", &group)) {
+            *group_list = g_list_append(*group_list, strdup((const char *)group));
+        }
+
+        g_variant_iter_free(iter);
+    }
 
     if (reply_body)
         g_variant_unref(reply_body);
@@ -999,22 +1141,53 @@ int sticker_dbus_get_sticker_info_by_group(GDBusConnection *gdbus_connection, co
     return ret;
 }
 
-int sticker_dbus_get_sticker_info_by_keyword(GDBusConnection *gdbus_connection, const char *keyword, int offset, int count, GVariantIter **id_iter)
+int sticker_dbus_check_file_exists(GDBusConnection *gdbus_connection, const char *uri, int *result)
 {
     int ret;
     GDBusMessage *reply = NULL;
-    GVariant *body = NULL;
     GVariant *reply_body = NULL;
 
-    body = g_variant_new("(sii)", keyword, offset, count);
-    ret = _send_sync_message(gdbus_connection, body, &reply, "get_sticker_info_by_keyword");
+    ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "check_file_exists");
     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, "(i)", result);
     }
 
-    if (body)
-        g_variant_unref(body);
+    if (reply_body)
+        g_variant_unref(reply_body);
+
+    if (reply)
+        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);