Fix the issue sometimes provider_handle sometimes does not create when removing stickers 69/234869/4
authorInHong Han <inhong1.han@samsung.com>
Fri, 29 May 2020 09:14:44 +0000 (18:14 +0900)
committerInHong Han <inhong1.han@samsung.com>
Fri, 29 May 2020 09:59:51 +0000 (18:59 +0900)
Change-Id: I38710cb7146439fa20c767fbddb05badebed054d

receiver/inc/sticker_info.h
receiver/src/ft.cpp
receiver/src/main.cpp
receiver/src/sticker_info.cpp

index b45eae5..bad7dc3 100644 (file)
@@ -18,7 +18,7 @@
 #define __STICKER_INFO_H__
 
 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 create_sticker_provider_handle(void);
 void destroy_sticker_provider_handle(void);
 void delete_sticker_data(const char *fileName);
 void delete_all_stickers(const char *groupName);
index 32aa136..ebf7e92 100644 (file)
@@ -210,33 +210,30 @@ static void _on_transfer_completed(sap_file_transaction_h file_transaction,
         }
         else {
             LOGI("Succeed to change permission : %s", sticker_data.file_path.c_str());
-            if (create_sticker_provider_handle() == STICKER_ERROR_NONE) {
-                char thumb_path[PATH_MAX];
-                char *data_path = NULL;
-                data_path = app_get_shared_data_path();
-                snprintf(thumb_path, sizeof(thumb_path), "%s/thumbnail/%s", data_path, incoming_file_name.c_str());
-                sticker_data.thumbnail_path = string(thumb_path);
-
-                if (data_path)
-                    free(data_path);
-
-                int ret = thumbnail_util_extract_to_file(sticker_data.file_path.c_str(), THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, sticker_data.thumbnail_path.c_str());
-                if (ret != THUMBNAIL_UTIL_ERROR_NONE) {
-                    LOGE("Failed to create thumbnail. msg : %s", get_error_message(ret));
-                    sticker_data.thumbnail_path.clear();
-                }
+            char thumb_path[PATH_MAX];
+            char *data_path = NULL;
+            data_path = app_get_shared_data_path();
+            snprintf(thumb_path, sizeof(thumb_path), "%s/thumbnail/%s", data_path, incoming_file_name.c_str());
+            sticker_data.thumbnail_path = string(thumb_path);
+
+            if (data_path)
+                free(data_path);
+
+            int ret = thumbnail_util_extract_to_file(sticker_data.file_path.c_str(), THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, sticker_data.thumbnail_path.c_str());
+            if (ret != THUMBNAIL_UTIL_ERROR_NONE) {
+                LOGE("Failed to create thumbnail. msg : %s", get_error_message(ret));
+                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(), sticker_data.disp_type.c_str());
-                destroy_sticker_provider_handle();
+            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());
 
-                if (unlink(sticker_data.file_path.c_str()) == -1)
-                    LOGE("Failed to remove sticker file");
+            if (unlink(sticker_data.file_path.c_str()) == -1)
+                LOGE("Failed to remove sticker file");
 
-                if (!sticker_data.thumbnail_path.empty()) {
-                    if (unlink(sticker_data.thumbnail_path.c_str()) == -1)
-                        LOGE("Failed to remove sticker thumbnail");
-                }
+            if (!sticker_data.thumbnail_path.empty()) {
+                if (unlink(sticker_data.thumbnail_path.c_str()) == -1)
+                    LOGE("Failed to remove sticker thumbnail");
             }
         }
 
@@ -773,24 +770,15 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in
             send_sync_start_response(result_code);
             if (current_request.category == string("bitmoji")) {
                 LOGD("Delete all bitmoji stickers");
-                if (create_sticker_provider_handle() == STICKER_ERROR_NONE) {
-                    delete_all_stickers("bitmoji");
-                    destroy_sticker_provider_handle();
-                }
+                delete_all_stickers("bitmoji");
             }
         } else {
             if (result_code == SYNC_START_RSP_BITMOJI_ALL_DELETE) {
                 LOGD("Delete all bitmoji stickers");
-                if (create_sticker_provider_handle() == STICKER_ERROR_NONE) {
-                    delete_all_stickers("bitmoji");
-                    destroy_sticker_provider_handle();
-                }
+                delete_all_stickers("bitmoji");
             } else if (result_code == SYNC_START_RSP_AREMOJI_ALL_DELETE) {
                 LOGD("Delete all AR Emoji stickers");
-                if (create_sticker_provider_handle() == STICKER_ERROR_NONE) {
-                    delete_all_stickers("arsticker");
-                    destroy_sticker_provider_handle();
-                }
+                delete_all_stickers("arsticker");
             }
 
             if (!process_request_queue()) {
@@ -854,10 +842,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in
                     snprintf(del_path, sizeof(del_path), "%s/%s%s",STICKER_DIRECTORY, app_id, file_path);
 
                     LOGD("Delete file : %s, len : %d", del_path, file_len);
-                    if (create_sticker_provider_handle() == STICKER_ERROR_NONE) {
-                        delete_sticker_data(del_path);
-                        destroy_sticker_provider_handle();
-                    }
+                    delete_sticker_data(del_path);
 
                     if (app_id)
                         free(app_id);
index 34b9837..dc105d0 100644 (file)
@@ -29,6 +29,7 @@
 #include "log.h"
 #include "config.h"
 #include "receiver_preference.h"
+#include "sticker_info.h"
 
 using namespace std;
 
@@ -55,6 +56,8 @@ static bool app_create(void *data)
         }
     }
 
+    create_sticker_provider_handle();
+
     return true;
 }
 
@@ -241,6 +244,7 @@ static void app_terminate(void *data)
 {
     /* Release all resources. */
     LOGD("");
+    destroy_sticker_provider_handle();
     deinitialize_sap();
 }
 
index afe989b..650d880 100644 (file)
@@ -118,16 +118,14 @@ insert_sticker_data(const char *filepath, const char *keyword, const char *group
     }
 }
 
-int create_sticker_provider_handle(void)
+void create_sticker_provider_handle(void)
 {
     int ret;
     ret = sticker_provider_create(&sticker_provider);
     if (ret != STICKER_ERROR_NONE) {
         /* Error handling */
-        LOGE("Failed to create sticker provider");
+        LOGE("Failed to create sticker provider. ret : %d", ret);
     }
-
-    return ret;
 }
 
 void destroy_sticker_provider_handle(void)