BuildRequires: pkgconfig(capi-base-common)
BuildRequires: pkgconfig(capi-appfw-service-application)
BuildRequires: pkgconfig(capi-message-port)
-BuildRequires: pkgconfig(capi-appfw-alarm)
+BuildRequires: pkgconfig(capi-appfw-preference)
BuildRequires: pkgconfig(capi-system-device)
BuildRequires: pkgconfig(sap-client-stub-api)
BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(capi-media-thumbnail-util)
+BuildRequires: pkgconfig(ecore)
BuildRequires: hash-signer
Requires(post): signing-client
src/ft.cpp
src/sticker_info.cpp
src/message.cpp
- src/sync_alarm.cpp
)
INCLUDE(FindPkgConfig)
capi-appfw-service-application
capi-message-port
capi-appfw-app-common
- capi-appfw-alarm
capi-appfw-event
+ capi-appfw-preference
capi-system-device
sap-client-stub-api
json-glib-1.0
vconf
capi-media-thumbnail-util
+ ecore
)
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/receiver/inc)
#define ACCESSORY_SERVICE_PROFILE_ID "/sample/filetransfersender"
#define ACCESSORY_SERVICE_CHANNEL_ID 107
-#define SYNC_ALARM_DELAY 0
-#define SYNC_ALARM_INTERVAL 12*60*60
+#define SYNC_INTERVAL 12*60*60
#define REMOTE_APP_ID "com.samsung.w-input-selector"
#define MESSAGE_PORT_REMOTE_NAME REMOTE_APP_ID"_msg_port_rcv"
void accept_file(void);
gboolean initialize_sap(void);
void deinitialize_sap(void);
+gboolean is_init_sap();
+void request_all_sticker_data(const char *mode, const char *type);
bool request_sticker_data(const char *mode, const char *category, const char *type);
void request_sticker_feature();
void send_disconnect_message();
+bool get_job_progress();
+
#endif /* __FT_H__ */
+++ /dev/null
-/*
- * 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"
-
-bool sync_alarm_register(const char *operation, int delay, int period);
-bool sync_alarm_exist();
-
-#endif /* __ALARM_H__ */
#include <vconf.h>
#include <queue>
#include <thumbnail_util.h>
+#include <Ecore.h>
+#include <app_preference.h>
#include "ft.h"
#include "log.h"
#include "../inc/sticker_data.h"
#include "sticker_request.h"
#include "message.h"
-#include "sync_alarm.h"
#include "config.h"
+#include "receiver_preference.h"
#define STICKER_SYNC_FEATURE_REQ "sticker-sync-feature-req"
#define STICKER_SYNC_FEATURE_RSP "sticker-sync-feature-rsp"
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 void set_first_sync_complete()
+static void save_last_sync_time()
+{
+ // save last sync time in preference
+ double current_time = ecore_time_get();
+ if (preference_set_double(LAST_SYNC_TIME, current_time) == PREFERENCE_ERROR_NONE) {
+ LOGI("Succeed to set last sync time : %f", current_time);
+ }
+ else {
+ LOGW("Failed to set last sync time");
+ }
+}
+
+static void set_sync_complete()
{
int complete_flags = 0;
if (vconf_get_int(VCONFKEY_STICKER_SYNC_COMPLETE, &complete_flags) == 0 && complete_flags == 0) {
+ // first sync
if (vconf_set_int(VCONFKEY_STICKER_SYNC_COMPLETE, VCONFKEY_STICKER_SYNC_COMPLETE_DONE) == 0)
LOGD("Succeed to set sync complete");
else
LOGW("Fail to set sync complete");
}
+
+ save_last_sync_time();
}
static void set_sync_progressing(gboolean flag)
{
+ job_progress = flag;
#ifdef VCONFKEY_STICKER_SYNC_STATE
LOGD("sync progressing : %d", flag);
if (vconf_set_int(VCONFKEY_STICKER_SYNC_STATE, flag ? VCONFKEY_STICKER_SYNC_STATE_IN_PROGRESS : VCONFKEY_STICKER_SYNC_STATE_WAITING) == 0)
sap_file_transfer_set_done_cb(file_socket, _on_transfer_completed, NULL);
}
+bool get_job_progress()
+{
+ return job_progress;
+}
+
void accept_file()
{
int ret;
JsonObject *j_object = NULL;
if (!priv_data.socket) {
+ job_progress = TRUE;
StickerRequest pending_request;
pending_request.req_type = REQUEST_TYPE_SYNC;
pending_request.mode = string(mode ? mode : "manual");
return result;
}
+void request_all_sticker_data(const char *mode, const char *type)
+{
+#ifdef VCONFKEY_STICKER_SUPPORTED_FEATURE
+ int feature_flag = 0;
+ if (vconf_get_int(VCONFKEY_STICKER_SUPPORTED_FEATURE, &feature_flag) == 0)
+ {
+ if (feature_flag & VCONFKEY_STICKER_FEATURE_AREMOJI)
+ request_sticker_data(mode, "arsticker", type);
+
+ if (feature_flag & VCONFKEY_STICKER_FEATURE_BITMOJI)
+ request_sticker_data(mode, "bitmoji", type);
+ }
+ else
+ LOGW("Failed to get value of VCONFKEY_STICKER_SUPPORTED_FEATURE");
+#else
+ request_sticker_data(mode, "arsticker", type);
+ request_sticker_data(mode, "bitmoji", type);
+#endif
+}
+
void request_sticker_feature()
{
JsonObject *j_object = NULL;
if (!priv_data.socket) {
+ job_progress = TRUE;
StickerRequest pending_request;
pending_request.req_type = REQUEST_TYPE_FEATURE_REQ;
ReqQueue.push(pending_request);
if (_send_json_data(j_object) == FALSE) {
LOGE("Failed to send STICKER_SYNC_FEATURE_REQ");
}
+ else {
+ job_progress = TRUE;
+ }
json_object_unref(j_object);
#endif
if (!process_request_queue()) {
+ job_progress = FALSE;
send_disconnect_message();
service_app_exit();
}
if (result_code != SYNC_START_RSP_SUCCESS) {
set_sync_progressing(FALSE);
if (!process_request_queue()) {
+ if (result_code == SYNC_START_RSP_NO_STICKER)
+ save_last_sync_time();
+
+ job_progress = FALSE;
send_disconnect_message();
service_app_exit();
}
{
if (current_request.category == string("arsticker"))
{
- set_first_sync_complete();
+ set_sync_complete();
set_sync_progressing(FALSE);
}
}
{
if (current_request.category == string("bitmoji"))
{
- set_first_sync_complete();
+ set_sync_complete();
set_sync_progressing(FALSE);
}
}
send_message("sync_stop_result", reason.c_str());
if (!process_request_queue()) {
- if (sync_success_cnt > 0 && current_request.mode == string("manual")) {
- if (!sync_alarm_exist())
- sync_alarm_register(APP_CONTROL_OPERATION_SYNC_ALARM, SYNC_ALARM_DELAY, SYNC_ALARM_INTERVAL);
- }
-
sync_success_cnt = 0;
+ job_progress = FALSE;
send_disconnect_message();
service_app_exit();
}
{
sap_agent_h agent = NULL;
+ if (priv_data.agent) {
+ LOGW("duplicate initialize");
+ return FALSE;
+ }
+
sap_agent_create(&agent);
priv_data.agent = agent;
void deinitialize_sap(void)
{
+ LOGD("deinitialize");
if (priv_data.agent) {
int ret = sap_agent_deinitialize(priv_data.agent, on_agent_deinitialized, NULL);
switch (ret) {
priv_data.agent = NULL;
}
}
+
+gboolean is_init_sap()
+{
+ return priv_data.agent ? TRUE : FALSE;
+}
\ No newline at end of file
#include <app_common.h>
#include <service_app.h>
#include <stdlib.h>
-#include <app_alarm.h>
+#include <app_event.h>
#include <device/battery.h>
#include <vconf.h>
+#include <string>
+#include <app_preference.h>
+#include <Ecore.h>
#include "main.h"
#include "ft.h"
#include "log.h"
#include "config.h"
-#include "sync_alarm.h"
+#include "receiver_preference.h"
+
+using namespace std;
static bool app_create(void *data)
{
If this function returns true, the main loop of application starts
If this function returns false, the application is terminated */
- initialize_sap();
+ LOGD("");
return true;
}
+static bool check_battery_condition()
+{
+ int battery_percentage = 0;
+ int ret;
+
+ // check battery percentage
+ ret = device_battery_get_percent(&battery_percentage);
+ if (ret != DEVICE_ERROR_NONE)
+ {
+ LOGW("No sync. Failed to get battery percent. error : %d", ret);
+ return false;
+ }
+
+ LOGI("battery percent : %d", battery_percentage);
+ if (battery_percentage >= MINIMUM_BATTERY)
+ return true;
+ else
+ {
+ LOGI("No sync due to insufficient battery");
+ return false;
+ }
+}
+
+static bool check_sync_time_condition()
+{
+ double last_sync_time;
+ int feature_flag = 0;
+ bool result = false;
+
+#ifdef VCONFKEY_STICKER_SUPPORTED_FEATURE
+ // Check whether oobe has been done
+ if (vconf_get_int(VCONFKEY_STICKER_SUPPORTED_FEATURE, &feature_flag) == 0 && feature_flag > 0)
+ {
+ if (preference_get_double(LAST_SYNC_TIME, &last_sync_time) != PREFERENCE_ERROR_NONE)
+ {
+ LOGD("Can't get last sync time.");
+ return true;
+ }
+
+ // compare time
+ LOGD("current time : %f, last_sync_time : %f", ecore_time_get(), last_sync_time);
+ if (ecore_time_get() - last_sync_time > SYNC_INTERVAL)
+ result = true;
+ else
+ result = false;
+ }
+ else
+ {
+ result = false;
+ }
+#endif /* VCONFKEY_STICKER_SUPPORTED_FEATURE */
+
+ return result;
+}
+
static void app_control(app_control_h app_control, void *data)
{
/* Handle the launch request. */
char* mode = NULL;
char* type = NULL;
char* operation = NULL;
- char* alarm_data = NULL;
-
+ char* event_value = NULL;
+ char* uri = NULL;
+ const char *event_uri = "event://tizen.system.event.battery_charger_status";
int res;
- int battery_percentage = 0;
- bool battery_charging = false;
// 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;
- }
-
- LOGD("alarm data : %s", alarm_data);
-
- int ret = device_battery_is_charging(&battery_charging);
- if (ret != DEVICE_ERROR_NONE) {
- LOGW("No sync. Can't get battery charging status");
- goto cleanup;
- }
-
- if (!battery_charging) {
- LOGI("No sync due to no battery charging status");
- goto cleanup;
- }
-
- ret = device_battery_get_percent(&battery_percentage);
- if (ret != DEVICE_ERROR_NONE) {
- LOGW("No sync. Failed to get battery percent. error : %d", ret);
- goto cleanup;
- }
+ if (!operation) {
+ goto cleanup;
+ }
- LOGI("battery percent : %d", battery_percentage);
- if (battery_percentage >= MINIMUM_BATTERY) {
- request_sticker_data("auto", "arsticker", "input");
- request_sticker_data("auto", "bitmoji", "input");
- }
- else {
- LOGI("No sync due to insufficient battery");
+ if (strcmp(operation, APP_CONTROL_OPERATION_LAUNCH_ON_EVENT) == 0)
+ {
+ ret = app_control_get_uri(app_control, &uri);
+ if (ret == APP_CONTROL_ERROR_NONE && uri)
+ {
+ if (strncmp(uri, event_uri, strlen(event_uri) + 1) == 0)
+ {
+ ret = app_control_get_extra_data(app_control, "battery_charger_status", &event_value);
+ if (ret == APP_CONTROL_ERROR_NONE && event_value)
+ {
+ if (string(event_value) == "connected")
+ {
+ if (!is_init_sap()) {
+ if (check_sync_time_condition()) {
+ if (check_battery_condition()) {
+ initialize_sap();
+ request_all_sticker_data("auto", "input");
+ }
+ }
+ else {
+ if (!get_job_progress())
+ {
+ LOGD("exit");
+ service_app_exit();
+ }
+ }
+ }
+ else {
+ LOGD("continue doing current job");
+ }
+ }
+ free(event_value);
+ }
+ }
+ free(uri);
}
-
- goto cleanup;
}
}
else {
goto cleanup;
if (mode && type) {
-#ifdef VCONFKEY_STICKER_SUPPORTED_FEATURE
- int feature_flag = 0;
- if (vconf_get_int(VCONFKEY_STICKER_SUPPORTED_FEATURE, &feature_flag) == 0) {
- if (feature_flag & VCONFKEY_STICKER_FEATURE_AREMOJI)
- request_sticker_data(mode, "arsticker", type);
-
- if (feature_flag & VCONFKEY_STICKER_FEATURE_BITMOJI)
- request_sticker_data(mode, "bitmoji", type);
- } else
- LOGW("Failed to get value of VCONFKEY_STICKER_SUPPORTED_FEATURE");
-#else
- request_sticker_data(mode, "arsticker", type);
- request_sticker_data(mode, "bitmoji", type);
-#endif
+ if (!is_init_sap()) {
+ initialize_sap();
+ request_all_sticker_data(mode, 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);
+ initialize_sap();
request_sticker_feature();
}
else
{
LOGW("Unknown command : %s", request);
+ if (!is_init_sap())
+ {
+ service_app_exit();
+ }
}
}
static void app_terminate(void *data)
{
/* Release all resources. */
+ LOGD("");
deinitialize_sap();
}
+++ /dev/null
-/*
- * 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"
-#include "config.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
<background-category value="background-network"/>
<background-category value="iot-communication"/>
<background-category value="system"/>
+ <app-control>
+ <operation name="http://tizen.org/appcontrol/operation/launch_on_event"/>
+ <uri name="event://tizen.system.event.battery_charger_status"/>
+ </app-control>
</service-application>
<privileges>
<privilege>http://developer.samsung.com/tizen/privilege/accessoryprotocol</privilege>