3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
23 #include <vconf-keys.h>
26 #include <sync_agent.h>
29 #include "common/dm_common.h"
30 #include "common/util/util.h"
31 #include "framework/platform-event-handler/dm_platform_event_handler_internal.h"
32 #include "framework/task/oma_dm_task_request.h"
33 #include "dm-engine/fumo/fumo_account.h"
34 #include "dm-engine/fumo/fumo_engine_internal.h"
35 #include "dm-engine/cp/dm_cp_processor.h"
36 #include "mo-handler/dm_mo_common.h"
37 #include "mo-handler/dm_mo_common_internal.h"
38 #include "ipc_common.h"
39 #include "ipc_agent.h"
41 #ifndef OMADM_AGENT_LOG
43 #define LOG_TAG "OMA_DM_IPC"
46 static gint64 timeout;
50 #define TIMEOUT_VAL_UIC 60 //uic time out time
51 #define REST_TIMEOUT_VAL 10
53 static gint64 uic_timeout_val = 0;
55 static uic_res_data *res_uic_data = NULL;
57 static int (*_get_event_callback(int event_id)) (sync_agent_event_data_s * request, sync_agent_event_data_s * response);
59 static int __event_callback_software_update(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
60 static int __event_callback_cancel(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
61 static int __event_callback_download(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
62 static int __event_callback_install(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
63 static int __event_callback_set_interval(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
65 static int __event_callback_account_registration(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
67 static int __event_callback_get_profile(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
68 static int __event_callback_set_profile(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
69 static int __event_callback_reset_profile(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
71 static int __event_callback_uic_alert(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
73 static int __event_callback_get_fumo_config(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
74 static int __event_callback_set_fumo_config_wifi_only(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
76 static int __event_callback_check_pin_code(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
77 static int __event_callback_default(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
79 static int __event_add_dmacc(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
80 static int __event_remove_dmacc(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
82 static int _IPC_noti(int noti_type, int noti_id, int input_param, char *input_string, void *user_data);
83 static sync_agent_event_ipc_cancel_e __dm_task_process_check_cancel_flag(void *user_data);
85 static int __check_ui_mode(char **ui_mode, char *input_string);
86 static int __launch_ui(char *ui_mode, int noti_type);
88 static int __uic_response(int noti_id, void *user_data);
90 static int __check_ui_mode(char **ui_mode, char *input_string)
94 if (*ui_mode == NULL) {
95 _DEBUG_VERBOSE("ui mode is NULL");
96 if (input_string != NULL) {
97 _DEBUG_VERBOSE("input_string : %s", input_string);
98 if (strcmp(input_string, OMADM_ALERT_UI_TYPE) == 0 || strcmp(input_string, OMADM_FUMO_NOTI_UI_TYPE) == 0 || strcmp(input_string, OMADM_FUMO_UI_TYPE) == 0 || strcmp(input_string, OMADM_FUMO_BACKGROUND_UI_TYPE) == 0) {
100 *ui_mode = strdup(input_string);
105 _DEBUG_VERBOSE("ERROR UI MODE NULL");
107 return RESPONSE_TYPE_CANCEL;
110 _DEBUG_VERBOSE("ui mode : %s", *ui_mode);
111 _DEBUG_VERBOSE("input_string : %s", input_string);
112 if (input_string != NULL) {
113 if (strcmp(input_string, OMADM_ALERT_UI_TYPE) == 0 || strcmp(input_string, OMADM_FUMO_NOTI_UI_TYPE) == 0 || strcmp(input_string, OMADM_FUMO_UI_TYPE) == 0 || strcmp(input_string, OMADM_FUMO_BACKGROUND_UI_TYPE) == 0) {
116 *ui_mode = strdup(input_string);
126 return RESPONSE_TYPE_OK;
129 //static int __launch_ui(char *ui_mode, int noti_type)
130 static int __launch_ui(char *ui_mode, int noti_id)
136 if (ui_mode != NULL) {
137 //_DEBUG_INFO("ui_mode[%s], noti_type[%d]", ui_mode, noti_type);
138 _DEBUG_INFO("ui_mode[%s], noti_id[%d]", ui_mode, noti_id);
140 if (strcmp(ui_mode, OMADM_FUMO_UI_TYPE) == 0) {
141 ui_ret = launch_oma_dm_fumo_ui();
142 _DEBUG_INFO("fumo ui : %d", ui_ret);
143 } else if (strcmp(ui_mode, OMADM_FUMO_NOTI_UI_TYPE) == 0) {
144 DM_ERROR ret_poll = DM_OK;
145 char *server_id = NULL;
146 ret_poll = get_Serverid(SAMSUNG_FUMO_TYPE, &server_id);
147 if (ret_poll!= DM_OK || server_id == NULL) {
148 ui_ret = launch_om_dm_fumo_noti_ui(NOTI_TYPE_USERINTERACTION, NULL, NULL, POLL_EVENT);
150 ui_ret = launch_om_dm_fumo_noti_ui(NOTI_TYPE_USERINTERACTION, NULL, server_id, POLL_EVENT);
153 _DEBUG_INFO("noti ui : %d", ui_ret);
154 } else if (strcmp(ui_mode, OMADM_FUMO_BACKGROUND_UI_TYPE) == 0) {
155 //if (noti_type == NOTI_INSTALL) {
156 if (noti_id == NOTI_INSTALL) {
157 ui_ret = launch_om_dm_fumo_noti_ui(NOTI_TYPE_BACKGRUOUND, NULL, NULL, 0);
158 _DEBUG_INFO("noti ui : %d", ui_ret);
160 _DEBUG_INFO("background ui");
163 } else if (strcmp(ui_mode, OMADM_ALERT_UI_TYPE) == 0) {
164 ui_ret = launch_om_dm_fumo_alert_ui();
165 _DEBUG_INFO("alert ui : %d", ui_ret);
172 _DEBUG_INFO("UI launch fail");
178 _DEBUG_INFO("ERROR UI MODE NULL");
186 static int (*_get_event_callback(int event_id)) (sync_agent_event_data_s * request, sync_agent_event_data_s * response) {
187 _DEBUG_TRACE("%s: start (event_id:%d)\n", __func__, event_id);
190 case EVENT_SOFTWARE_UPDATE: // Type 0, Replies Exist
192 return __event_callback_software_update;
195 case EVENT_CANCEL: // Type 0, No Reply
197 return __event_callback_cancel;
200 case EVENT_DOWNLOAD: // Type 0, No Reply
202 return __event_callback_download;
205 case EVENT_INSTALL: // Type 0, No Reply
206 return __event_callback_install;
209 case EVENT_SET_INTERVAL:
210 return __event_callback_set_interval;
213 case EVENT_ACCOUNT_REGISTRATION:
214 return __event_callback_account_registration;
217 case EVENT_GET_FUMO_CONFIG:
218 return __event_callback_get_fumo_config;
221 case EVENT_SET_FUMO_CONFIG:
222 return __event_callback_set_fumo_config_wifi_only;
225 case EVENT_GET_PROFILE:
226 return __event_callback_get_profile;
229 case EVENT_SET_PROFILE:
230 return __event_callback_set_profile;
233 case EVENT_SET_RESET_PROFILE:
234 return __event_callback_reset_profile;
237 case EVENT_UIC_ALERT:
238 return __event_callback_uic_alert;
241 case EVENT_CHECK_PIN_CODE:
242 return __event_callback_check_pin_code;
245 case EVENT_ADD_DMACC:
246 return __event_add_dmacc;
249 case EVENT_REMOVE_DMACC:
250 return __event_remove_dmacc;
254 return __event_callback_default;
261 static int __event_callback_software_update(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
265 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
269 /*sleep(10); // for test */
272 retvm_if((request) == NULL, 0, "request is NULL!!");
275 char *session_id = NULL;
276 char *fota_ui_type = NULL;
277 char *server_id = NULL;
278 Event_Type triger_type = POLL_EVENT;
280 SERVICE_SERVER_TYPE server_type = SAMSUNG_FUMO_TYPE;
281 OPER_MODE operationMode = OPER_UNKNOWN;
282 NotI_Type noti_type = NOTI_TYPE_NOT_SPECIFIED;
284 sync_agent_get_event_data_param_int(request, (int*) &ui_type);
285 _DEBUG_INFO("UI TYPE : %d\n", ui_type);
289 _DEBUG_INFO("common ui");
290 fota_ui_type = OMADM_FUMO_UI_TYPE;
291 sync_agent_get_event_data_param_int(request, &task_id);
292 _DEBUG_INFO("get task id : %d", task_id);
293 sync_agent_get_event_data_param_int(request, (int*) &server_type);
294 triger_type = UI_EVENT;
295 ret = get_Serverid(server_type, &server_id);
296 //ret =get_Serverid(SAMSUNG_FUMO_TYPE , &server_id);
297 //ret =get_Serverid(GCF_TYPE , &server_id);
298 _DEBUG_INFO("get server id : %s : %d", server_id, ret);
299 operationMode = OPER_USER_INITIATION;
302 _DEBUG_INFO("noti ui");
303 fota_ui_type = OMADM_FUMO_NOTI_UI_TYPE;
304 sync_agent_get_event_data_param_str(request, &session_id);
305 sync_agent_get_event_data_param_str(request, &server_id);
306 sync_agent_get_event_data_param_int(request,(int*) &triger_type);
307 _DEBUG_INFO("get session id : %s", session_id);
308 _DEBUG_INFO("get server id : %s", server_id);
309 _DEBUG_INFO("get triger_type : %d", triger_type);
311 operationMode = OPER_SERVER_INITIATION_FROM_IP;
313 case FOTA_BACKGROUND_UI:
314 _DEBUG_INFO("background ui");
317 _DEBUG_INFO("admin ui");
318 fota_ui_type = OMADM_ADMIN_UI_TYPE;
319 sync_agent_get_event_data_param_int(request, (int*) &server_type);
320 ret = get_Serverid(server_type, &server_id);
321 _DEBUG_INFO("get server id : %s : %d", server_id, ret);
322 operationMode = OPER_USER_INITIATION;
325 _DEBUG_INFO("cp ui");
328 _DEBUG_INFO("not use ui");
332 if (server_id != NULL) {
333 _DEBUG_INFO("fumo server id = %s", server_id);
334 Event_Contents *ev_data = (Event_Contents *) calloc(1, sizeof(Event_Contents));
335 if (ev_data == NULL) {
336 _DEBUG_INFO("alloc fail");
339 //ev_data->type = UI_EVENT;
340 //ev_data->type = IP_PUSH_EVENT;
341 ev_data->type = triger_type;
342 _DEBUG_INFO("get triger_type : %d", triger_type);
343 if (session_id != NULL)
344 ev_data->session_id = strdup(session_id);
345 if (server_id != NULL) {
346 ev_data->server_id = strdup(server_id);
347 str_free(&server_id);
349 ev_data->noti_type = noti_type;
350 ev_data->ui_mode = strdup(fota_ui_type);
352 ret = dm_fumo_common_task_request(ev_data);
354 event_data_free((void *)ev_data);
362 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
367 int response_int = REPLY_FAIL_TO_CONNECT; //initial value
369 //Todo ------------------------------------------------------------------------------------------------------------------------ (from here)
370 sleep(10); // for test
372 response_int = REPLY_SUCCESS_TO_CONNECT; // resulted value
373 // ---------------------------------------------------------------------------------------------------------------------------------- (end)
374 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &response_int);
377 str_free(&(session_id));
378 str_free(&(server_id));
383 ev_response = EVENT_RESPONSE_FAIL;
384 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
386 str_free(&(session_id));
387 str_free(&(server_id));
393 static int __event_callback_cancel(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
397 retvm_if((request) == NULL, 0, "request is NULL!!");
400 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
401 _DEBUG_VERBOSE(">>> >>> >>> Connect to server CANCELED !!!\n");
404 sync_agent_get_event_data_param_int(request, &task_id);
405 _DEBUG_VERBOSE("task id : %d\n", task_id);
407 /*sync_agent_cancel_task(task_id); */
408 cancel_task(task_id);
411 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
418 static int __event_callback_download(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
422 retvm_if((request) == NULL, 0, "request is NULL!!");
424 DM_ERROR ret = DM_OK;
427 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
428 int response_type = 0;
429 RESUME_STATUS download_clicked = 0;
431 sync_agent_get_event_data_param_int(request, &response_type);
432 _DEBUG_INFO("DOWNLOAD BUTTON TYPE : %d\n", response_type);
435 _DEBUG_INFO("db open : %d", ret);
437 if (response_type == RESPONSE_TYPE_OK) {
438 /*download button clicked */
439 download_clicked = RESUME_STATUS_DOWNLOAD;
440 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
441 _DEBUG_INFO("update engine status clolumn download click : %d", ret);
443 } else if (RESPONSE_TYPE_CANCEL) {
444 /*later button clicked */
445 download_clicked = RESUME_STATUS_DOWNLOAD_LATER;
446 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
447 _DEBUG_INFO("update engine status clolumn download click : %d", ret);
451 if (response_type == RESPONSE_TYPE_OK) {
452 ret = fumo_serviceEngine_task_request();
458 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
463 ev_response = EVENT_RESPONSE_FAIL;
464 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
470 static int __event_callback_install(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
474 retvm_if((request) == NULL, 0, "request is NULL!!");
476 DM_ERROR ret = DM_OK;
479 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
480 int response_type = 0;
481 RESUME_STATUS download_clicked = 0;
483 sync_agent_get_event_data_param_int(request, &response_type);
484 _DEBUG_VERBOSE("INSTALL BUTTON TYPE : %d\n", response_type);
487 _DEBUG_VERBOSE("db open : %d", ret);
489 if (response_type == RESPONSE_TYPE_OK) {
490 /*download button clicked */
491 download_clicked = RESUME_STATUS_INSTALL;
492 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
493 _DEBUG_VERBOSE("update engine status clolumn install click : %d", ret);
495 } else if (RESPONSE_TYPE_CANCEL) {
496 /*later button clicked */
497 download_clicked = RESUME_STATUS_INSTALL_LATER;
498 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
499 _DEBUG_VERBOSE("update engine status clolumn install click : %d", ret);
503 ret = fumo_serviceEngine_task_request();
508 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
514 ev_response = EVENT_RESPONSE_FAIL;
515 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
521 static int __event_callback_set_interval(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
525 retvm_if((request) == NULL, 0, "request is NULL!!");
527 DM_ERROR ret = DM_OK;
529 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
530 int request_param = INTERVAL_CANCEL;
532 sync_agent_get_event_data_param_int(request, &request_param);
533 _DEBUG_INFO("interval val from UI : %d\n", request_param);
535 switch (request_param) {
536 case RESPONSE_TYPE_REMINDER_INTERVAL_1_HOUR:
537 request_param = INTERVAL_1HOUR;
539 case RESPONSE_TYPE_REMINDER_INTERVAL_3_HOURS:
540 request_param = INTERVAL_3HOURS;
542 case RESPONSE_TYPE_REMINDER_INTERVAL_6_HOURS:
543 request_param = INTERVAL_6HOURS;
545 case RESPONSE_TYPE_REMINDER_INTERVAL_12_HOURS:
546 request_param = INTERVAL_12HOURS;
548 case RESPONSE_TYPE_REMINDER_INTERVAL_1_DAY:
549 request_param = INTERVAL_1DAY;
551 case RESPONSE_TYPE_CANCEL:
552 request_param = INTERVAL_CANCEL;
558 _DEBUG_INFO(" interval val in fumo engine : %d\n", request_param);
559 if (request_param != INTERVAL_CANCEL) {
560 ret = fumo_schedule_task_request(request_param);
564 _DEBUG_INFO("fumo schedule task result : %d\n", ret);
567 ret = fumo_schedule_task_request(request_param);
573 _DEBUG_INFO("db open : %d", ret);
575 int engine_return = FUMO_USER_CANCELLED;// 401;
576 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_RESULT_STATUS, &engine_return);
577 _DEBUG_INFO("ret[%d] service engine status generic alert status : %d", ret, engine_return);
580 ret = fumo_serviceEngine_task_request();
584 _DEBUG_INFO("fumo schedule cancel : %d \n", ret);
588 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
595 ev_response = EVENT_RESPONSE_FAIL;
596 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
603 static int __event_callback_account_registration(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
607 retvm_if((request) == NULL, 0, "request is NULL!!");
610 DM_ERROR push_ret = DM_OK;
611 push_ret = register_fumo_ip_push();
612 if (push_ret == -1) {
613 _DEBUG_INFO("fail register fumo ip push : %d ", push_ret);
615 _DEBUG_INFO("success register fumo ip push : %d ", push_ret);
620 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
625 db_ret = sync_agent_open_agent();
626 _DEBUG_INFO("OPEN DACI : %d", db_ret);
628 ret = register_fota_account();
631 _DEBUG_INFO("fail register fota account : %d ", ret);
634 _DEBUG_INFO("success register fota account : %d ", ret);
636 char * str_version_url = NULL;
637 str_version_url = vconf_get_str(VERSION_URL_KEY);
638 if(str_version_url == NULL) {
639 _DEBUG_ERROR("vconf_get_str[%s] failed", VERSION_URL_KEY);
640 ret = EVENT_RESPONSE_FAIL;
644 char * str_version_filename = NULL;
645 str_version_filename = vconf_get_str(VERSION_FILENAME_KEY);
646 if(str_version_filename == NULL) {
647 _DEBUG_ERROR("vconf_get_str[%s] failed", VERSION_FILENAME_KEY);
648 ret = EVENT_RESPONSE_FAIL;
652 int exist_version = -1;
653 //ret = register_fota_polling(str_version_url, str_version_filename, &exist_version);
654 _DEBUG_INFO("exist_version [%d]", exist_version);
658 db_ret = sync_agent_close_agent();
659 _DEBUG_INFO("CLOSE DACI : %d", db_ret);
662 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
668 db_ret = sync_agent_close_agent();
669 _DEBUG_INFO("CLOSE DACI : %d", db_ret);
672 ev_response = EVENT_RESPONSE_FAIL;
673 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
678 // Type 1, Fumo setting data Reply
679 static int __event_callback_get_profile(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
683 retvm_if((request) == NULL, 0, "request is NULL!!");
685 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
687 char *profile_name = NULL;
688 SERVICE_SERVER_TYPE sv_type = NO_ENGINE_TYPE;
690 char *client_id = NULL;
691 char *client_pwd = NULL;
692 char *client_sourceUrl = NULL;
693 char *client_targetUrl = NULL;
694 int client_isBase64 = 0;
695 char *client_nextNonce = NULL;
696 char *client_authType = NULL;
698 char *server_url = NULL;
699 char *server_pwd = NULL;
700 char *server_sourceUrl = NULL;
701 char *server_targetUrl = NULL;
702 int server_isBase64 = 0;
703 char *server_nextNonce = NULL;
704 char *server_authType = NULL;
706 sync_agent_dm_mo_error_e db_ret = SYNC_AGENT_DM_MO_SUCCESS;
707 char *server_id = NULL;
709 sync_agent_get_event_data_param_int(request, (int*) &sv_type);
710 _DEBUG_VERBOSE("server type : %d\n", sv_type);
712 db_ret = sync_agent_open_mo();
713 _DEBUG_VERBOSE("mo db open : %d", db_ret);
716 case SAMSUNG_FUMO_TYPE:
718 profile_name = "Fumo";
721 case SAMSUNG_FMM_TYPE:
723 profile_name = "Lawmo";
728 profile_name = "gcf";
733 _DEBUG_VERBOSE("not exist server id error");
738 get_Serverid(sv_type, &server_id);
739 _DEBUG_VERBOSE("server id : %s", server_id);
741 if (server_id != NULL) {
742 DM_ERROR err = get_client_dmacc(server_id, &client_id, &client_pwd, &client_sourceUrl, &client_targetUrl, &client_isBase64, &client_nextNonce, &client_authType);
744 _DEBUG_VERBOSE("get_client_dmacc() fail !!");
747 _DEBUG_VERBOSE("get_client_dmacc() success !!");
750 err = get_server_dmacc(server_id, &server_url, &server_pwd, &server_sourceUrl, &server_targetUrl, &server_isBase64, &server_nextNonce, &server_authType);
752 _DEBUG_VERBOSE("get_server_dmacc() fail !!");
755 _DEBUG_VERBOSE("get_server_dmacc() success !!");
758 db_ret = sync_agent_close_mo();
759 _DEBUG_VERBOSE("mo db close : %d", db_ret);
761 _DEBUG_VERBOSE("profile_name : %s", profile_name);
762 _DEBUG_VERBOSE("client_targetUrl : %s", client_targetUrl);
763 _DEBUG_VERBOSE("server_id : %s", server_url);
764 _DEBUG_VERBOSE("server_pwd : %s", server_pwd);
765 _DEBUG_VERBOSE("client_id : %s", client_id);
766 _DEBUG_VERBOSE("client_pwd : %s", client_pwd);
767 _DEBUG_VERBOSE("client_authType : %s", client_authType);
768 _DEBUG_VERBOSE("server_authType : %s", server_authType);
771 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
773 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, profile_name);
774 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, client_targetUrl);
775 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, server_url);
776 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, server_pwd);
777 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, client_id);
778 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, client_pwd);
779 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, client_authType);
780 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, server_authType);
782 str_free(&server_nextNonce);
783 str_free(&client_nextNonce);
784 str_free(&client_sourceUrl);
785 str_free(&server_sourceUrl);
786 str_free(&server_targetUrl);
787 str_free(&client_targetUrl);
788 str_free(&server_url);
789 str_free(&server_pwd);
790 str_free(&client_id);
791 str_free(&client_pwd);
792 str_free(&client_authType);
793 str_free(&server_authType);
795 _DEBUG_VERBOSE("not exist server id error");
803 db_ret = sync_agent_close_mo();
804 _DEBUG_VERBOSE("mo db close : %d", db_ret);
806 ev_response = EVENT_RESPONSE_FAIL;
807 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
812 static int __event_callback_set_profile(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
816 retvm_if((request) == NULL, 0, "request is NULL!!");
819 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
822 SERVICE_SERVER_TYPE sv_type = NO_ENGINE_TYPE;
823 char *server_id = NULL;
825 dm_acc *dmaccount = (dm_acc *) calloc(1, sizeof(dm_acc));
826 if (dmaccount == NULL) {
827 _DEBUG_VERBOSE("alloc fail");
831 sync_agent_get_event_data_param_int(request, (int*) &sv_type);
832 _DEBUG_VERBOSE("server profile type : %d", sv_type);
833 sync_agent_get_event_data_param_str(request, &(dmaccount->server_url));
834 _DEBUG_VERBOSE("server url : %s", (dmaccount->server_url));
835 sync_agent_get_event_data_param_str(request, &(dmaccount->server_id));
836 _DEBUG_VERBOSE("server id : %s", dmaccount->server_id);
837 sync_agent_get_event_data_param_str(request, &(dmaccount->server_pw));
838 _DEBUG_VERBOSE("server_pw : %s", dmaccount->server_pw);
839 sync_agent_get_event_data_param_str(request, &(dmaccount->user_id));
840 _DEBUG_VERBOSE("user_id : %s", dmaccount->user_id);
841 sync_agent_get_event_data_param_str(request, &(dmaccount->user_pw));
842 _DEBUG_VERBOSE("user_pw : %s", dmaccount->user_pw);
843 sync_agent_get_event_data_param_str(request, &(dmaccount->user_auth_type));
844 _DEBUG_VERBOSE("user_auth_type : %s", dmaccount->user_auth_type);
845 sync_agent_get_event_data_param_str(request, &(dmaccount->server_auth_type));
846 _DEBUG_VERBOSE("server_auth_type : %s", dmaccount->server_auth_type);
848 get_Serverid(sv_type, &server_id);
849 _DEBUG_VERBOSE("server id : %s", server_id);
851 if (server_id != NULL) {
852 ret = update_dmacc(server_id, dmaccount);
854 _DEBUG_VERBOSE("update dm acc fail", ret);
858 _DEBUG_VERBOSE("update dm acc success", ret);
865 _DEBUG_VERBOSE("update dm acc : %d", ret);
866 free_dm_acc(dmaccount);
868 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
874 free_dm_acc(dmaccount);
875 ev_response = EVENT_RESPONSE_FAIL;
876 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
881 static int __event_callback_reset_profile(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
884 retvm_if((request) == NULL, 0, "request is NULL!!");
887 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
888 SERVICE_SERVER_TYPE sv_type = NO_ENGINE_TYPE;
890 sync_agent_get_event_data_param_int(request, (int*) &sv_type);
891 _DEBUG_VERBOSE("PROFILE TYPE : %d\n", sv_type);
894 case SAMSUNG_FUMO_TYPE:
896 reset_dmacc_msctestserver();
899 case SAMSUNG_FMM_TYPE:
901 reset_dmacc_mscserver();
915 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
920 ev_response = EVENT_RESPONSE_FAIL;
921 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
926 static int __event_callback_uic_alert(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
930 uic_type type = UIC_NONE_TYPE;
931 RESPONSE_TYPE response_ret = EVENT_RESPONSE_FAIL;
932 char *input_text = NULL;
937 if (type == UIC_DISPLAY_TYPE) {
941 free_res_data(res_uic_data);
943 sync_agent_get_event_data_param_int(request, (int*) &response_ret);
944 _DEBUG_TRACE("response is %d", response_ret);
946 sync_agent_get_event_data_param_int(request, (int*) &type);
947 _DEBUG_TRACE("uic type %d", type);
949 /*alloc reponse data */
950 res_uic_data = calloc(1, sizeof(uic_res_data) + 1);
951 res_uic_data->status = response_ret;
953 if (response_ret == RESPONSE_TYPE_OK) {
955 _DEBUG_TRACE("response ok");
958 case UIC_CONFIRMATION_TYPE:
960 case UIC_INPUT_TEXT_TYPE:{
961 sync_agent_get_event_data_param_str(request, &input_text);
962 _DEBUG_TRACE("input text %s", input_text);
964 res_uic_data->input_text = strdup(input_text);
967 case UIC_SINGLE_CHOICE_TYPE:
968 case UIC_MULTIPLE_CHOICE_TYPE:{
969 sync_agent_get_event_data_param_int(request, &count);
970 _DEBUG_TRACE("count is %d\n", count);
973 /*single, multiple choice */
974 for (i = 0; i < count; ++i) {
977 sync_agent_get_event_data_param_str(request, &input);
978 _DEBUG_TRACE(" choice : %s", input);
980 input = strdup("NULL");
981 res_uic_data->res_multi_data = g_list_append(res_uic_data->res_multi_data, input);
983 _DEBUG_TRACE("value data : %s", input);
984 value = strdup(input);
985 res_uic_data->res_multi_data = g_list_append(res_uic_data->res_multi_data, value);
989 _DEBUG_TRACE("not choice");
993 case UIC_DISPLAY_TYPE:
1003 _DEBUG_TRACE("response fail");
1007 g_mutex_lock(&(mutex));
1008 g_cond_signal(&(cond));
1009 g_mutex_unlock(&(mutex));
1011 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
1012 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1018 static int __event_callback_get_fumo_config(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
1021 retvm_if((request) == NULL, 0, "request is NULL!!");
1024 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
1027 sync_agent_open_agent();
1029 wifi_only = get_wifi_only_config();
1030 sync_agent_close_agent();
1032 if (wifi_only == -1) {
1033 _DEBUG_VERBOSE("get wifi only config fail\n");
1036 _DEBUG_VERBOSE("get wifi only config success\n");
1039 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1041 _DEBUG_VERBOSE("wifi only : %d", wifi_only);
1042 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &wifi_only);
1048 ev_response = EVENT_RESPONSE_FAIL;
1049 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1054 static int __event_callback_set_fumo_config_wifi_only(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
1057 retvm_if((request) == NULL, 0, "request is NULL!!");
1060 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
1062 int wifi_only_param;
1064 sync_agent_get_event_data_param_int(request, &wifi_only_param);
1066 sync_agent_open_agent();
1067 ret = set_wifi_only_config(wifi_only_param);
1068 sync_agent_close_agent();
1073 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1078 ev_response = EVENT_RESPONSE_FAIL;
1079 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1084 static int __event_callback_check_pin_code(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
1087 retvm_if((request) == NULL, 0, "request is NULL!!");
1090 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
1092 CP_ERROR err = CP_ERROR_SUCCESS;
1095 sync_agent_get_event_data_param_int(request, &ext_id);
1096 _DEBUG_VERBOSE("ext id : %d", ext_id);
1098 char *user_pin = NULL;
1100 int response_type = RESPONSE_TYPE_NONE;
1101 sync_agent_get_event_data_param_int(request, &response_type);
1102 _DEBUG_VERBOSE("response type : %d", response_type);
1104 int response_value = 0;
1106 if (response_type == RESPONSE_TYPE_OK) {
1107 _DEBUG_VERBOSE("check pin code !!");
1108 sync_agent_get_event_data_param_str(request, &user_pin);
1109 _DEBUG_VERBOSE("user pin : %s", user_pin);
1112 err = process_Check_Pincode(0, user_pin, &is_correct, ext_id);
1113 if (err != CP_ERROR_SUCCESS) {
1114 _DEBUG_VERBOSE("process_Check_Pincode() fail !!");
1115 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1118 /* todo : exception handling */
1119 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &response_value);
1121 _DEBUG_VERBOSE("process_Check_Pincode() success !!");
1123 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1125 if (is_correct != 0) {
1130 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &response_value);
1132 /* process_Setting_CP() */
1133 if (is_correct == 1) {
1134 _DEBUG_VERBOSE("Valid PIN !!");
1136 err = process_Setting_CP(ext_id);
1137 if (err != CP_ERROR_SUCCESS) {
1138 _DEBUG_VERBOSE("process_Setting_CP() fail !!");
1140 _DEBUG_VERBOSE("process_Setting_CP() success !!");
1142 } else if (is_correct == 0) {
1143 _DEBUG_VERBOSE("Invalid PIN !!");
1146 } else { /* response_type == RESPONSE_TYPE_CANCEL */
1147 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1149 response_value = 1; /* meaningless value */
1150 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &response_value);
1153 _DEBUG_VERBOSE("fail logic !!");
1154 err = process_Invalid_Pincode(ext_id);
1155 if (err != CP_ERROR_SUCCESS) {
1156 _DEBUG_VERBOSE("process_Invalid_Pincode() fail !!");
1157 /* todo : exception handling */
1159 _DEBUG_VERBOSE("process_Invalid_Pincode() success !!");
1162 _DEBUG_VERBOSE("cancel logic !!");
1167 str_free(&(user_pin));
1172 static int __event_add_dmacc(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
1176 sync_agent_dm_mo_error_e db_ret = SYNC_AGENT_DM_MO_SUCCESS;
1177 DM_ERROR ret = DM_OK;
1179 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
1180 SERVICE_SERVER_TYPE sv_type = NO_ENGINE_TYPE;
1182 sync_agent_get_event_data_param_int(request, (int*) &sv_type);
1183 _DEBUG_VERBOSE("server type : %d\n", sv_type);
1185 db_ret = sync_agent_open_mo();
1186 _DEBUG_VERBOSE("mo db open : %d", db_ret);
1189 _DEBUG_VERBOSE("dm status open : %d", db_ret);
1191 ret = DB_Begin_Transaction();
1192 _DEBUG_VERBOSE("begin transaction : %d", ret);
1195 //todo will change ipc refactoring
1196 case SAMSUNG_FUMO_TYPE:
1198 _DEBUG_VERBOSE("add mscservertest dmacc");
1199 ret = add_dm_acc(sv_type);
1202 case SAMSUNG_FMM_TYPE:
1204 _DEBUG_VERBOSE("add mscserver dmacc");
1205 ret = add_dm_acc(sv_type);
1210 _DEBUG_VERBOSE("add gcf dmacc");
1211 ret = add_dm_acc(sv_type);
1216 _DEBUG_VERBOSE("not exist server id error");
1220 _DEBUG_VERBOSE("add dm acc error :%d", ret);
1223 ev_response = EVENT_RESPONSE_FAIL;
1227 ret = DB_End_Transaction(TRANSACTION_COMMIT_);
1228 _DEBUG_VERBOSE("end transaction : %d", ret);
1230 db_ret = sync_agent_close_mo();
1231 _DEBUG_VERBOSE("mo db close : %d", db_ret);
1235 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1242 ret = DB_End_Transaction(TRANSACTION_ROLLBACK_);
1243 _DEBUG_VERBOSE("end transaction : %d", ret);
1245 db_ret = sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
1246 _DEBUG_VERBOSE("end transaction : %d", db_ret);
1248 db_ret = sync_agent_close_mo();
1249 _DEBUG_VERBOSE("mo db close : %d", db_ret);
1253 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1259 static int __event_remove_dmacc(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
1263 sync_agent_dm_mo_error_e db_ret = SYNC_AGENT_DM_MO_SUCCESS;
1264 DM_ERROR ret = DM_OK;
1265 engine_status *status = NULL;
1266 ENGINE_STATUS engine_status = DM_IDLE;
1268 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
1269 SERVICE_SERVER_TYPE sv_type = NO_ENGINE_TYPE;
1271 sync_agent_get_event_data_param_int(request, (int*) &sv_type);
1272 _DEBUG_VERBOSE("server type : %d\n", sv_type);
1275 db_ret = sync_agent_open_mo();
1276 _DEBUG_VERBOSE("mo db open : %d", db_ret);
1280 _DEBUG_VERBOSE("config alarm open : %d", db_ret);
1282 int is_exist = IsExist_Engine_id(IDLE_ENGINE);
1286 ret = Get_Engine_Status(IDLE_ENGINE, &status);
1288 _DEBUG_ERROR("Get_Engine_Status is not DM_OK");
1292 if(status == NULL) {
1293 _DEBUG_ERROR("status is null");
1297 _DEBUG_VERBOSE("STATUS VALUE : %d ", status->engine_status);
1298 engine_status = status->engine_status;
1300 if (engine_status == DM_BEFORE_BOOTSTRAP) {
1301 _DEBUG_VERBOSE("not bootstrap");
1305 db_ret = sync_agent_begin_transaction_mo();
1306 _DEBUG_VERBOSE("end transaction : %d", db_ret);
1308 ret = DB_Begin_Transaction();
1309 _DEBUG_VERBOSE("end transaction : %d", ret);
1313 case UI_SAMSUNG_FUMO_TYPE:
1315 _DEBUG_VERBOSE("remove mscservertest dmacc");
1316 ret = remove_dm_acc(DM_DMACC_MSCTESTSERVER);
1318 _DEBUG_ERROR("remove dm acc error :%d", ret);
1322 int is_exist = IsExist_Engine_id(FUMO_SERVICE_ENGINE);
1323 if (is_exist == 0) {
1324 _DEBUG_VERBOSE("not exist fumo engine");
1327 ret = Delete_Engine_Status(FUMO_SERVICE_ENGINE);
1329 _DEBUG_ERROR("delete engine status :%d", ret);
1333 delete_alarm_item(FUMO_INTERVAL, FUMO_INTERVAL_TYPE);
1334 _DEBUG_TRACE(" delete fumo reminder in config db ");
1337 delete_fumo_contents(MEMORY_INTERNAL);
1338 delete_fumo_contents(MEMORY_SD_CARD);
1340 //change fumo state 10
1341 char *fumo_state = NULL;
1342 fumo_state = g_strdup_printf("%s%s%s%s", MO_ROOT, MO_SEPERATOR, FUMO_SERVICE, DM_FUMO_STATE_OP);
1343 set_current_fumo_state(fumo_state, IDLE_START);
1344 str_free(&fumo_state);
1348 case UI_SAMSUNG_FMM_TYPE:
1350 _DEBUG_VERBOSE("remove mscserver dmacc");
1351 ret = remove_dm_acc(DM_DMACC_MSCSERVER);
1353 _DEBUG_ERROR("remove dm acc error :%d", ret);
1358 int is_exist = IsExist_Engine_id(LAWMO_SERVICE_ENGINE);
1359 if (is_exist == 0) {
1360 _DEBUG_VERBOSE("not exist fumo engine");
1363 ret = Delete_Engine_Status(LAWMO_SERVICE_ENGINE);
1365 _DEBUG_ERROR("delete engine status :%d", ret);
1374 _DEBUG_VERBOSE("remove gcf dmacc");
1375 ret = remove_dm_acc(DM_DMACC_GCF);
1377 _DEBUG_ERROR("remove dm acc error :%d", ret);
1380 _DEBUG_VERBOSE("remove dm acc");
1386 _DEBUG_VERBOSE("not exist server id error");
1390 ret = DB_End_Transaction(TRANSACTION_COMMIT_);
1391 _DEBUG_VERBOSE("end transaction : %d", ret);
1393 db_ret = sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_COMMIT);
1394 _DEBUG_VERBOSE("end transaction : %d", db_ret);
1396 _DEBUG_VERBOSE("remove dm acc error :%d", ret);
1398 db_ret = sync_agent_close_mo();
1399 _DEBUG_VERBOSE("mo db close : %d", db_ret);
1403 if (status != NULL) {
1404 Free_Memory_Engine_Status(&status, 1);
1407 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1413 ret = DB_End_Transaction(TRANSACTION_ROLLBACK_);
1414 _DEBUG_VERBOSE("end transaction : %d", ret);
1416 db_ret = sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
1417 _DEBUG_VERBOSE("end transaction : %d", db_ret);
1419 db_ret = sync_agent_close_mo();
1420 _DEBUG_VERBOSE("mo db close : %d", db_ret);
1424 if (status != NULL) {
1425 Free_Memory_Engine_Status(&status, 1);
1428 ev_response = EVENT_RESPONSE_FAIL;
1429 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1435 static int __event_callback_default(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
1438 retvm_if((request) == NULL, 0, "request is NULL!!");
1440 _DEBUG_VERBOSE("Undefined Event !!! \n");
1450 sync_agent_event_error_e error = SYNC_AGENT_EVENT_IPC_ERR;
1452 for (event_id = 1; event_id < EVENT_NUM; event_id++) {
1453 error = sync_agent_set_event_callback(event_id, _get_event_callback(event_id));
1454 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1455 _DEBUG_INFO("FAILURE: sync_agent_set_event_callback (event id: %d)\n", event_id);
1458 _DEBUG_INFO("SUCCESS: sync_agent_set_event_callback (event id: %d)\n", event_id);
1460 g_mutex_init(&(mutex));
1461 g_cond_init(&(cond));
1465 _DEBUG_INFO("%s: end (error:%d, event_id:%d) \n", __func__, error, event_id);
1470 int noti_start(char *ui_mode)
1473 _DEBUG_INFO("-----------------------------------------------------------------------noti start-------------------------------------------------------------------------------------");
1475 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ENGINE_START, 0, ui_mode, NULL);
1478 int noti_download(int file_size)
1481 _DEBUG_INFO("-----------------------------------------------------------------------noti_connect_to_server-------------------------------------------------------------------------------------");
1483 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_DOWNLOAD, file_size, NULL, NULL);
1489 _DEBUG_INFO("-----------------------------------------------------------------------noti_install-------------------------------------------------------------------------------------");
1491 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_INSTALL, 0, NULL, NULL);
1494 int noti_send_download_info(int filesize, char *path)
1497 _DEBUG_INFO("-----------------------------------------------------------------------noti_send_download_info-------------------------------------------------------------------------------------");
1499 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_DOWNLOAD_INFO, filesize, path, NULL);
1502 int noti_low_battery(char *battery_level)
1505 _DEBUG_INFO("-----------------------------------------------------------------------noti_low_battery-------------------------------------------------------------------------------------");
1507 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_LOW_BATTERY, 0, battery_level, NULL);
1510 int noti_update_result(int result)
1513 _DEBUG_INFO("-----------------------------------------------------------------------noti_update_result-------------------------------------------------------------------------------------");
1515 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_UPDATE_RESULT, result, NULL, NULL);
1518 int alert_uic_display(uic_data * uic_value)
1521 _DEBUG_INFO("-----------------------------------------------------------------------noti_alert_ui_display-------------------------------------------------------------------------------------");
1523 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ALERT_DISPLAY, 0, OMADM_ALERT_UI_TYPE, uic_value);
1526 int alert_uic_confirmation(uic_data * uic_value)
1529 _DEBUG_INFO("-----------------------------------------------------------------------noti_alert_ui_confirmation-------------------------------------------------------------------------------------");
1531 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ALERT_CONFIRMATION, 0, OMADM_ALERT_UI_TYPE, uic_value);
1534 int alert_uic_inputText(uic_data * uic_value)
1537 _DEBUG_INFO("-----------------------------------------------------------------------noti_alert_ui_inputText-------------------------------------------------------------------------------------");
1539 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ALERT_INPUTTEXT, 0, OMADM_ALERT_UI_TYPE, uic_value);
1542 int alert_uic_single_choice(uic_data * uic_value)
1545 _DEBUG_INFO("-----------------------------------------------------------------------noti_alert_ui_single_choice-------------------------------------------------------------------------------------");
1547 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ALERT_SINGLE_CHOICE, 0, OMADM_ALERT_UI_TYPE, uic_value);
1550 int alert_uic_multiple_choice(uic_data * uic_value)
1553 _DEBUG_INFO("-----------------------------------------------------------------------noti_alert_ui_multi_choice-------------------------------------------------------------------------------------");
1555 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ALERT_MULTIPLE_CHOICE, 0, OMADM_ALERT_UI_TYPE, uic_value);
1558 int noti_engine_fail(int prev_noti_id, int fail_type)
1561 _DEBUG_INFO("-----------------------------------------------------------------------noti_engine_fail-------------------------------------------------------------------------------------");
1563 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ENGINE_FAIL, prev_noti_id, 0, &fail_type);
1566 int noti_wifi_only_download_fail()
1569 _DEBUG_INFO("-----------------------------------------------------------------------noti_wifi_only_download_fail-------------------------------------------------------------------------------------");
1571 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_WIFI_ONLY_DOWNLOAD_FAIL, 0, 0, 0);
1574 int noti_memory_full(int file_size)
1577 _DEBUG_INFO("-----------------------------------------------------------------------noti_memory_full-------------------------------------------------------------------------------------");
1579 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_MEMORY_FULL, file_size, 0, 0);
1582 int noti_over_max_file_size(int file_size)
1585 _DEBUG_INFO("-----------------------------------------------------------------------noti_over_max_file_size-------------------------------------------------------------------------------------");
1587 // return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_OVER_BIG_SIZE, 0, 0, 0);
1588 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_OVER_BIG_SIZE, file_size, 0, 0);
1591 static int _IPC_noti(int noti_type, int noti_id, int input_param, char *input_string, void *user_data)
1595 int ret = RESPONSE_TYPE_NONE;
1597 char *ui_mode = NULL;
1600 uic_data *uic_value = NULL;
1601 sync_agent_event_data_s *noti = NULL;
1602 sync_agent_event_data_s *reply_msg = NULL;
1603 sync_agent_event_error_e err = SYNC_AGENT_EVENT_FAIL;
1605 task_id = sync_agent_get_self_request_id();
1606 _DEBUG_TRACE("task : id %d ", task_id);
1607 if (task_id == -1) {
1608 ret = RESPONSE_TYPE_CANCEL;
1613 ret = get_fumo_ui_mode(&ui_mode);
1614 _DEBUG_TRACE("get ui mode : %d", ret);
1616 ret = RESPONSE_TYPE_CANCEL;
1621 _DEBUG_TRACE("ui mode : %s", ui_mode);
1622 ret = __check_ui_mode(&ui_mode, input_string);
1623 if (ret != RESPONSE_TYPE_OK) {
1624 str_free(&(ui_mode));
1626 return RESPONSE_TYPE_CANCEL;
1628 _DEBUG_TRACE("ui mode : %s", ui_mode);
1630 //ret = __launch_ui(ui_mode, noti_type);
1631 ret = __launch_ui(ui_mode, noti_id);
1633 str_free(&(ui_mode));
1635 return RESPONSE_TYPE_CANCEL;
1636 } else if (ret == 0) {
1637 str_free(&(ui_mode));
1639 return RESPONSE_TYPE_OK;
1642 _DEBUG_TRACE("ui mode : %s", ui_mode);
1643 _DEBUG_TRACE("create noti noti_id : %d", noti_id);
1645 noti = sync_agent_create_noti(noti_id);
1647 _DEBUG_TRACE("failed to sync_agent_create_noti");
1648 str_free(&(ui_mode));
1653 _DEBUG_TRACE("append_eventdata");
1657 case NOTI_DOWNLOAD: //Type 0
1659 _DEBUG_TRACE("download file size : %d", input_param);
1660 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &input_param);
1663 case NOTI_INSTALL: //Type 0
1665 case NOTI_DOWNLOAD_INFO: //Type 0
1667 if (&input_param == NULL || input_string == NULL) {
1668 _DEBUG_TRACE("Error: input param: NULL\n");
1669 ret = RESPONSE_TYPE_CANCEL;
1673 _DEBUG_TRACE("agent noti: filesize:%d, path:%s\n", input_param, input_string);
1675 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &input_param);
1676 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, input_string);
1677 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &task_id);
1680 case NOTI_ENGINE_START: //Type 0
1682 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &task_id);
1685 case NOTI_ENGINE_FAIL: //Type 0
1687 int *fail_type = (int *)(user_data);
1689 _DEBUG_TRACE("noti id : %d\n", input_param);
1690 _DEBUG_TRACE("fail : %d\n", *fail_type);
1692 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &input_param);
1693 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, fail_type);
1696 case NOTI_WIFI_ONLY_DOWNLOAD_FAIL: //Type 0
1698 _DEBUG_TRACE("wifi only downlaod fail ipc");
1701 case NOTI_MEMORY_FULL: //Type 0
1703 _DEBUG_TRACE("memory full ipc : %d", input_param);
1704 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &input_param);
1708 case NOTI_OVER_BIG_SIZE: //Type 0
1710 _DEBUG_TRACE("over max size : %d", input_param);
1711 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &input_param);
1714 case NOTI_LOW_BATTERY: //Type 0
1716 if (input_string == NULL) {
1718 _DEBUG_TRACE("Error : input string : NULL\n");
1719 ret = RESPONSE_TYPE_CANCEL;
1724 _DEBUG_TRACE("agent noti - battery level : %s\n", input_string);
1725 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, input_string);
1728 case NOTI_UPDATE_RESULT:
1730 _DEBUG_TRACE("fota update result : %d", input_param);
1731 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &input_param);
1734 case NOTI_ALERT_DISPLAY: //Type 2, response event
1735 case NOTI_ALERT_CONFIRMATION: //Type 2, response event
1736 case NOTI_ALERT_INPUTTEXT: //Type 2, response event
1738 _DEBUG_TRACE("uic flow noti type : %d", noti_id);
1739 uic_value = (uic_data *) user_data;
1741 uic_timeout_val = atoi(uic_value->pUic_option->max_t);
1743 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->min_t);
1744 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->max_t);
1745 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->default_data);
1746 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->maxlen);
1747 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->input_type);
1748 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->echo_type);
1750 _DEBUG_TRACE("display : %s\n", uic_value->display);
1751 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->display);
1754 case NOTI_ALERT_SINGLE_CHOICE: //Type 2, response event
1755 case NOTI_ALERT_MULTIPLE_CHOICE: //Type 2, response event
1757 uic_value = (uic_data *) user_data;
1759 uic_timeout_val = atoi(uic_value->pUic_option->max_t);
1761 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->min_t);
1762 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->max_t);
1763 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->default_data);
1764 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->maxlen);
1765 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->input_type);
1766 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->echo_type);
1768 _DEBUG_TRACE("display : %s\n", uic_value->display);
1769 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->display);
1771 count = g_list_length(uic_value->multi_data);
1772 _DEBUG_TRACE("choice data count : %d\n", count);
1773 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &count);
1775 for (iter = uic_value->multi_data; iter != NULL; iter = g_list_next(iter)) {
1776 _DEBUG_TRACE("choice data : %s", (char *)(iter->data));
1777 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (char *)(iter->data));
1786 if (noti_id != NOTI_ALERT_DISPLAY && noti_id != NOTI_ALERT_CONFIRMATION && noti_id != NOTI_ALERT_INPUTTEXT && noti_id != NOTI_ALERT_SINGLE_CHOICE && noti_id != NOTI_ALERT_MULTIPLE_CHOICE) {
1787 DB_Begin_Transaction();
1789 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_UI_NOTI_TYPE, ¬i_id);
1791 _DEBUG_TRACE("update engine status column : %d, %d\n", ret, noti_id);
1792 ret = RESPONSE_TYPE_CANCEL;
1797 _DEBUG_TRACE("sendNoti");
1798 reply_msg = sync_agent_send_noti(ui_mode, noti, __dm_task_process_check_cancel_flag, ui_mode, &err);
1799 if(reply_msg == NULL) {
1800 _DEBUG_TRACE("sendNoti return : %d", err);
1802 _DEBUG_TRACE("sendNoti return : %d , event_num[%d] , reply_msg data[%s]", err, reply_msg->event_num, reply_msg->data);
1804 if (err != SYNC_AGENT_EVENT_SUCCESS) {
1805 if (err == SYNC_AGENT_EVENT_IPC_ERR) {
1807 if (noti_id != NOTI_ALERT_DISPLAY && noti_id != NOTI_ALERT_CONFIRMATION && noti_id != NOTI_ALERT_INPUTTEXT && noti_id != NOTI_ALERT_SINGLE_CHOICE && noti_id != NOTI_ALERT_MULTIPLE_CHOICE) {
1808 DB_End_Transaction(TRANSACTION_ROLLBACK_);
1812 _DEBUG_TRACE("sendNoti (noti id:%d), FAIL\n", noti_id);
1813 ret = RESPONSE_TYPE_CANCEL;
1818 _DEBUG_TRACE("sendNoti (noti id:%d), success\n", noti_id);
1819 _DEBUG_TRACE("IPC RESPONSE\n");
1821 if (noti_id != NOTI_ALERT_DISPLAY && noti_id != NOTI_ALERT_CONFIRMATION && noti_id != NOTI_ALERT_INPUTTEXT && noti_id != NOTI_ALERT_SINGLE_CHOICE && noti_id != NOTI_ALERT_MULTIPLE_CHOICE) {
1822 DB_End_Transaction(TRANSACTION_COMMIT_);
1824 ret = __uic_response(noti_id, user_data);
1825 _DEBUG_TRACE("uic_response ret : %d", ret);
1830 ret = RESPONSE_TYPE_OK;
1833 str_free(&(ui_mode));
1834 sync_agent_free_noti(noti);
1840 str_free(&(ui_mode));
1841 sync_agent_free_noti(noti);
1842 _DEBUG_TRACE("%s : end : %d\n", __func__, ret);
1847 sync_agent_event_ipc_cancel_e __dm_task_process_check_cancel_flag(void *user_data)
1851 retvm_if((user_data) == NULL, SYNC_AGENT_EVENT_IPC_CANCEL_NEED_CANCEL, "user_data is NULL!!");
1853 sync_agent_ec_boolean cancel_flag = sync_agent_check_cancel_flag();
1854 sync_agent_event_ipc_cancel_e result_cancel;
1856 char *ui_mode = (char *)user_data;
1858 if (cancel_flag == 0) {
1859 result_cancel = SYNC_AGENT_EVENT_IPC_CANCEL_UN_NEED_CANCEL;
1860 _DEBUG_VERBOSE("%s : cancel_flag = %d\n", __func__, result_cancel);
1862 result_cancel = SYNC_AGENT_EVENT_IPC_CANCEL_NEED_CANCEL;
1863 _DEBUG_VERBOSE("%s : cancel_flag = %d\n", __func__, result_cancel);
1866 if (strcmp(ui_mode, OMADM_FUMO_UI_TYPE) == 0) {
1867 result_ui = aul_app_is_running(OMA_DM_FUMO_UI_PKG);
1868 if (result_ui == 0) {
1869 _DEBUG_VERBOSE("oma dm fumo ui process off \n");
1870 result_cancel = SYNC_AGENT_EVENT_IPC_CANCEL_NEED_CANCEL;
1872 } else if (strcmp(ui_mode, OMADM_FUMO_NOTI_UI_TYPE) == 0) {
1873 result_ui = aul_app_is_running(OMA_DM_FUMO_NOTI_UI_PKG);
1874 if (result_ui == 0) {
1875 _DEBUG_VERBOSE("oma dm noti ui process off \n");
1876 result_cancel = SYNC_AGENT_EVENT_IPC_CANCEL_NEED_CANCEL;
1882 return result_cancel;
1885 static int __uic_response(int noti_id, void *user_data)
1888 int ret = RESPONSE_TYPE_NONE;
1891 case NOTI_ALERT_DISPLAY: //Type 0
1893 _DEBUG_TRACE("display alert response ");
1894 ret = RESPONSE_TYPE_OK;
1897 case NOTI_ALERT_CONFIRMATION: //Type 0
1899 _DEBUG_TRACE("confirmation alert response ");
1902 if (uic_timeout_val == TIMEOUT_VAL_UIC) {
1903 uic_timeout_val = TIMEOUT_VAL_UIC + REST_TIMEOUT_VAL;
1905 uic_timeout_val += REST_TIMEOUT_VAL;
1908 timeout = g_get_monotonic_time() + uic_timeout_val * G_TIME_SPAN_SECOND;
1910 _DEBUG_TRACE("timeout : %d ", timeout);
1912 g_mutex_lock(&(mutex));
1913 g_cond_wait_until(&(cond), &(mutex), timeout);
1914 g_mutex_unlock(&(mutex));
1916 if (res_uic_data == NULL) {
1917 /*signal by timeout */
1918 ret = RESPONSE_TYPE_TIMEOVER;
1920 ret = res_uic_data->status;
1921 _DEBUG_TRACE("response is %d\n", ret);
1923 free_res_data(res_uic_data);
1924 res_uic_data = NULL;
1928 case NOTI_ALERT_INPUTTEXT: //Type 0
1931 if (uic_timeout_val == TIMEOUT_VAL_UIC) {
1932 uic_timeout_val = TIMEOUT_VAL_UIC + REST_TIMEOUT_VAL;
1934 uic_timeout_val += REST_TIMEOUT_VAL;
1937 timeout = g_get_monotonic_time() + uic_timeout_val * G_TIME_SPAN_SECOND;
1939 _DEBUG_TRACE("timeout : %d ", timeout);
1941 g_mutex_lock(&(mutex));
1942 g_cond_wait_until(&(cond), &(mutex), timeout);
1943 g_mutex_unlock(&(mutex));
1945 uic_data *uic_value = (uic_data *) user_data;
1947 if (res_uic_data == NULL) {
1948 /*signal by timeout */
1949 uic_value->res_data->input_text = strdup("NULL");
1950 _DEBUG_TRACE("INPUT TEXT CANCEL / TIMEOVER");
1951 ret = RESPONSE_TYPE_TIMEOVER;
1953 ret = res_uic_data->status;
1954 _DEBUG_TRACE("response is %d\n", ret);
1955 _DEBUG_TRACE("input text alert response ");
1957 if (ret == RESPONSE_TYPE_OK) {
1958 if (res_uic_data->input_text == NULL) {
1959 res_uic_data->input_text = strdup("NULL");
1962 uic_value->res_data->input_text = strdup(res_uic_data->input_text);
1965 uic_value->res_data->input_text = strdup("NULL");
1966 _DEBUG_TRACE("INPUT TEXT CANCEL / TIMEOVER");
1969 free_res_data(res_uic_data);
1970 res_uic_data = NULL;
1974 case NOTI_ALERT_SINGLE_CHOICE: //Type 0
1975 case NOTI_ALERT_MULTIPLE_CHOICE: //Type 0
1979 if (uic_timeout_val == TIMEOUT_VAL_UIC) {
1980 uic_timeout_val = TIMEOUT_VAL_UIC + REST_TIMEOUT_VAL;
1982 uic_timeout_val += REST_TIMEOUT_VAL;
1985 timeout = g_get_monotonic_time() + uic_timeout_val * G_TIME_SPAN_SECOND;
1986 _DEBUG_TRACE("timeout : %d ", timeout);
1988 g_mutex_lock(&(mutex));
1989 g_cond_wait_until(&(cond), &(mutex), timeout);
1990 g_mutex_unlock(&(mutex));
1992 _DEBUG_TRACE("choice alert response ");
1994 uic_data *uic_value = (uic_data *) user_data;
1998 if (res_uic_data == NULL) {
1999 /*signal by timeout */
2000 ret = RESPONSE_TYPE_TIMEOVER;
2001 input = strdup("NULL");
2002 uic_value->res_data->res_multi_data = g_list_append(uic_value->res_data->res_multi_data, input);
2003 _DEBUG_TRACE("CHOICE CANCEL / TIMEOVER");
2005 ret = res_uic_data->status;
2006 _DEBUG_TRACE("response is %d\n", ret);
2008 if (ret == RESPONSE_TYPE_OK) {
2010 if (res_uic_data->res_multi_data != NULL) {
2011 count = g_list_length(res_uic_data->res_multi_data);
2014 input = strdup("NULL");
2015 uic_value->res_data->res_multi_data = g_list_append(uic_value->res_data->res_multi_data, input);
2018 for (iter = res_uic_data->res_multi_data; iter != NULL; iter = g_list_next(iter)) {
2020 input = strdup(iter->data);
2021 uic_value->res_data->res_multi_data = g_list_append(uic_value->res_data->res_multi_data, input);
2025 input = strdup("NULL");
2026 uic_value->res_data->res_multi_data = g_list_append(uic_value->res_data->res_multi_data, input);
2027 _DEBUG_TRACE("CHOICE CANCEL / TIMEOVER");
2031 free_res_data(res_uic_data);
2032 res_uic_data = NULL;
2038 case NOTI_DOWNLOAD_INFO:
2039 case NOTI_ENGINE_START:
2040 case NOTI_LOW_BATTERY:
2041 case NOTI_OVER_BIG_SIZE: