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 <sync_agent.h>
26 #include "common/dm_common.h"
27 #include "common/util/util.h"
28 #include "framework/platform-event-handler/dm_platform_event_handler_internal.h"
29 #include "framework/task/oma_dm_task_request.h"
30 #include "dm-engine/fumo/fumo_account.h"
31 #include "dm-engine/fumo/fumo_engine_internal.h"
32 #include "dm-engine/cp/dm_cp_processor.h"
33 #include "mo-handler/dm_mo_common.h"
34 #include "mo-handler/dm_mo_common_internal.h"
35 #include "ipc_common.h"
36 #include "ipc_agent.h"
38 #ifndef OMADM_AGENT_LOG
40 #define LOG_TAG "OMA_DM_IPC"
43 static gint64 timeout;
47 #define TIMEOUT_VAL_UIC 60 //uic time out time
48 #define REST_TIMEOUT_VAL 10
50 static gint64 uic_timeout_val = 0;
52 static uic_res_data *res_uic_data = NULL;
54 static int (*_get_event_callback(int event_id)) (sync_agent_event_data_s * request, sync_agent_event_data_s * response);
56 static int __event_callback_software_update(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
57 static int __event_callback_cancel(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
58 static int __event_callback_download(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
59 static int __event_callback_install(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
60 static int __event_callback_set_interval(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
62 static int __event_callback_account_registration(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
64 static int __event_callback_get_profile(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
65 static int __event_callback_set_profile(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
66 static int __event_callback_reset_profile(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
68 static int __event_callback_uic_alert(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
70 static int __event_callback_get_fumo_config(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
71 static int __event_callback_set_fumo_config_wifi_only(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
73 static int __event_callback_check_pin_code(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
74 static int __event_callback_default(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
76 static int __event_add_dmacc(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
77 static int __event_remove_dmacc(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
79 static int _IPC_noti(int noti_type, int noti_id, int input_param, char *input_string, void *user_data);
80 static sync_agent_event_ipc_cancel_e __dm_task_process_check_cancel_flag(void *user_data);
82 static int __check_ui_mode(char **ui_mode, char *input_string);
83 static int __launch_ui(char *ui_mode, int noti_type);
85 static int __uic_response(int noti_id, void *user_data);
87 static int __check_ui_mode(char **ui_mode, char *input_string)
91 if (*ui_mode == NULL) {
92 if (input_string != NULL) {
93 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) {
95 *ui_mode = strdup(input_string);
100 _DEBUG_VERBOSE("ERROR UI MODE NULL");
102 return RESPONSE_TYPE_CANCEL;
105 _DEBUG_VERBOSE("ui mode : %s", *ui_mode);
106 _DEBUG_VERBOSE("ui mode : %s", input_string);
107 if (input_string != NULL) {
108 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) {
111 *ui_mode = strdup(input_string);
121 return RESPONSE_TYPE_OK;
124 static int __launch_ui(char *ui_mode, int noti_type)
130 if (ui_mode != NULL) {
131 if (strcmp(ui_mode, OMADM_FUMO_UI_TYPE) == 0) {
132 ui_ret = launch_oma_dm_fumo_ui();
133 _DEBUG_VERBOSE("fumo ui : %d", ui_ret);
134 } else if (strcmp(ui_mode, OMADM_FUMO_NOTI_UI_TYPE) == 0) {
135 ui_ret = launch_om_dm_fumo_noti_ui(NOTI_TYPE_USERINTERACTION, NULL, NULL);
136 _DEBUG_VERBOSE("noti ui : %d", ui_ret);
137 } else if (strcmp(ui_mode, OMADM_FUMO_BACKGROUND_UI_TYPE) == 0) {
138 if (noti_type == NOTI_INSTALL) {
139 ui_ret = launch_om_dm_fumo_noti_ui(NOTI_TYPE_BACKGRUOUND, NULL, NULL);
140 _DEBUG_VERBOSE("noti ui : %d", ui_ret);
142 _DEBUG_VERBOSE("background ui");
145 } else if (strcmp(ui_mode, OMADM_ALERT_UI_TYPE) == 0) {
146 ui_ret = launch_om_dm_fumo_alert_ui();
147 _DEBUG_VERBOSE("alert ui : %d", ui_ret);
154 _DEBUG_VERBOSE("UI launch fail");
160 _DEBUG_VERBOSE("ERROR UI MODE NULL");
168 static int (*_get_event_callback(int event_id)) (sync_agent_event_data_s * request, sync_agent_event_data_s * response) {
169 _DEBUG_TRACE("%s: start (event_id:%d)\n", __func__, event_id);
172 case EVENT_SOFTWARE_UPDATE: // Type 0, Replies Exist
174 return __event_callback_software_update;
177 case EVENT_CANCEL: // Type 0, No Reply
179 return __event_callback_cancel;
182 case EVENT_DOWNLOAD: // Type 0, No Reply
184 return __event_callback_download;
187 case EVENT_INSTALL: // Type 0, No Reply
188 return __event_callback_install;
191 case EVENT_SET_INTERVAL:
192 return __event_callback_set_interval;
195 case EVENT_ACCOUNT_REGISTRATION:
196 return __event_callback_account_registration;
199 case EVENT_GET_FUMO_CONFIG:
200 return __event_callback_get_fumo_config;
203 case EVENT_SET_FUMO_CONFIG:
204 return __event_callback_set_fumo_config_wifi_only;
207 case EVENT_GET_PROFILE:
208 return __event_callback_get_profile;
211 case EVENT_SET_PROFILE:
212 return __event_callback_set_profile;
215 case EVENT_SET_RESET_PROFILE:
216 return __event_callback_reset_profile;
219 case EVENT_UIC_ALERT:
220 return __event_callback_uic_alert;
223 case EVENT_CHECK_PIN_CODE:
224 return __event_callback_check_pin_code;
227 case EVENT_ADD_DMACC:
228 return __event_add_dmacc;
231 case EVENT_REMOVE_DMACC:
232 return __event_remove_dmacc;
236 return __event_callback_default;
243 static int __event_callback_software_update(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
247 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
251 /*sleep(10); // for test */
254 retvm_if((request) == NULL, 0, "request is NULL!!");
257 char *session_id = NULL;
258 char *fota_ui_type = NULL;
259 char *server_id = NULL;
261 SERVICE_SERVER_TYPE server_type = SAMSUNG_FUMO_TYPE;
262 OPER_MODE operationMode = OPER_UNKNOWN;
263 NotI_Type noti_type = NOTI_TYPE_NOT_SPECIFIED;
265 sync_agent_get_event_data_param(request, &ui_type);
266 _DEBUG_VERBOSE("UI TYPE : %d\n", ui_type);
270 _DEBUG_VERBOSE("common ui");
271 fota_ui_type = OMADM_FUMO_UI_TYPE;
272 sync_agent_get_event_data_param(request, &task_id);
273 _DEBUG_VERBOSE("get task id : %d", task_id);
274 sync_agent_get_event_data_param(request, &server_type);
275 ret = get_Serverid(server_type, &server_id);
276 //ret =get_Serverid(SAMSUNG_FUMO_TYPE , &server_id);
277 //ret =get_Serverid(GCF_TYPE , &server_id);
278 _DEBUG_VERBOSE("get server id : %s : %d", server_id, ret);
279 operationMode = OPER_USER_INITIATION;
282 _DEBUG_VERBOSE("noti ui");
283 fota_ui_type = OMADM_FUMO_NOTI_UI_TYPE;
284 sync_agent_get_event_data_param(request, &session_id);
285 sync_agent_get_event_data_param(request, &server_id);
286 _DEBUG_VERBOSE("get session id : %s", session_id);
287 _DEBUG_VERBOSE("get server id : %s", server_id);
288 operationMode = OPER_SERVER_INITIATION_FROM_IP;
290 case FOTA_BACKGROUND_UI:
291 _DEBUG_VERBOSE("background ui");
294 _DEBUG_VERBOSE("admin ui");
295 fota_ui_type = OMADM_ADMIN_UI_TYPE;
296 sync_agent_get_event_data_param(request, &server_type);
297 ret = get_Serverid(server_type, &server_id);
298 _DEBUG_VERBOSE("get server id : %s : %d", server_id, ret);
299 operationMode = OPER_USER_INITIATION;
302 _DEBUG_VERBOSE("cp ui");
305 _DEBUG_VERBOSE("not use ui");
309 if (server_id != NULL) {
310 _DEBUG_VERBOSE("fumo server id = %s", server_id);
311 Event_Contents *ev_data = (Event_Contents *) calloc(1, sizeof(Event_Contents));
312 if (ev_data == NULL) {
313 _DEBUG_VERBOSE("alloc fail");
316 ev_data->type = UI_EVENT;
317 if (session_id != NULL)
318 ev_data->session_id = strdup(session_id);
319 if (server_id != NULL) {
320 ev_data->server_id = strdup(server_id);
321 str_free(&server_id);
323 ev_data->noti_type = noti_type;
324 ev_data->ui_mode = strdup(fota_ui_type);
326 ret = dm_fumo_common_task_request(ev_data);
328 event_data_free((void *)ev_data);
336 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
341 int response_int = REPLY_FAIL_TO_CONNECT; //initial value
343 //Todo ------------------------------------------------------------------------------------------------------------------------ (from here)
344 sleep(10); // for test
346 response_int = REPLY_SUCCESS_TO_CONNECT; // resulted value
347 // ---------------------------------------------------------------------------------------------------------------------------------- (end)
348 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &response_int);
351 str_free(&(session_id));
352 str_free(&(server_id));
357 ev_response = EVENT_RESPONSE_FAIL;
358 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
360 str_free(&(session_id));
361 str_free(&(server_id));
367 static int __event_callback_cancel(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
371 retvm_if((request) == NULL, 0, "request is NULL!!");
374 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
375 _DEBUG_VERBOSE(">>> >>> >>> Connect to server CANCELED !!!\n");
378 sync_agent_get_event_data_param(request, &task_id);
379 _DEBUG_VERBOSE("task id : %d\n", task_id);
381 /*sync_agent_cancel_task(task_id); */
382 cancel_task(task_id);
385 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
392 static int __event_callback_download(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
396 retvm_if((request) == NULL, 0, "request is NULL!!");
398 DM_ERROR ret = DM_OK;
401 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
402 int response_type = 0;
403 RESUME_STATUS download_clicked = 0;
405 sync_agent_get_event_data_param(request, &response_type);
406 _DEBUG_VERBOSE("DOWNLOAD BUTTON TYPE : %d\n", response_type);
409 _DEBUG_VERBOSE("db open : %d", ret);
411 if (response_type == RESPONSE_TYPE_OK) {
412 /*download button clicked */
413 download_clicked = RESUME_STATUS_DOWNLOAD;
414 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
415 _DEBUG_VERBOSE("update engine status clolumn download click : %d", ret);
417 } else if (RESPONSE_TYPE_CANCEL) {
418 /*later button clicked */
419 download_clicked = RESUME_STATUS_DOWNLOAD_LATER;
420 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
421 _DEBUG_VERBOSE("update engine status clolumn download click : %d", ret);
425 ret = fumo_serviceEngine_task_request();
430 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
435 ev_response = EVENT_RESPONSE_FAIL;
436 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
442 static int __event_callback_install(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
446 retvm_if((request) == NULL, 0, "request is NULL!!");
448 DM_ERROR ret = DM_OK;
451 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
452 int response_type = 0;
453 RESUME_STATUS download_clicked = 0;
455 sync_agent_get_event_data_param(request, &response_type);
456 _DEBUG_VERBOSE("INSTALL BUTTON TYPE : %d\n", response_type);
459 _DEBUG_VERBOSE("db open : %d", ret);
461 if (response_type == RESPONSE_TYPE_OK) {
462 /*download button clicked */
463 download_clicked = RESUME_STATUS_INSTALL;
464 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
465 _DEBUG_VERBOSE("update engine status clolumn install click : %d", ret);
467 } else if (RESPONSE_TYPE_CANCEL) {
468 /*later button clicked */
469 download_clicked = RESUME_STATUS_INSTALL_LATER;
470 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
471 _DEBUG_VERBOSE("update engine status clolumn install click : %d", ret);
475 ret = fumo_serviceEngine_task_request();
480 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
486 ev_response = EVENT_RESPONSE_FAIL;
487 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
493 static int __event_callback_set_interval(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
497 retvm_if((request) == NULL, 0, "request is NULL!!");
499 DM_ERROR ret = DM_OK;
501 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
502 int request_param = INTERVAL_CANCEL;
504 sync_agent_get_event_data_param(request, &request_param);
505 _DEBUG_VERBOSE("interval val from UI : %d\n", request_param);
507 switch (request_param) {
508 case RESPONSE_TYPE_REMINDER_INTERVAL_1_HOUR:
509 request_param = INTERVAL_1HOUR;
511 case RESPONSE_TYPE_REMINDER_INTERVAL_3_HOURS:
512 request_param = INTERVAL_3HOURS;
514 case RESPONSE_TYPE_REMINDER_INTERVAL_6_HOURS:
515 request_param = INTERVAL_6HOURS;
517 case RESPONSE_TYPE_REMINDER_INTERVAL_12_HOURS:
518 request_param = INTERVAL_12HOURS;
520 case RESPONSE_TYPE_REMINDER_INTERVAL_1_DAY:
521 request_param = INTERVAL_1DAY;
523 case RESPONSE_TYPE_CANCEL:
524 request_param = INTERVAL_CANCEL;
530 _DEBUG_VERBOSE(" interval val in fumo engine : %d\n", request_param);
531 if (request_param != INTERVAL_CANCEL) {
532 ret = fumo_schedule_task_request(request_param);
536 _DEBUG_VERBOSE("fumo schedule task result : %d\n", ret);
538 _DEBUG_VERBOSE("fumo schedule cancel : %d \n", ret);
542 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
549 ev_response = EVENT_RESPONSE_FAIL;
550 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
557 static int __event_callback_account_registration(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
561 retvm_if((request) == NULL, 0, "request is NULL!!");
564 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
569 db_ret = sync_agent_open_agent();
570 _DEBUG_VERBOSE("OPEN DACI : %d", db_ret);
572 ret = register_fota_account();
574 db_ret = sync_agent_close_agent();
575 _DEBUG_VERBOSE("CLOSE DACI : %d", db_ret);
578 _DEBUG_VERBOSE("fail register fota account : %d ", ret);
581 _DEBUG_VERBOSE("success register fota account : %d ", ret);
585 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
591 ev_response = EVENT_RESPONSE_FAIL;
592 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
597 // Type 1, Fumo setting data Reply
598 static int __event_callback_get_profile(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
602 retvm_if((request) == NULL, 0, "request is NULL!!");
604 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
606 char *profile_name = NULL;
607 SERVICE_SERVER_TYPE sv_type = NO_ENGINE_TYPE;
609 char *client_id = NULL;
610 char *client_pwd = NULL;
611 char *client_sourceUrl = NULL;
612 char *client_targetUrl = NULL;
613 int client_isBase64 = 0;
614 char *client_nextNonce = NULL;
615 char *client_authType = NULL;
617 char *server_url = NULL;
618 char *server_pwd = NULL;
619 char *server_sourceUrl = NULL;
620 char *server_targetUrl = NULL;
621 int server_isBase64 = 0;
622 char *server_nextNonce = NULL;
623 char *server_authType = NULL;
625 sync_agent_dm_mo_error_e db_ret = SYNC_AGENT_DM_MO_SUCCESS;
626 char *server_id = NULL;
628 sync_agent_get_event_data_param(request, &sv_type);
629 _DEBUG_VERBOSE("server type : %d\n", sv_type);
631 db_ret = sync_agent_open_mo();
632 _DEBUG_VERBOSE("mo db open : %d", db_ret);
635 case SAMSUNG_FUMO_TYPE:
637 profile_name = "Fumo";
640 case SAMSUNG_FMM_TYPE:
642 profile_name = "Lawmo";
647 profile_name = "gcf";
652 _DEBUG_VERBOSE("not exist server id error");
657 get_Serverid(sv_type, &server_id);
658 _DEBUG_VERBOSE("server id : %s", server_id);
660 if (server_id != NULL) {
661 DM_ERROR err = get_client_dmacc(server_id, &client_id, &client_pwd, &client_sourceUrl, &client_targetUrl, &client_isBase64, &client_nextNonce, &client_authType);
663 _DEBUG_VERBOSE("get_client_dmacc() fail !!");
666 _DEBUG_VERBOSE("get_client_dmacc() success !!");
669 err = get_server_dmacc(server_id, &server_url, &server_pwd, &server_sourceUrl, &server_targetUrl, &server_isBase64, &server_nextNonce, &server_authType);
671 _DEBUG_VERBOSE("get_server_dmacc() fail !!");
674 _DEBUG_VERBOSE("get_server_dmacc() success !!");
677 db_ret = sync_agent_close_mo();
678 _DEBUG_VERBOSE("mo db close : %d", db_ret);
680 _DEBUG_VERBOSE("profile_name : %s", profile_name);
681 _DEBUG_VERBOSE("client_targetUrl : %s", client_targetUrl);
682 _DEBUG_VERBOSE("server_id : %s", server_url);
683 _DEBUG_VERBOSE("server_pwd : %s", server_pwd);
684 _DEBUG_VERBOSE("client_id : %s", client_id);
685 _DEBUG_VERBOSE("client_pwd : %s", client_pwd);
686 _DEBUG_VERBOSE("client_authType : %s", client_authType);
687 _DEBUG_VERBOSE("server_authType : %s", server_authType);
690 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
692 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, profile_name);
693 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, client_targetUrl);
694 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, server_url);
695 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, server_pwd);
696 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, client_id);
697 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, client_pwd);
698 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, client_authType);
699 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, server_authType);
701 str_free(&server_nextNonce);
702 str_free(&client_nextNonce);
703 str_free(&client_sourceUrl);
704 str_free(&server_sourceUrl);
705 str_free(&server_targetUrl);
706 str_free(&client_targetUrl);
707 str_free(&server_url);
708 str_free(&server_pwd);
709 str_free(&client_id);
710 str_free(&client_pwd);
711 str_free(&client_authType);
712 str_free(&server_authType);
714 _DEBUG_VERBOSE("not exist server id error");
722 db_ret = sync_agent_close_mo();
723 _DEBUG_VERBOSE("mo db close : %d", db_ret);
725 ev_response = EVENT_RESPONSE_FAIL;
726 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
731 static int __event_callback_set_profile(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
735 retvm_if((request) == NULL, 0, "request is NULL!!");
738 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
741 SERVICE_SERVER_TYPE sv_type = NO_ENGINE_TYPE;
742 char *server_id = NULL;
744 dm_acc *dmaccount = (dm_acc *) calloc(1, sizeof(dm_acc));
745 if (dmaccount == NULL) {
746 _DEBUG_VERBOSE("alloc fail");
750 sync_agent_get_event_data_param(request, &sv_type);
751 _DEBUG_VERBOSE("server profile type : %d", sv_type);
752 sync_agent_get_event_data_param(request, &(dmaccount->server_url));
753 _DEBUG_VERBOSE("server url : %s", (dmaccount->server_url));
754 sync_agent_get_event_data_param(request, &(dmaccount->server_id));
755 _DEBUG_VERBOSE("server id : %s", dmaccount->server_id);
756 sync_agent_get_event_data_param(request, &(dmaccount->server_pw));
757 _DEBUG_VERBOSE("server_pw : %s", dmaccount->server_pw);
758 sync_agent_get_event_data_param(request, &(dmaccount->user_id));
759 _DEBUG_VERBOSE("user_id : %s", dmaccount->user_id);
760 sync_agent_get_event_data_param(request, &(dmaccount->user_pw));
761 _DEBUG_VERBOSE("user_pw : %s", dmaccount->user_pw);
762 sync_agent_get_event_data_param(request, &(dmaccount->user_auth_type));
763 _DEBUG_VERBOSE("user_auth_type : %s", dmaccount->user_auth_type);
764 sync_agent_get_event_data_param(request, &(dmaccount->server_auth_type));
765 _DEBUG_VERBOSE("server_auth_type : %s", dmaccount->server_auth_type);
767 get_Serverid(sv_type, &server_id);
768 _DEBUG_VERBOSE("server id : %s", server_id);
770 if (server_id != NULL) {
771 ret = update_dmacc(server_id, dmaccount);
773 _DEBUG_VERBOSE("update dm acc fail", ret);
777 _DEBUG_VERBOSE("update dm acc success", ret);
784 _DEBUG_VERBOSE("update dm acc : %d", ret);
785 free_dm_acc(dmaccount);
787 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
793 free_dm_acc(dmaccount);
794 ev_response = EVENT_RESPONSE_FAIL;
795 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
800 static int __event_callback_reset_profile(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
803 retvm_if((request) == NULL, 0, "request is NULL!!");
806 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
807 SERVICE_SERVER_TYPE sv_type = NO_ENGINE_TYPE;
809 sync_agent_get_event_data_param(request, &sv_type);
810 _DEBUG_VERBOSE("PROFILE TYPE : %d\n", sv_type);
813 case SAMSUNG_FUMO_TYPE:
815 reset_dmacc_msctestserver();
818 case SAMSUNG_FMM_TYPE:
820 reset_dmacc_mscserver();
834 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
839 ev_response = EVENT_RESPONSE_FAIL;
840 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
845 static int __event_callback_uic_alert(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
849 uic_type type = UIC_NONE_TYPE;
850 RESPONSE_TYPE response_ret = EVENT_RESPONSE_FAIL;
851 char *input_text = NULL;
856 if (type == UIC_DISPLAY_TYPE) {
860 free_res_data(res_uic_data);
862 sync_agent_get_event_data_param(request, &response_ret);
863 _DEBUG_TRACE("response is %d", response_ret);
865 sync_agent_get_event_data_param(request, &type);
866 _DEBUG_TRACE("uic type %d", type);
868 /*alloc reponse data */
869 res_uic_data = calloc(1, sizeof(uic_res_data) + 1);
870 res_uic_data->status = response_ret;
872 if (response_ret == RESPONSE_TYPE_OK) {
874 _DEBUG_TRACE("response ok");
877 case UIC_CONFIRMATION_TYPE:
879 case UIC_INPUT_TEXT_TYPE:{
880 sync_agent_get_event_data_param(request, &input_text);
881 _DEBUG_TRACE("input text %s", input_text);
883 res_uic_data->input_text = strdup(input_text);
886 case UIC_SINGLE_CHOICE_TYPE:
887 case UIC_MULTIPLE_CHOICE_TYPE:{
888 sync_agent_get_event_data_param(request, &count);
889 _DEBUG_TRACE("count is %d\n", count);
892 /*single, multiple choice */
893 for (i = 0; i < count; ++i) {
896 sync_agent_get_event_data_param(request, &input);
897 _DEBUG_TRACE(" choice : %s", input);
899 input = strdup("NULL");
900 res_uic_data->res_multi_data = g_list_append(res_uic_data->res_multi_data, input);
902 _DEBUG_TRACE("value data : %s", input);
903 value = strdup(input);
904 res_uic_data->res_multi_data = g_list_append(res_uic_data->res_multi_data, value);
908 _DEBUG_TRACE("not choice");
912 case UIC_DISPLAY_TYPE:
922 _DEBUG_TRACE("response fail");
926 g_mutex_lock(&(mutex));
927 g_cond_signal(&(cond));
928 g_mutex_unlock(&(mutex));
930 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
931 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
937 static int __event_callback_get_fumo_config(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
940 retvm_if((request) == NULL, 0, "request is NULL!!");
943 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
946 sync_agent_open_agent();
948 wifi_only = get_wifi_only_config();
949 sync_agent_close_agent();
951 if (wifi_only == -1) {
952 _DEBUG_VERBOSE("get wifi only config fail\n");
955 _DEBUG_VERBOSE("get wifi only config success\n");
958 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
960 _DEBUG_VERBOSE("wifi only : %d", wifi_only);
961 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &wifi_only);
967 ev_response = EVENT_RESPONSE_FAIL;
968 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
973 static int __event_callback_set_fumo_config_wifi_only(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
976 retvm_if((request) == NULL, 0, "request is NULL!!");
979 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
983 sync_agent_get_event_data_param(request, &wifi_only_param);
985 sync_agent_open_agent();
986 ret = set_wifi_only_config(wifi_only_param);
987 sync_agent_close_agent();
992 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
997 ev_response = EVENT_RESPONSE_FAIL;
998 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1003 static int __event_callback_check_pin_code(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
1006 retvm_if((request) == NULL, 0, "request is NULL!!");
1009 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
1011 CP_ERROR err = CP_ERROR_SUCCESS;
1014 sync_agent_get_event_data_param(request, &ext_id);
1015 _DEBUG_VERBOSE("ext id : %d", ext_id);
1017 char *user_pin = NULL;
1019 int response_type = RESPONSE_TYPE_NONE;
1020 sync_agent_get_event_data_param(request, &response_type);
1021 _DEBUG_VERBOSE("response type : %d", response_type);
1023 int response_value = 0;
1025 if (response_type == RESPONSE_TYPE_OK) {
1026 _DEBUG_VERBOSE("check pin code !!");
1027 sync_agent_get_event_data_param(request, &user_pin);
1028 _DEBUG_VERBOSE("user pin : %s", user_pin);
1031 err = process_Check_Pincode(0, user_pin, &is_correct, ext_id);
1032 if (err != CP_ERROR_SUCCESS) {
1033 _DEBUG_VERBOSE("process_Check_Pincode() fail !!");
1034 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1037 /* todo : exception handling */
1038 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &response_value);
1040 _DEBUG_VERBOSE("process_Check_Pincode() success !!");
1042 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1044 if (is_correct != 0) {
1049 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &response_value);
1051 /* process_Setting_CP() */
1052 if (is_correct == 1) {
1053 _DEBUG_VERBOSE("Valid PIN !!");
1055 err = process_Setting_CP(ext_id);
1056 if (err != CP_ERROR_SUCCESS) {
1057 _DEBUG_VERBOSE("process_Setting_CP() fail !!");
1059 _DEBUG_VERBOSE("process_Setting_CP() success !!");
1061 } else if (is_correct == 0) {
1062 _DEBUG_VERBOSE("Invalid PIN !!");
1065 } else { /* response_type == RESPONSE_TYPE_CANCEL */
1066 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1068 response_value = 1; /* meaningless value */
1069 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &response_value);
1072 _DEBUG_VERBOSE("fail logic !!");
1073 err = process_Invalid_Pincode(ext_id);
1074 if (err != CP_ERROR_SUCCESS) {
1075 _DEBUG_VERBOSE("process_Invalid_Pincode() fail !!");
1076 /* todo : exception handling */
1078 _DEBUG_VERBOSE("process_Invalid_Pincode() success !!");
1081 _DEBUG_VERBOSE("cancel logic !!");
1086 str_free(&(user_pin));
1091 static int __event_add_dmacc(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
1095 sync_agent_dm_mo_error_e db_ret = SYNC_AGENT_DM_MO_SUCCESS;
1096 DM_ERROR ret = DM_OK;
1098 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
1099 SERVICE_SERVER_TYPE sv_type = NO_ENGINE_TYPE;
1101 sync_agent_get_event_data_param(request, &sv_type);
1102 _DEBUG_VERBOSE("server type : %d\n", sv_type);
1104 db_ret = sync_agent_open_mo();
1105 _DEBUG_VERBOSE("mo db open : %d", db_ret);
1108 _DEBUG_VERBOSE("dm status open : %d", db_ret);
1110 ret = DB_Begin_Transaction();
1111 _DEBUG_VERBOSE("end transaction : %d", ret);
1114 //todo will change ipc refactoring
1115 case SAMSUNG_FUMO_TYPE:
1117 _DEBUG_VERBOSE("add mscservertest dmacc");
1118 ret = add_dm_acc(sv_type);
1121 case SAMSUNG_FMM_TYPE:
1123 _DEBUG_VERBOSE("add mscserver dmacc");
1124 ret = add_dm_acc(sv_type);
1129 _DEBUG_VERBOSE("add gcf dmacc");
1130 ret = add_dm_acc(sv_type);
1135 _DEBUG_VERBOSE("not exist server id error");
1139 _DEBUG_VERBOSE("add dm acc error :%d", ret);
1142 ev_response = EVENT_RESPONSE_FAIL;
1146 ret = DB_End_Transaction(TRANSACTION_COMMIT_);
1147 _DEBUG_VERBOSE("end transaction : %d", ret);
1149 db_ret = sync_agent_close_mo();
1150 _DEBUG_VERBOSE("mo db close : %d", db_ret);
1154 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1161 ret = DB_End_Transaction(TRANSACTION_ROLLBACK_);
1162 _DEBUG_VERBOSE("end transaction : %d", ret);
1164 db_ret = sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
1165 _DEBUG_VERBOSE("end transaction : %d", db_ret);
1167 db_ret = sync_agent_close_mo();
1168 _DEBUG_VERBOSE("mo db close : %d", db_ret);
1172 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1178 static int __event_remove_dmacc(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
1182 sync_agent_dm_mo_error_e db_ret = SYNC_AGENT_DM_MO_SUCCESS;
1183 DM_ERROR ret = DM_OK;
1184 engine_status *status = NULL;
1185 ENGINE_STATUS engine_status = DM_IDLE;
1187 EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
1188 SERVICE_SERVER_TYPE sv_type = NO_ENGINE_TYPE;
1190 sync_agent_get_event_data_param(request, &sv_type);
1191 _DEBUG_VERBOSE("server type : %d\n", sv_type);
1194 db_ret = sync_agent_open_mo();
1195 _DEBUG_VERBOSE("mo db open : %d", db_ret);
1199 _DEBUG_VERBOSE("config alarm open : %d", db_ret);
1201 int is_exist = IsExist_Engine_id(IDLE_ENGINE);
1205 ret = Get_Engine_Status(IDLE_ENGINE, &status);
1207 _DEBUG_ERROR("Get_Engine_Status is not DM_OK");
1211 if(status == NULL) {
1212 _DEBUG_ERROR("status is null");
1216 _DEBUG_VERBOSE("STATUS VALUE : %d ", status->engine_status);
1217 engine_status = status->engine_status;
1219 if (engine_status == DM_BEFORE_BOOTSTRAP) {
1220 _DEBUG_VERBOSE("not bootstrap");
1224 db_ret = sync_agent_begin_transaction_mo();
1225 _DEBUG_VERBOSE("end transaction : %d", db_ret);
1227 ret = DB_Begin_Transaction();
1228 _DEBUG_VERBOSE("end transaction : %d", ret);
1232 case UI_SAMSUNG_FUMO_TYPE:
1234 _DEBUG_VERBOSE("remove mscservertest dmacc");
1235 ret = remove_dm_acc(DM_DMACC_MSCTESTSERVER);
1237 _DEBUG_ERROR("remove dm acc error :%d", ret);
1241 int is_exist = IsExist_Engine_id(FUMO_SERVICE_ENGINE);
1242 if (is_exist == 0) {
1243 _DEBUG_VERBOSE("not exist fumo engine");
1246 ret = Delete_Engine_Status(FUMO_SERVICE_ENGINE);
1248 _DEBUG_ERROR("delete engine status :%d", ret);
1252 delete_alarm_item(FUMO_INTERVAL, FUMO_INTERVAL_TYPE);
1253 _DEBUG_TRACE(" delete fumo reminder in config db ");
1256 delete_fumo_contents(MEMORY_INTERNAL);
1257 delete_fumo_contents(MEMORY_SD_CARD);
1259 //change fumo state 10
1260 char *fumo_state = NULL;
1261 fumo_state = g_strdup_printf("%s%s%s%s", MO_ROOT, MO_SEPERATOR, FUMO_SERVICE, DM_FUMO_STATE_OP);
1262 set_current_fumo_state(fumo_state, IDLE_START);
1263 str_free(&fumo_state);
1267 case UI_SAMSUNG_FMM_TYPE:
1269 _DEBUG_VERBOSE("remove mscserver dmacc");
1270 ret = remove_dm_acc(DM_DMACC_MSCSERVER);
1272 _DEBUG_ERROR("remove dm acc error :%d", ret);
1277 int is_exist = IsExist_Engine_id(LAWMO_SERVICE_ENGINE);
1278 if (is_exist == 0) {
1279 _DEBUG_VERBOSE("not exist fumo engine");
1282 ret = Delete_Engine_Status(LAWMO_SERVICE_ENGINE);
1284 _DEBUG_ERROR("delete engine status :%d", ret);
1293 _DEBUG_VERBOSE("remove gcf dmacc");
1294 ret = remove_dm_acc(DM_DMACC_GCF);
1296 _DEBUG_ERROR("remove dm acc error :%d", ret);
1299 _DEBUG_VERBOSE("remove dm acc");
1305 _DEBUG_VERBOSE("not exist server id error");
1309 ret = DB_End_Transaction(TRANSACTION_COMMIT_);
1310 _DEBUG_VERBOSE("end transaction : %d", ret);
1312 db_ret = sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_COMMIT);
1313 _DEBUG_VERBOSE("end transaction : %d", db_ret);
1315 _DEBUG_VERBOSE("remove dm acc error :%d", ret);
1317 db_ret = sync_agent_close_mo();
1318 _DEBUG_VERBOSE("mo db close : %d", db_ret);
1322 if (status != NULL) {
1323 Free_Memory_Engine_Status(&status, 1);
1326 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1332 ret = DB_End_Transaction(TRANSACTION_ROLLBACK_);
1333 _DEBUG_VERBOSE("end transaction : %d", ret);
1335 db_ret = sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
1336 _DEBUG_VERBOSE("end transaction : %d", db_ret);
1338 db_ret = sync_agent_close_mo();
1339 _DEBUG_VERBOSE("mo db close : %d", db_ret);
1343 if (status != NULL) {
1344 Free_Memory_Engine_Status(&status, 1);
1347 ev_response = EVENT_RESPONSE_FAIL;
1348 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1354 static int __event_callback_default(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
1357 retvm_if((request) == NULL, 0, "request is NULL!!");
1359 _DEBUG_VERBOSE("Undefined Event !!! \n");
1369 sync_agent_event_error_e error = SYNC_AGENT_EVENT_IPC_ERR;
1371 for (event_id = 1; event_id < EVENT_NUM; event_id++) {
1372 error = sync_agent_set_event_callback(event_id, _get_event_callback(event_id));
1373 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1374 _DEBUG_INFO("FAILURE: sync_agent_set_event_callback (event id: %d)\n", event_id);
1377 _DEBUG_INFO("SUCCESS: sync_agent_set_event_callback (event id: %d)\n", event_id);
1379 g_mutex_init(&(mutex));
1380 g_cond_init(&(cond));
1384 _DEBUG_INFO("%s: end (error:%d, event_id:%d) \n", __func__, error, event_id);
1389 int noti_start(char *ui_mode)
1392 _DEBUG_INFO("-----------------------------------------------------------------------noti start-------------------------------------------------------------------------------------");
1394 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ENGINE_START, 0, ui_mode, NULL);
1400 _DEBUG_INFO("-----------------------------------------------------------------------noti_connect_to_server-------------------------------------------------------------------------------------");
1402 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_DOWNLOAD, 0, NULL, NULL);
1408 _DEBUG_INFO("-----------------------------------------------------------------------noti_install-------------------------------------------------------------------------------------");
1410 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_INSTALL, 0, NULL, NULL);
1413 int noti_send_download_info(int filesize, char *path)
1416 _DEBUG_INFO("-----------------------------------------------------------------------noti_send_download_info-------------------------------------------------------------------------------------");
1418 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_DOWNLOAD_INFO, filesize, path, NULL);
1421 int noti_low_battery(char *battery_level)
1424 _DEBUG_INFO("-----------------------------------------------------------------------noti_low_battery-------------------------------------------------------------------------------------");
1426 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_LOW_BATTERY, 0, battery_level, NULL);
1429 int alert_uic_display(uic_data * uic_value)
1432 _DEBUG_INFO("-----------------------------------------------------------------------noti_alert_ui_display-------------------------------------------------------------------------------------");
1434 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ALERT_DISPLAY, 0, OMADM_ALERT_UI_TYPE, uic_value);
1437 int alert_uic_confirmation(uic_data * uic_value)
1440 _DEBUG_INFO("-----------------------------------------------------------------------noti_alert_ui_confirmation-------------------------------------------------------------------------------------");
1442 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ALERT_CONFIRMATION, 0, OMADM_ALERT_UI_TYPE, uic_value);
1445 int alert_uic_inputText(uic_data * uic_value)
1448 _DEBUG_INFO("-----------------------------------------------------------------------noti_alert_ui_inputText-------------------------------------------------------------------------------------");
1450 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ALERT_INPUTTEXT, 0, OMADM_ALERT_UI_TYPE, uic_value);
1453 int alert_uic_single_choice(uic_data * uic_value)
1456 _DEBUG_INFO("-----------------------------------------------------------------------noti_alert_ui_single_choice-------------------------------------------------------------------------------------");
1458 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ALERT_SINGLE_CHOICE, 0, OMADM_ALERT_UI_TYPE, uic_value);
1461 int alert_uic_multiple_choice(uic_data * uic_value)
1464 _DEBUG_INFO("-----------------------------------------------------------------------noti_alert_ui_multi_choice-------------------------------------------------------------------------------------");
1466 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ALERT_MULTIPLE_CHOICE, 0, OMADM_ALERT_UI_TYPE, uic_value);
1469 int noti_engine_fail(int prev_noti_id, int fail_type)
1472 _DEBUG_INFO("-----------------------------------------------------------------------noti_engine_fail-------------------------------------------------------------------------------------");
1474 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ENGINE_FAIL, prev_noti_id, 0, &fail_type);
1477 int noti_wifi_only_download_fail()
1480 _DEBUG_INFO("-----------------------------------------------------------------------noti_wifi_only_download_fail-------------------------------------------------------------------------------------");
1482 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_WIFI_ONLY_DOWNLOAD_FAIL, 0, 0, 0);
1485 int noti_memory_full(int file_size)
1488 _DEBUG_INFO("-----------------------------------------------------------------------noti_memory_full-------------------------------------------------------------------------------------");
1490 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_MEMORY_FULL, file_size, 0, 0);
1493 int noti_over_max_file_size()
1496 _DEBUG_INFO("-----------------------------------------------------------------------noti_over_max_file_size-------------------------------------------------------------------------------------");
1498 return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_OVER_BIG_SIZE, 0, 0, 0);
1501 static int _IPC_noti(int noti_type, int noti_id, int input_param, char *input_string, void *user_data)
1505 int ret = RESPONSE_TYPE_NONE;
1507 char *ui_mode = NULL;
1510 uic_data *uic_value = NULL;
1511 sync_agent_event_data_s *noti = NULL;
1512 sync_agent_event_data_s *reply_msg = NULL;
1513 sync_agent_event_error_e err = SYNC_AGENT_EVENT_FAIL;
1515 task_id = sync_agent_get_self_request_id();
1516 _DEBUG_TRACE("task : id %d ", task_id);
1517 if (task_id == -1) {
1518 ret = RESPONSE_TYPE_CANCEL;
1523 ret = get_fumo_ui_mode(&ui_mode);
1524 _DEBUG_TRACE("get ui mode : %d", ret);
1526 ret = RESPONSE_TYPE_CANCEL;
1531 _DEBUG_TRACE("ui mode : %s", ui_mode);
1532 ret = __check_ui_mode(&ui_mode, input_string);
1533 if (ret != RESPONSE_TYPE_OK) {
1534 str_free(&(ui_mode));
1536 return RESPONSE_TYPE_CANCEL;
1538 _DEBUG_TRACE("ui mode : %s", ui_mode);
1540 ret = __launch_ui(ui_mode, noti_type);
1542 str_free(&(ui_mode));
1544 return RESPONSE_TYPE_CANCEL;
1545 } else if (ret == 0) {
1546 str_free(&(ui_mode));
1548 return RESPONSE_TYPE_OK;
1551 _DEBUG_TRACE("ui mode : %s", ui_mode);
1552 _DEBUG_TRACE("create noti noti_id : %d", noti_id);
1554 noti = sync_agent_create_noti(noti_id);
1556 _DEBUG_TRACE("failed to sync_agent_create_noti");
1557 str_free(&(ui_mode));
1562 _DEBUG_TRACE("append_eventdata");
1566 case NOTI_DOWNLOAD: //Type 0
1568 case NOTI_INSTALL: //Type 0
1570 case NOTI_DOWNLOAD_INFO: //Type 0
1572 if (&input_param == NULL || input_string == NULL) {
1573 _DEBUG_TRACE("Error: input param: NULL\n");
1574 ret = RESPONSE_TYPE_CANCEL;
1578 _DEBUG_TRACE("agent noti: filesize:%d, path:%s\n", input_param, input_string);
1580 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &input_param);
1581 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, input_string);
1582 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &task_id);
1585 case NOTI_ENGINE_START: //Type 0
1587 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &task_id);
1590 case NOTI_ENGINE_FAIL: //Type 0
1592 int *fail_type = (int *)(user_data);
1594 _DEBUG_TRACE("noti id : %d\n", input_param);
1595 _DEBUG_TRACE("fail : %d\n", *fail_type);
1597 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &input_param);
1598 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, fail_type);
1601 case NOTI_WIFI_ONLY_DOWNLOAD_FAIL: //Type 0
1603 _DEBUG_TRACE("wifi only downlaod fail ipc");
1606 case NOTI_MEMORY_FULL: //Type 0
1608 _DEBUG_TRACE("memory full ipc : %d", input_param);
1609 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &input_param);
1613 case NOTI_OVER_BIG_SIZE: //Type 0
1615 _DEBUG_TRACE("over max size");
1618 case NOTI_LOW_BATTERY: //Type 0
1620 if (input_string == NULL) {
1622 _DEBUG_TRACE("Error : input string : NULL\n");
1623 ret = RESPONSE_TYPE_CANCEL;
1628 _DEBUG_TRACE("agent noti - battery level : %s\n", input_string);
1629 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, input_string);
1632 case NOTI_ALERT_DISPLAY: //Type 2, response event
1633 case NOTI_ALERT_CONFIRMATION: //Type 2, response event
1634 case NOTI_ALERT_INPUTTEXT: //Type 2, response event
1636 _DEBUG_TRACE("uic flow noti type : %d", noti_id);
1637 uic_value = (uic_data *) user_data;
1639 uic_timeout_val = atoi(uic_value->pUic_option->max_t);
1641 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->min_t);
1642 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->max_t);
1643 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->default_data);
1644 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->maxlen);
1645 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->input_type);
1646 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->echo_type);
1648 _DEBUG_TRACE("display : %s\n", uic_value->display);
1649 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->display);
1652 case NOTI_ALERT_SINGLE_CHOICE: //Type 2, response event
1653 case NOTI_ALERT_MULTIPLE_CHOICE: //Type 2, response event
1655 uic_value = (uic_data *) user_data;
1657 uic_timeout_val = atoi(uic_value->pUic_option->max_t);
1659 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->min_t);
1660 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->max_t);
1661 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->default_data);
1662 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->maxlen);
1663 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->input_type);
1664 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->echo_type);
1666 _DEBUG_TRACE("display : %s\n", uic_value->display);
1667 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->display);
1669 count = g_list_length(uic_value->multi_data);
1670 _DEBUG_TRACE("choice data count : %d\n", count);
1671 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &count);
1673 for (iter = uic_value->multi_data; iter != NULL; iter = g_list_next(iter)) {
1674 _DEBUG_TRACE("choice data : %s", (char *)(iter->data));
1675 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (char *)(iter->data));
1684 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) {
1685 DB_Begin_Transaction();
1687 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_UI_NOTI_TYPE, ¬i_id);
1689 _DEBUG_TRACE("update engine status column : %d, %d\n", ret, noti_id);
1690 ret = RESPONSE_TYPE_CANCEL;
1695 _DEBUG_TRACE("sendNoti");
1696 reply_msg = sync_agent_send_noti(ui_mode, noti, __dm_task_process_check_cancel_flag, ui_mode, &err);
1697 if(reply_msg == NULL) {
1698 _DEBUG_TRACE("sendNoti return : %d", err);
1700 _DEBUG_TRACE("sendNoti return : %d , event_num[%d] , reply_msg data[%s]", err, reply_msg->event_num, reply_msg->data);
1702 if (err != SYNC_AGENT_EVENT_SUCCESS) {
1703 if (err == SYNC_AGENT_EVENT_IPC_ERR) {
1705 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) {
1706 DB_End_Transaction(TRANSACTION_ROLLBACK_);
1710 _DEBUG_TRACE("sendNoti (noti id:%d), FAIL\n", noti_id);
1711 ret = RESPONSE_TYPE_CANCEL;
1716 _DEBUG_TRACE("sendNoti (noti id:%d), success\n", noti_id);
1717 _DEBUG_TRACE("IPC RESPONSE\n");
1719 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) {
1720 DB_End_Transaction(TRANSACTION_COMMIT_);
1722 ret = __uic_response(noti_id, user_data);
1723 _DEBUG_TRACE("uic_response ret : %d", ret);
1728 ret = RESPONSE_TYPE_OK;
1731 str_free(&(ui_mode));
1732 sync_agent_free_noti(noti);
1738 str_free(&(ui_mode));
1739 sync_agent_free_noti(noti);
1740 _DEBUG_TRACE("%s : end : %d\n", __func__, ret);
1745 sync_agent_event_ipc_cancel_e __dm_task_process_check_cancel_flag(void *user_data)
1749 retvm_if((user_data) == NULL, SYNC_AGENT_EVENT_IPC_CANCEL_NEED_CANCEL, "user_data is NULL!!");
1751 sync_agent_ec_boolean cancel_flag = sync_agent_check_cancel_flag();
1752 sync_agent_event_ipc_cancel_e result_cancel;
1754 char *ui_mode = (char *)user_data;
1756 if (cancel_flag == 0) {
1757 result_cancel = SYNC_AGENT_EVENT_IPC_CANCEL_UN_NEED_CANCEL;
1758 _DEBUG_VERBOSE("%s : cancel_flag = %d\n", __func__, result_cancel);
1760 result_cancel = SYNC_AGENT_EVENT_IPC_CANCEL_NEED_CANCEL;
1761 _DEBUG_VERBOSE("%s : cancel_flag = %d\n", __func__, result_cancel);
1764 if (strcmp(ui_mode, OMADM_FUMO_UI_TYPE) == 0) {
1765 result_ui = aul_app_is_running(OMA_DM_FUMO_UI_PKG);
1766 if (result_ui == 0) {
1767 _DEBUG_VERBOSE("oma dm fumo ui process off \n");
1768 result_cancel = SYNC_AGENT_EVENT_IPC_CANCEL_NEED_CANCEL;
1770 } else if (strcmp(ui_mode, OMADM_FUMO_NOTI_UI_TYPE) == 0) {
1771 result_ui = aul_app_is_running(OMA_DM_FUMO_NOTI_UI_PKG);
1772 if (result_ui == 0) {
1773 _DEBUG_VERBOSE("oma dm noti ui process off \n");
1774 result_cancel = SYNC_AGENT_EVENT_IPC_CANCEL_NEED_CANCEL;
1780 return result_cancel;
1783 static int __uic_response(int noti_id, void *user_data)
1786 int ret = RESPONSE_TYPE_NONE;
1789 case NOTI_ALERT_DISPLAY: //Type 0
1791 _DEBUG_TRACE("display alert response ");
1792 ret = RESPONSE_TYPE_OK;
1795 case NOTI_ALERT_CONFIRMATION: //Type 0
1797 _DEBUG_TRACE("confirmation alert response ");
1800 if (uic_timeout_val == TIMEOUT_VAL_UIC) {
1801 uic_timeout_val = TIMEOUT_VAL_UIC + REST_TIMEOUT_VAL;
1803 uic_timeout_val += REST_TIMEOUT_VAL;
1806 timeout = g_get_monotonic_time() + uic_timeout_val * G_TIME_SPAN_SECOND;
1808 _DEBUG_TRACE("timeout : %d ", timeout);
1810 g_mutex_lock(&(mutex));
1811 g_cond_wait_until(&(cond), &(mutex), timeout);
1812 g_mutex_unlock(&(mutex));
1814 if (res_uic_data == NULL) {
1815 /*signal by timeout */
1816 ret = RESPONSE_TYPE_TIMEOVER;
1818 ret = res_uic_data->status;
1819 _DEBUG_TRACE("response is %d\n", ret);
1821 free_res_data(res_uic_data);
1822 res_uic_data = NULL;
1826 case NOTI_ALERT_INPUTTEXT: //Type 0
1829 if (uic_timeout_val == TIMEOUT_VAL_UIC) {
1830 uic_timeout_val = TIMEOUT_VAL_UIC + REST_TIMEOUT_VAL;
1832 uic_timeout_val += REST_TIMEOUT_VAL;
1835 timeout = g_get_monotonic_time() + uic_timeout_val * G_TIME_SPAN_SECOND;
1837 _DEBUG_TRACE("timeout : %d ", timeout);
1839 g_mutex_lock(&(mutex));
1840 g_cond_wait_until(&(cond), &(mutex), timeout);
1841 g_mutex_unlock(&(mutex));
1843 uic_data *uic_value = (uic_data *) user_data;
1845 if (res_uic_data == NULL) {
1846 /*signal by timeout */
1847 uic_value->res_data->input_text = strdup("NULL");
1848 _DEBUG_TRACE("INPUT TEXT CANCEL / TIMEOVER");
1849 ret = RESPONSE_TYPE_TIMEOVER;
1851 ret = res_uic_data->status;
1852 _DEBUG_TRACE("response is %d\n", ret);
1853 _DEBUG_TRACE("input text alert response ");
1855 if (ret == RESPONSE_TYPE_OK) {
1856 if (res_uic_data->input_text == NULL) {
1857 res_uic_data->input_text = strdup("NULL");
1860 uic_value->res_data->input_text = strdup(res_uic_data->input_text);
1863 uic_value->res_data->input_text = strdup("NULL");
1864 _DEBUG_TRACE("INPUT TEXT CANCEL / TIMEOVER");
1867 free_res_data(res_uic_data);
1868 res_uic_data = NULL;
1872 case NOTI_ALERT_SINGLE_CHOICE: //Type 0
1873 case NOTI_ALERT_MULTIPLE_CHOICE: //Type 0
1877 if (uic_timeout_val == TIMEOUT_VAL_UIC) {
1878 uic_timeout_val = TIMEOUT_VAL_UIC + REST_TIMEOUT_VAL;
1880 uic_timeout_val += REST_TIMEOUT_VAL;
1883 timeout = g_get_monotonic_time() + uic_timeout_val * G_TIME_SPAN_SECOND;
1884 _DEBUG_TRACE("timeout : %d ", timeout);
1886 g_mutex_lock(&(mutex));
1887 g_cond_wait_until(&(cond), &(mutex), timeout);
1888 g_mutex_unlock(&(mutex));
1890 _DEBUG_TRACE("choice alert response ");
1892 uic_data *uic_value = (uic_data *) user_data;
1896 if (res_uic_data == NULL) {
1897 /*signal by timeout */
1898 ret = RESPONSE_TYPE_TIMEOVER;
1899 input = strdup("NULL");
1900 uic_value->res_data->res_multi_data = g_list_append(uic_value->res_data->res_multi_data, input);
1901 _DEBUG_TRACE("CHOICE CANCEL / TIMEOVER");
1903 ret = res_uic_data->status;
1904 _DEBUG_TRACE("response is %d\n", ret);
1906 if (ret == RESPONSE_TYPE_OK) {
1908 if (res_uic_data->res_multi_data != NULL) {
1909 count = g_list_length(res_uic_data->res_multi_data);
1912 input = strdup("NULL");
1913 uic_value->res_data->res_multi_data = g_list_append(uic_value->res_data->res_multi_data, input);
1916 for (iter = res_uic_data->res_multi_data; iter != NULL; iter = g_list_next(iter)) {
1918 input = strdup(iter->data);
1919 uic_value->res_data->res_multi_data = g_list_append(uic_value->res_data->res_multi_data, input);
1923 input = strdup("NULL");
1924 uic_value->res_data->res_multi_data = g_list_append(uic_value->res_data->res_multi_data, input);
1925 _DEBUG_TRACE("CHOICE CANCEL / TIMEOVER");
1929 free_res_data(res_uic_data);
1930 res_uic_data = NULL;
1936 case NOTI_DOWNLOAD_INFO:
1937 case NOTI_ENGINE_START:
1938 case NOTI_LOW_BATTERY:
1939 case NOTI_OVER_BIG_SIZE: