Merge branch 'tizen_5.5' into tizen 71/227971/1 accepted/tizen/unified/20200318.130456 submit/tizen/20200318.023532
authorJihoon Kim <jihoon48.kim@samsung.com>
Wed, 18 Mar 2020 00:25:18 +0000 (09:25 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Wed, 18 Mar 2020 00:25:35 +0000 (09:25 +0900)
Change-Id: Ia3f50a16c8a994b304956c58225d0665693783d6

13 files changed:
packaging/capi-ui-sticker.spec
receiver/CMakeLists.txt
receiver/inc/ft.h
receiver/inc/log.h
receiver/inc/main.h
receiver/inc/sticker_info.h
receiver/inc/sync_alarm.h [new file with mode: 0644]
receiver/src/ft.cpp
receiver/src/main.cpp
receiver/src/message.cpp
receiver/src/sticker_info.cpp
receiver/src/sync_alarm.cpp [new file with mode: 0644]
receiver/tizen-manifest.xml

index a7c1eac..7ead7b4 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-ui-sticker
 Summary:    Sticker client library and daemon
-Version:    0.1.17
+Version:    0.1.22
 Release:    1
 Group:      Graphics & UI Framework/Input
 License:    Apache-2.0
@@ -28,6 +28,8 @@ BuildRequires:  pkgconfig(sqlite3)
 BuildRequires:  pkgconfig(capi-base-common)
 BuildRequires:  pkgconfig(capi-appfw-service-application)
 BuildRequires:  pkgconfig(capi-message-port)
+BuildRequires:  pkgconfig(capi-appfw-alarm)
+BuildRequires:  pkgconfig(capi-system-device)
 BuildRequires:  pkgconfig(sap-client-stub-api)
 BuildRequires:  pkgconfig(vconf)
 BuildRequires:  hash-signer
index 9cd44fb..73d4503 100644 (file)
@@ -6,6 +6,7 @@ SET(SRCS
        src/ft.cpp
        src/sticker_info.cpp
        src/message.cpp
+       src/sync_alarm.cpp
 )
 
 INCLUDE(FindPkgConfig)
@@ -14,6 +15,9 @@ pkg_check_modules(pkgs_test REQUIRED
     dlog
     capi-appfw-service-application
     capi-message-port
+    capi-appfw-app-common
+    capi-appfw-alarm
+    capi-system-device
     sap-client-stub-api
     json-glib-1.0
     vconf
index 271a98f..a95204c 100644 (file)
@@ -29,7 +29,7 @@ void     accept_file(void);
 gboolean initialize_sap(void);
 void deinitialize_sap(void);
 
-void sap_file_transfer_get_receive_filepath(char **filepath);
 void request_sticker_data(const char *mode, const char *category, const char *type);
+void request_sticker_feature();
 
 #endif /* __FT_H__ */
index 3749cad..07ee738 100644 (file)
@@ -1,3 +1,18 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 #ifndef __debug_H__
 #define __debug_H__
 
index b6fac02..e32a820 100644 (file)
@@ -1,3 +1,18 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 #include <app_common.h>
 #include <dlog.h>
 #include <glib.h>
index 7cf88fe..86b6c88 100644 (file)
@@ -1,8 +1,24 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 #ifndef __STICKER_INFO_H__
 #define __STICKER_INFO_H__
 
 void insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc);
 int create_sticker_provider_handle(void);
 void destroy_sticker_provider_handle(void);
+void delete_sticker_data(const char *fileName);
 
 #endif /* __STICKER_INF_H__ */
diff --git a/receiver/inc/sync_alarm.h b/receiver/inc/sync_alarm.h
new file mode 100644 (file)
index 0000000..e46515c
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <glib.h>
+
+#ifndef __ALARM_H__
+#define __ALARM_H__
+
+#define APP_CONTROL_OPERATION_SYNC_ALARM "http://tizen.org/appcontrol/operation/sticker_sync_alarm"
+#define SYNC_ALARM_DELAY 0
+#define SYNC_ALARM_INTERVAL 12*60*60
+
+bool sync_alarm_register(const char *operation, int delay, int period);
+bool sync_alarm_exist();
+
+#endif /* __ALARM_H__ */
index d1c960f..9d42623 100644 (file)
 #include "log.h"
 #include "sticker_info.h"
 #include "message.h"
+#include "sync_alarm.h"
 
 #define ACCESSORY_SERVICE_PROFILE_ID "/sample/filetransfersender"
 #define ACCESSORY_SERVICE_CHANNEL_ID 107
 
+#define STICKER_SYNC_FEATURE_REQ "sticker-sync-feature-req"
+#define STICKER_SYNC_FEATURE_RSP "sticker-sync-feature-rsp"
 #define STICKER_SYNC_START_REQ "sticker-sync-start-req"
 #define STICKER_SYNC_START_RSP "sticker-sync-start-rsp"
 #define STICKER_SEND_START_REQ "sticker-send-start-req"
 #define STICKER_SEND_STOP_REQ  "sticker-send-stop-req"
 #define STICKER_SEND_STOP_RSP  "sticker-send-stop-rsp"
 
+#ifndef VCONFKEY_STICKER_SUPPORTED_FEATURE
+#define VCONFKEY_STICKER_SUPPORTED_FEATURE  "db/sticker/supported_feature"
+
+enum {
+    VCONFKEY_STICKER_FEATURE_NONE = 0x00,
+    VCONFKEY_STICKER_FEATURE_AREMOJI = 0x01,
+    VCONFKEY_STICKER_FEATURE_BITMOJI = 0x02
+};
+#endif
+
 using namespace std;
 
+typedef enum {
+    REQUEST_TYPE_SYNC,
+    REQUEST_TYPE_FEATURE_REQ
+} request_type;
+
+enum {
+    SYNC_START_RSP_SUCCESS = 1000,
+    SYNC_START_RSP_NO_STICKER = 1001
+};
+
 struct sap_info_s {
     sap_agent_h agent;
     sap_socket_h socket;
@@ -57,7 +80,8 @@ struct sap_info_s {
     sap_file_transaction_h file_socket;
 };
 
-struct sync_request {
+struct request {
+    request_type req_type;
     string mode;
     string category;
     string type;
@@ -80,7 +104,7 @@ struct sticker_info {
 
 static struct sap_info_s priv_data = { 0 };
 static struct sticker_info sticker_data;
-static struct sync_request pending_sync_request;
+static struct request pending_request, current_request;
 
 gboolean file_on_progress = 0;
 static string incoming_file_name;
@@ -142,7 +166,7 @@ static void notify_sync_progress(unsigned int file_progress)
 
     double total_progress = (((double)rec_file_cnt / (double)total_file_count) + (1.0/(double)total_file_count*file_progress/100))*100;
 
-    LOGI("recv : %d, total : %d, file_progress : %d, %u%%", rec_file_cnt, total_file_count, file_progress, (unsigned int)total_progress);
+    LOGI("(%2d / %2d), file progress : %3u%%, total progress : %3u%%", rec_file_cnt, total_file_count, file_progress, (unsigned int)total_progress);
     char progress_str[32];
     snprintf(progress_str, sizeof(progress_str), "%u", (unsigned int)total_progress);
     send_message("sync_progress", progress_str);
@@ -231,7 +255,6 @@ static void _on_sending_file_in_progress(sap_file_transaction_h file_transaction
                                          unsigned short int percentage_progress,
                                          void *user_data)
 {
-    LOGI("# progress %d", percentage_progress);
     notify_sync_progress(percentage_progress);
 }
 
@@ -272,11 +295,6 @@ void accept_file()
     file_on_progress = 1;
 }
 
-void sap_file_transfer_get_receive_filepath(char **filepath)
-{
-    *filepath = strdup(sticker_data.file_path.c_str());
-}
-
 void request_sticker_data(const char *mode, const char *category, const char *type)
 {
     JsonObject *j_object = json_object_new();
@@ -292,12 +310,38 @@ void request_sticker_data(const char *mode, const char *category, const char *ty
     json_object_set_string_member(j_object, "type", type);
 
     if (_send_json_data(j_object) == FALSE) {
-        pending_sync_request.mode = string(mode ? mode : "manual");
-        pending_sync_request.category = string(category? category : "arsticker");
-        pending_sync_request.type = string(type ? type : "input");
+        pending_request.req_type = REQUEST_TYPE_SYNC;
+        pending_request.mode = string(mode ? mode : "manual");
+        pending_request.category = string(category? category : "arsticker");
+        pending_request.type = string(type ? type : "input");
 
         LOGI("Push sync request");
     }
+    else {
+        current_request.req_type = REQUEST_TYPE_SYNC;
+        current_request.mode = string(mode ? mode : "manual");
+        current_request.category = string(category? category : "arsticker");
+        current_request.type = string(type ? type : "input");
+    }
+
+    json_object_unref(j_object);
+}
+
+void request_sticker_feature()
+{
+    JsonObject *j_object = json_object_new();
+    if (j_object == NULL) {
+        LOGE("json object create error");
+        return;
+    }
+
+    json_object_set_string_member(j_object, "msgId", STICKER_SYNC_FEATURE_REQ);
+    json_object_set_int_member(j_object, "tID", ++t_id);
+
+    if (_send_json_data(j_object) == FALSE) {
+        pending_request.req_type = REQUEST_TYPE_FEATURE_REQ;
+        LOGE("Failed to send STICKER_SYNC_FEATURE_REQ");
+    }
 
     json_object_unref(j_object);
 }
@@ -372,7 +416,8 @@ 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) */
 {
-    LOGI("received data: %s, len:%d", (char *)buffer, payload_length);
+    unsigned int buf_len = strlen((char *)buffer);
+    LOGI("received data: %s, len: %d, buffer len : %d", (char *)buffer, payload_length, buf_len);
 
     JsonParser *parser = json_parser_new();
     GError *err_msg = NULL;
@@ -381,7 +426,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in
     string msg_id;
     const char *json_msgid = NULL;
 
-    json_parser_load_from_data(parser, (char *)buffer, -1, &err_msg);
+    json_parser_load_from_data(parser, (char *)buffer, payload_length, &err_msg);
     if (err_msg) {
         LOGE("failed to load json file. error message: %s", err_msg->message);
         goto cleanup;
@@ -401,12 +446,50 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in
 
     json_msgid = json_object_get_string_member(root_obj, "msgId");
     msg_id = string(json_msgid ? json_msgid : "");
-    if (msg_id == STICKER_SYNC_START_RSP) {
+    if (msg_id == STICKER_SYNC_FEATURE_RSP) {
+        LOGD("msg : %s", msg_id.c_str());
+        const char *json_aremoji = json_object_get_string_member(root_obj, "arEmoji");
+        const char *json_bitmoji = json_object_get_string_member(root_obj, "bitmoji");
+        string support_aremoji = string(json_aremoji ? json_aremoji : "");
+        string support_bitmoji = string(json_bitmoji ? json_bitmoji : "");
+        int supported_feature = VCONFKEY_STICKER_FEATURE_NONE;
+
+        if (support_aremoji == "support")
+            supported_feature |= VCONFKEY_STICKER_FEATURE_AREMOJI;
+
+        if (support_bitmoji == "support")
+            supported_feature |= VCONFKEY_STICKER_FEATURE_BITMOJI;
+
+        if (vconf_set_int(VCONFKEY_STICKER_SUPPORTED_FEATURE, supported_feature) == 0)
+            LOGD("Succeed to set supported feature");
+        else
+            LOGW("Fail to set supported feature");
+
+        service_app_exit();
+    } else if (msg_id == STICKER_SYNC_START_RSP) {
         LOGD("msg : %s", msg_id.c_str());
         const char *json_result = json_object_get_string_member(root_obj, "result");
         string result = string(json_result ? json_result : "");
         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());
+
+        if (result_code != SYNC_START_RSP_SUCCESS)
+            service_app_exit();
     } else if (msg_id == STICKER_SEND_START_REQ) {
         LOGD("msg : %s", msg_id.c_str());
         total_file_count = 0;
@@ -419,17 +502,17 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in
                 JsonObject *file_obj = json_array_get_object_element(file_list, i);
                 int file_len = json_object_get_int_member(file_obj, "size");
                 const char *json_filename = json_object_get_string_member(file_obj, "fileName");
-                if (!json_filename) {
-                    json_filename = json_object_get_string_member(file_obj, "filename");
-                }
                 string file_name = string(json_filename ? json_filename : "");
 
                 if (file_len > 0) {
-                    LOGD("fileName : %s, len : %d", file_name.c_str(), file_len);
+                    LOGD("Add file : %s, len : %d", file_name.c_str(), file_len);
                     total_file_count++;
                 } else {
-                    // Delete sticker
-                    LOGD("fileName : %s, len : %d", file_name.c_str(), file_len);
+                    LOGD("Delete file : %s, len : %d", file_name.c_str(), file_len);
+                    if (create_sticker_provider_handle() == STICKER_ERROR_NONE) {
+                        delete_sticker_data(file_name.c_str());
+                        destroy_sticker_provider_handle();
+                    }
                 }
             }
         }
@@ -498,12 +581,25 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in
             }
 
             json_object_set_string_member(j_object, "result", "success");
+
+            if (current_request.mode == string("manual")) {
+                if (!sync_alarm_exist())
+                    sync_alarm_register(APP_CONTROL_OPERATION_SYNC_ALARM, SYNC_ALARM_DELAY, SYNC_ALARM_INTERVAL);
+            }
         }
 
         if (_send_json_data(j_object) == FALSE)
             LOGE("Failed to send message");
 
+        send_message("sync_stop_result", reason.c_str());
+
         json_object_unref(j_object);
+
+        current_request.mode.clear();
+        current_request.category.clear();
+        current_request.type.clear();
+
+        service_app_exit();
     } else
         LOGW("unknown msg id : %s", msg_id.c_str());
 
@@ -576,15 +672,24 @@ _on_service_connection_created(sap_peer_agent_h peer_agent,
         priv->socket = socket;
         LOGI("Connection Established");
 
-        if (!pending_sync_request.mode.empty()) {
-            LOGD("[Request to sync sticker] mode: %s, category: %s, type : %s", pending_sync_request.mode.c_str(),
-                                                                                pending_sync_request.category.c_str(),
-                                                                                pending_sync_request.type.c_str());
+        LOGD("pending_request : %d", pending_request.req_type);
+
+        if (pending_request.req_type == REQUEST_TYPE_FEATURE_REQ) {
+            LOGD("[Request feature exchange]");
+            request_sticker_feature();
+        }
+        else if (pending_request.req_type == REQUEST_TYPE_SYNC) {
+            if (!pending_request.mode.empty()) {
+                LOGD("[Request to sync sticker] mode: %s, category: %s, type : %s", pending_request.mode.c_str(),
+                                                                                    pending_request.category.c_str(),
+                                                                                    pending_request.type.c_str());
+
+                request_sticker_data(pending_request.mode.c_str(), pending_request.category.c_str(), pending_request.type.c_str());
 
-            request_sticker_data(pending_sync_request.mode.c_str(), pending_sync_request.category.c_str(), pending_sync_request.type.c_str());
-            pending_sync_request.mode.clear();
-            pending_sync_request.category.clear();
-            pending_sync_request.type.clear();
+                pending_request.mode.clear();
+                pending_request.category.clear();
+                pending_request.type.clear();
+            }
         }
 
         break;
index 6191a28..9968b91 100644 (file)
@@ -1,10 +1,30 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 #include <app_common.h>
 #include <service_app.h>
 #include <stdlib.h>
+#include <app_alarm.h>
+#include <device/battery.h>
 
 #include "main.h"
 #include "ft.h"
 #include "log.h"
+#include "sync_alarm.h"
+
+#define MINIMUM_BATTERY 15
 
 static bool app_create(void *data)
 {
@@ -23,51 +43,92 @@ static void app_control(app_control_h app_control, void *data)
     /* Handle the launch request. */
     char* request = NULL;
     char* mode = NULL;
-    char* category = NULL;
     char* type = NULL;
+    char* operation = NULL;
+    char* alarm_data = NULL;
 
     int res;
 
-    // sync request
-    res = app_control_get_extra_data(app_control, "request", &request);
-    if (APP_CONTROL_ERROR_NONE == res && NULL != request)
-    {
-        if (strcmp(request, "sync") == 0)
-        {
-            if (app_control_get_extra_data(app_control, "mode", &mode) != APP_CONTROL_ERROR_NONE)
-            {
-                LOGE("No given mode");
+    // operation
+    int ret = app_control_get_operation(app_control, &operation);
+    if (ret == APP_CONTROL_ERROR_NONE) {
+        LOGD("operation: %s", operation);
+
+        if (operation && (strncmp(operation, APP_CONTROL_OPERATION_SYNC_ALARM, strlen(APP_CONTROL_OPERATION_SYNC_ALARM)) == 0)) {
+            ret = app_control_get_extra_data(app_control, APP_CONTROL_DATA_ALARM_ID, &alarm_data);
+            if (ret != APP_CONTROL_ERROR_NONE) {
+                dlog_print(DLOG_ERROR, LOG_TAG, "Function app_control_get_extra_data() failed.");
                 goto cleanup;
             }
 
-            if (app_control_get_extra_data(app_control, "category", &category) != APP_CONTROL_ERROR_NONE)
-            {
-                LOGE("No given category");
-                goto cleanup;
+            LOGD("alarm data : %s", alarm_data);
+
+            int battery_percentage = 0;
+            int ret = device_battery_get_percent(&battery_percentage);
+            if (ret == DEVICE_ERROR_NONE) {
+                LOGD("battery percent : %d", battery_percentage);
+                if (battery_percentage >= MINIMUM_BATTERY) {
+                    request_sticker_data("auto", "arsticker", "input");
+                    request_sticker_data("auto", "bitmoji", "input");
+                }
+                else {
+                    LOGD("No sync request due to insufficient battery");
+                }
             }
+            else {
+               LOGW("Failed to get battery percent. error : %d", ret);
+            }
+
+            goto cleanup;
+        }
+    }
+    else {
+        LOGW("Failed to get operation. error : %d", ret);
+    }
 
-            if (app_control_get_extra_data(app_control, "type", &type) != APP_CONTROL_ERROR_NONE)
-            {
+    // sync request
+    res = app_control_get_extra_data(app_control, "request", &request);
+    if (APP_CONTROL_ERROR_NONE == res && NULL != request) {
+        if (strcmp(request, "sync") == 0) {
+            bool param_error = false;
+            if (app_control_get_extra_data(app_control, "mode", &mode) != APP_CONTROL_ERROR_NONE) {
+                LOGE("No given mode");
+                param_error = true;
+            }
+
+            if (app_control_get_extra_data(app_control, "type", &type) != APP_CONTROL_ERROR_NONE) {
                 LOGE("No given type");
-                goto cleanup;
+                param_error = true;
             }
 
-            LOGI("[sync request] mode : %s, category : %s, type : %s", mode, category, type);
+            LOGI("[sync request] mode : %s, type : %s", mode, type);
+            if (param_error)
+                goto cleanup;
 
-            if (mode && category && type)
-                request_sticker_data(mode, category, type);
+            if (mode && type)
+                request_sticker_data(mode, "arsticker", type);
+        }
+        else if (strcmp(request, "oobe") == 0) {
+            LOGI("[OOBE] register sync alarm");
+            sync_alarm_register(APP_CONTROL_OPERATION_SYNC_ALARM, SYNC_ALARM_DELAY, SYNC_ALARM_INTERVAL);
+            request_sticker_feature();
+        }
+        else
+        {
+            LOGW("Unknown command : %s", request);
         }
     }
+
 cleanup:
+    if (NULL != operation)
+        free(operation);
+
     if (NULL != request)
         free(request);
 
     if (NULL != mode)
         free(mode);
 
-    if (NULL != category)
-        free(category);
-
     if (NULL != type)
         free(type);
 }
index 4513000..f67b29e 100644 (file)
@@ -62,6 +62,8 @@ bool send_message(const char *cmd, const char *data)
     int ret;
     bool found = false;
 
+    LOGD("command: %s, data: %s", cmd, data);
+
     message_port_check_remote_port(REMOTE_APP_ID, MESSAGE_PORT_REMOTE_NAME, &found);
     if (!found) {
         LOGW("Can't find remote port");
@@ -78,7 +80,7 @@ bool send_message(const char *cmd, const char *data)
     }
     else
     {
-        LOGI("send message done");
+        LOGI("Succeed to send message.");
         result = true;
     }
 
index a391fc2..89aedfb 100644 (file)
@@ -1,12 +1,31 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 #include "sticker_info.h"
 #include <sticker_provider.h>
 #include <app_common.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <iostream>
 
 #include "log.h"
 
+using namespace std;
+
 static sticker_provider_h sticker_provider = NULL;
+static bool need_to_retrive = false;
 
 sticker_data_h
 set_sticker_data(sticker_data_uri_type_e type, const char* uri, const char* keyword,
@@ -106,3 +125,47 @@ void destroy_sticker_provider_handle(void)
     sticker_provider_destroy(sticker_provider);
     sticker_provider = NULL;
 }
+
+static void _sticker_foreach_cb(sticker_data_h data_handle, void *user_data)
+{
+    int ret;
+    char *del_file = (char *)user_data;
+    sticker_data_uri_type_e type;
+    char *uri = NULL;
+
+    if (!need_to_retrive)
+        return;
+
+    ret = sticker_data_get_uri(data_handle, &type, &uri);
+    if (ret != STICKER_ERROR_NONE)
+        LOGE("Failed to get sticker uri");
+
+    int result = (string(uri)).find(del_file);
+    if (result >= 0) {
+        LOGI("Delete sticker (%s)", uri);
+        need_to_retrive = false;
+
+        ret = sticker_provider_delete_data(sticker_provider, data_handle);
+        if (ret != STICKER_ERROR_NONE)
+            LOGE("Failed to delete sticker");
+    }
+}
+
+void delete_sticker_data(const char *fileName)
+{
+    int ret;
+    int offset = 0;
+    int count = 0;
+    int result = 0;
+    need_to_retrive = true;
+
+    while (result == count && need_to_retrive) {
+        count = 20;
+        ret = sticker_provider_data_foreach_all(sticker_provider, offset, count, &result, _sticker_foreach_cb, (void *)fileName);
+        offset += result;
+        if (ret != STICKER_ERROR_NONE) {
+            LOGE("Failed to retrieve sticker");
+            return;
+        }
+    }
+}
\ No newline at end of file
diff --git a/receiver/src/sync_alarm.cpp b/receiver/src/sync_alarm.cpp
new file mode 100644 (file)
index 0000000..d4879d8
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <app_alarm.h>
+#include <app_common.h>
+#include <stdlib.h>
+
+#include "log.h"
+
+static int recurring_alarm_id = -1;
+
+static bool
+on_foreach_registered_alarm(int alarm_id, void *user_data)
+{
+    bool *result = (bool *)user_data;
+
+    LOGD("alarm id : %d", alarm_id);
+
+    *result = *result | 0x1;
+
+    return false;
+}
+
+bool sync_alarm_register(const char *operation, int delay, int period)
+{
+    int ret;
+    app_control_h app_control = NULL;
+    char *app_id = NULL;
+    bool result = false;
+
+    ret = app_control_create(&app_control);
+    if (ret != APP_CONTROL_ERROR_NONE)
+    {
+        LOGE("Function app_control_create() failed.");
+        return false;
+    }
+
+    ret = app_control_set_operation(app_control, operation);
+    if (ret != APP_CONTROL_ERROR_NONE)
+    {
+        LOGE("Function app_control_set_operation() failed.");
+        goto cleanup;
+    }
+
+    if (app_get_id(&app_id) != APP_ERROR_NONE) {
+        goto cleanup;
+    }
+
+    LOGD("app id : %s", app_id);
+    if (!app_id) {
+        goto cleanup;
+    }
+
+    ret = app_control_set_app_id(app_control, app_id);
+    if (ret != APP_CONTROL_ERROR_NONE)
+    {
+        LOGE("Function app_control_set_app_id() failed.");
+        goto cleanup;
+    }
+
+    alarm_cancel_all();
+
+    ret = alarm_schedule_after_delay(app_control, delay, period, &recurring_alarm_id);
+    if (ret != ALARM_ERROR_NONE)
+        LOGE("Function alarm_schedule_after_delay() failed.");
+    else
+        LOGD("Function alarm_schedule_after_delay() succeed. delay : %d, interval : %d", delay, period);
+
+    result = true;
+
+cleanup:
+    if (app_id)
+        free(app_id);
+
+    if (app_control) {
+        ret = app_control_destroy(app_control);
+        if (ret != APP_CONTROL_ERROR_NONE)
+            LOGE("Function app_control_destroy() failed.");
+        else
+            LOGD("Set recurring alarm with id: %i", recurring_alarm_id);
+    }
+
+    return result;
+}
+
+bool sync_alarm_exist()
+{
+    bool result = false;
+    int ret = alarm_foreach_registered_alarm(on_foreach_registered_alarm, &result);
+    if (ret != ALARM_ERROR_NONE)
+        LOGD("Listing error : %d", ret);
+
+    return result;
+}
\ No newline at end of file
index 980a4aa..6726d6d 100644 (file)
@@ -1,10 +1,12 @@
 <?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns="http://tizen.org/ns/packages" api-version="5.5" package="org.tizen.sticker-receiver" version="1.0.17">
+<manifest xmlns="http://tizen.org/ns/packages" api-version="5.5" package="org.tizen.sticker-receiver" version="1.0.22">
         <profile name="wearable" />
         <service-application appid="org.tizen.sticker-receiver" exec="sticker-receiver" type="capp" multiple="false" taskmanage="false" nodisplay="true" launch_mode="single">
         <label>sticker-receiver</label>
                 <metadata key="accessory-services-location" value="/res/xml/accessoryservices.xml"/>
                 <metadata key="launch-on-attach" value="false"/>
+                <background-category value="background-network"/>
+                <background-category value="iot-communication"/>
                 <background-category value="system"/>
         </service-application>
         <privileges>
@@ -12,6 +14,9 @@
             <privilege>http://tizen.org/privilege/content.write</privilege>
             <privilege>http://tizen.org/privilege/mediastorage</privilege>
             <privilege>http://tizen.org/privilege/appdir.shareddata</privilege>
+            <privilege>http://tizen.org/privilege/alarm.set</privilege>
+            <privilege>http://tizen.org/privilege/alarm.get</privilege>
+            <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
         </privileges>
         <category name="http://tizen.org/category/sticker"/>
 </manifest>