Support to copy thumbnail to RW directory 54/229054/4
authorInHong Han <inhong1.han@samsung.com>
Fri, 27 Mar 2020 09:53:03 +0000 (18:53 +0900)
committerInHong Han <inhong1.han@samsung.com>
Mon, 30 Mar 2020 08:41:34 +0000 (17:41 +0900)
Change-Id: I0a590cbccbca31453898c762baf27309b9980f7c

client/sticker_dbus.c
server/stickerd_data_manager.c
sticker-parser/sticker-parser.c

index 13eef77..633089c 100644 (file)
@@ -718,7 +718,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_
 
     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);
-        ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->thumbnail), &reply, "update_sticker_thumbnail");
+        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");
             goto cleanup;
index 4f0b5b2..fc5492b 100644 (file)
@@ -214,6 +214,7 @@ int stickerd_register_dbus_interface(void)
 
             "        <method name='update_sticker_thumbnail'>"
             "          <arg type='i' name='record_id' direction='in'/>"
+            "          <arg type='s' name='app_id' direction='in'/>"
             "          <arg type='s' name='thumbnail' direction='in'/>"
             "        </method>"
 
@@ -595,6 +596,21 @@ int stickerd_insert_sticker_info(GVariant *parameters, GVariant **reply_body)
         }
     }
 
+    if (sticker_info->thumbnail) {
+        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) {
+                LOGE("failed to copy sticker thumbnail");
+                ret = STICKERD_SERVER_ERROR_FILE_EXISTS;
+                goto cleanup;
+            }
+        } else {
+            LOGE("sticker thumbnail does not exist");
+            ret = STICKERD_SERVER_ERROR_NO_SUCH_FILE;
+            goto cleanup;
+        }
+    }
+
     ret = stickerd_db_insert_sticker_info(&record_id, sticker_info);
     if (ret != STICKERD_SERVER_ERROR_NONE) {
         LOGE("Failed to insert sticker info");
@@ -738,8 +754,15 @@ 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)
-                goto free_memory;
+            if (sticker_info->thumbnail) {
+                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)
+                        goto free_memory;
+                } else {
+                    goto free_memory;
+                }
+            }
 
             sticker_info->description = _get_string_from_object(info_object, "description");
 
@@ -892,6 +915,7 @@ int stickerd_update_sticker_thumbnail(GVariant *parameters, GVariant **reply_bod
 {
     int ret;
     int record_id;
+    char *app_id;
     char *thumbnail;
 
     *reply_body = g_variant_new("()");
@@ -900,7 +924,17 @@ int stickerd_update_sticker_thumbnail(GVariant *parameters, GVariant **reply_bod
         return STICKERD_SERVER_ERROR_OPERATION_FAILED;
     }
 
-    g_variant_get(parameters, "(i&s)", &record_id, &thumbnail);
+    g_variant_get(parameters, "(i&s&s)", &record_id, &app_id, &thumbnail);
+
+    if (_check_file_exist(app_id, thumbnail) == 0) {
+        thumbnail = _convert_sticker_uri(thumbnail, app_id);
+        if (!thumbnail) {
+            LOGE("failed to copy sticker thumbnail");
+            return STICKERD_SERVER_ERROR_FILE_EXISTS;
+        }
+    } else {
+        return STICKERD_SERVER_ERROR_NO_SUCH_FILE;
+    }
 
     ret = stickerd_db_update_sticker_info(record_id, STICKER_DB_STICKER_THUMBNAIL, (void *)thumbnail);
     if (ret != STICKERD_SERVER_ERROR_NONE) {
index 6910d6b..d5a3bd4 100644 (file)
@@ -599,6 +599,9 @@ static int __get_sticker_info_from_json(const char *appid, const char *file_path
                 goto free_memory;
 
             thumbnail = __get_string_from_object(info_object, "thumbnail");
+            if (thumbnail)
+                thumbnail = __convert_sticker_uri(thumbnail, appid, app_path);
+
             description = __get_string_from_object(info_object, "description");
             int disp_type = __get_int_from_object(info_object, "display_type");